s-news
[Top] [All Lists]

Re: about input parameters

To: Stefano Sofia <stefano.sofia@usa.net>
Subject: Re: about input parameters
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Wed, 16 Apr 2003 07:43:53 -0500
Cc: s-news@lists.biostat.wustl.edu
Organization: PDF Solutions, Inc.
References: <690HDPJRT8080S07.1050484639@uwdvg007.cms.usa.net>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01


Stefano Sofia 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


This is a scoping issue. Replace function internal with:

  internal <- function(normalmean, normalvariance, state){
    alpha <- 0.01
    if(state == 0) {
      smallg <- substitute(function(eta, mu, sigma){
        (dnorm(eta, mean = mu, sd = sigma) * 1)/(1 + exp(alpha * eta))})
    } else {
      smallg <- substitute(function(eta, mu, sigma){
(dnorm(eta, mean = mu, sd = sigma) * 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
      Y1.num <- smallg(Y1, normalmean, sqrt(normalvariance))
      Y1.den <- dnorm(Y1, mean = normalmean, sd = sqrt(normalvariance))
      if(U <= Y1.num/Y1.den) {
        sampledvalue <- Y1
        break
      }
    }
    result <- sampledvalue
    result
  }



<Prev in Thread] Current Thread [Next in Thread>