From murdoch at stats.uwo.ca  Sat Oct 20 12:02:55 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sat, 20 Oct 2007 06:02:55 -0400
Subject: [Rd] Name length of function argument? (PR#10357)
In-Reply-To: <20071019160510.0B602283416A@mail.pubhealth.ku.dk>
References: <20071019160510.0B602283416A@mail.pubhealth.ku.dk>
Message-ID: <4719D24F.3020800@stats.uwo.ca>

deiwiks at icr.gess.ethz.ch wrote:
> 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?
>   
See ?optim.  The first argument should be par, not fn.

Duncan Murdoch



[Rd] Name length of function argument? (PR#10357)
Duncan Murdoch