# [S] Recursive Question

Erin Hodgess (hodgess@uhdux2.dt.uh.edu)
Fri, 31 Jul 1998 14:54:32 -0500

Dear Josi:

I took a quick look at your S+ code and I see a snag right away:

The M and N in the Pi function need to be defined somewhere.

Also, I am a bit confused about your line in the Pi function
which starts with "a^f...."

Where is "a" coming from, please?

Thanks!

Sincerely,
Erin Hodgess
Assistant Professor
Dept. of Computer and Mathematical Sciences
University of Houston -- Downtown
e-mail: hodgess@uhdux2.dt.uh.edu

X-Mailer: Mozilla 4.04 [en] (Win95; I)
Mime-Version: 1.0
To: s-plus discussion <s-news@wubios.wustl.edu>
Subject: [S] Recursive Occurrence; and sub-function
Content-Type: text/plain; charset=us-ascii
Sender: owner-s-news@wubios.wustl.edu
Content-Transfer-Encoding: 7bit
Status: R

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

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