s-news
[Top] [All Lists]

Re: [about input parameters ]

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: [about input parameters ]
From: Stefano Sofia <stefano.sofia@usa.net>
Date: Thu, 17 Apr 2003 21:28:39 +0100
Yes, my problem was a scooping issue, that can be solved either defining the
variable at the outer frame
(thank you to Patrick Burns who suggested to look at the Spoetry and James
Holtman) or including the variable as argument of the function where this
variable is used (thank you to Sundar Dorai-Raj and Tim Hesterberg)

thank you
Stefano



Stefano Sofia <stefano.sofia@usa.net> wrote:
> Dear Splus users,
> I have got some problems about input parameters for a Splus personal
> procedure.
> 
> If I call the procedure below reported 
> myprocedure(-38.94376,0.001842975)
> there is an error in "smallg(Y1)" which says: 
> Error in small(Y1): Object "E7" not found.
> Why? 
> E7 and V7 are two scalars.
> Defining E7 and V7 as 
> array(NA, dim = c(1, 1)),
> mode(E7) is "numeric", mode(V7) is "numeric". 
> I encounter the same problem if I define E7 and V7 as matrices of 
> dimesion 1 by 1 
> or even if I do not define them at all.
> Why smallg can't be evaluated for eta=E7?
> If I use the internal procedure without E7 and V7 but with pure 
> numbers, i.e.
> 
> internal(-38.94376,0.001842975,1)
> everything works fine. Why?
> 
> I am using Splus4 with W XP.
> 
> grateful for your help
> Stefano
> 
> 
> 
> function(firstvalue, secondvalue)
> {
> E7 <- array(NA, dim = c(1, 1))
> V7 <- array(NA, dim = c(1, 1))
> E7 <- firstvalue
> V7 <- secondvalue
> internal <- function(normalmean, normalvariance, state){
> alpha <- 0.01
> if(state == 0) {
> smallg <- substitute(function(eta){
> (dnorm(eta, mean = normalmean, sd = sqrt(normalvariance)) * 1)/(1 + exp
> (alpha
> * eta))})}
> else {
> smallg <- substitute(function(eta){
> (dnorm(eta, mean = normalmean, sd = sqrt(normalvariance)) * exp(alpha *
> eta))/(1 + exp(alpha * eta))})}
> repeat {
> # STEP 1: SAMPLE A POINT Y1 FROM bigg(Y)
> Y1 <- rnorm(1, mean = normalmean, sd = sqrt(normalvariance)) 
> # STEP 2: SAMPLE A UNIFORM(0,1) RANDOM VARIABLE U
> U <- runif(1, min = 0, max = 1) 
> # STEP 3: IF U <= g(Y1)/G(Y1) ACCEPT Y1; 
> # REPEAT THIS LOOP UNTIL ONE Y IS ACCEPTED
> if(U <= smallg(Y1)/dnorm(Y1, mean = normalmean, sd = sqrt
> (normalvariance))) {
> sampledvalue <- Y1
> break}}
> result <- sampledvalue
> result
> }
> finalvalue <- internal(E7, V7, 1)
> }


<Prev in Thread] Current Thread [Next in Thread>
  • Re: [about input parameters ], Stefano Sofia <=