From deiwiks at icr.gess.ethz.ch  Fri Oct 19 18:05:09 2007
From: deiwiks at icr.gess.ethz.ch (deiwiks at icr.gess.ethz.ch)
Date: Fri, 19 Oct 2007 18:05:09 +0200 (CEST)
Subject: [Rd] Name length of function argument? (PR#10357)
Message-ID: <20071019160510.0B602283416A@mail.pubhealth.ku.dk>

Hi,
I've just been programming a function to calculate the likelihood in a 
probit model.
The function looks like this

likelihood <- function(Y,X,p) {
Z <- p[1] +p[2]*X
P <- Y*pnorm(Z) + (1-Y)*(1-pnorm(Z))
-prod(P)
}

out <- optim(likelihood,p=c(0,0),Y=wells$switch,X=wells$dist, hessian=TRUE)

X and Y are vectors containing column data.
This works fine, however, if I rename p to pp or anything that is longer 
than one character, I get the following error message:

Error in optim(f, pp = c(0, 0), Y=wells$switch, X=wells$dist, 
hessian=TRUE) :
  cannot coerce type closure to double vector

This seems like a bug... Or can you help me find the mistake I made?

Thanks,
 Christa

-- 
Christa Deiwiks
International Conflict Research
ETH Zurich

Seilergraben 49 (SEI E.3)
8092 Zurich
Ph: +41 44 632 67 60

http://www.icr.ethz.ch/people/deiwiks



[Rd] Name length of function argument? (PR#10357)
deiwiks at icr.gess.ethz.ch