[S] Recursive Occurrence; and sub-function

Josť Ailton Alencar andrade (andrade@inep.gov.br)
Fri, 31 Jul 1998 16:24:59 -0300


Hello All,

I have two question. Let the following program in S+ :

gera.p
function(w, lambda, theta, eta)
{
Pi <- function(f)
{
a^f/(gamma(f)^(M + N))
}
psi.r <- function(x)
{
(log(gamma(x + 1e-008)) - log(gamma(x)))/1e-008 - log(a)
}
a <- (lambda^(M + N) * prod(theta) * prod(eta))
mu <- nlminb(start = 0.3, objective = psi.r, lo = 0, up =
100)$parameters
sig <- sqrt((2 * 1)/((N + M) * d1.psi(x = mu)))
q <- function(t)
{
exp(-1/(2 * sig^2) * (t - mu)^2)
}
p <- rnorm(1, mu, sig)
u <- runif(1, 0, 1)
if(Pi(f = w) * q(t = p) > 0) {
alpha <- min((Pi(f = p) * q(t = w))/(Pi(f = w) * q(t = p)), 1)
}
{
alpha <- 1
}
novop <- ifelse(u <= alpha, p, w)
novop

Questions:

1)when I run this program using the command:

gera.p(w=0.4, lambda=30, theta=runif(30,0,1), eta=runif(52,0,1))

So, the S+ put the following error message:
Error in Pi(f = w): Recursive occurrence of default argument "a"
Dumped

But the object "a" is in first line of program. Why is it happening?

2) In this same program, when I use a object "a" in sub-function
psi.r, so it do not find "a", but clearly "a" was defined above!!!!

THANKS

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news