Re: [Rd] Name length of function argument? (PR#10357)

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Sat, 20 Oct 2007 06:02:55 -0400

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 20 Oct 2007 - 10:13:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.