[R] non-numeric argument in mle2

Ben Bolker bbolker at gmail.com
Thu Apr 19 21:58:19 CEST 2012


peter dalgaard <pdalgd <at> gmail.com> writes:

> 
> 
> On Apr 19, 2012, at 09:52 , Joachim Audenaert wrote:
> 
> > Hi all,
> > 
> > I have some problems with the mle2 function
> > 
> > 
> >> RogersIIbinom <- function(N0,attackR3_B,Th3_B) 
>  {N0-lambertW(attackR3_B*Th3_B*N0*exp(-attackR3_B*(24-Th3_B*N0)))/
>     (attackR3_B*Th3_B)}
> >> RogersII_B <- 
> > mle2(FR~dbinom(size=N0,prob=RogersIIbinom(N0,attackR3_B,Th3_B)/N0),
>  start=list(attackR3_B=1.5,Th3_B=0.04),method="Nelder-Mead",data=dat)
> > Error in dbinom(x, size, prob, log) : 
> >  Non-numeric argument to mathematical function
> > 
> > Can somenone explain met what this error means? All my parameters and data 
> > are defined, so I don't understand what the non-numeric argument is??? 
> > With different equations the script does work...........
> 
> traceback() indicates that the prob= argument is a vector of 
> complex numbers when doing the call
> 
> minuslogl(attackR3_B = -0.262499999999999, Th3_B = 1.755625)
> 

  [snip]

Further debugging shows that this is caused by an attempt
to evaluate a negative attack-rate parameter.

  The short answer is that if you use method="L-BFGS-B",
lower=1e-5 (you need to set the lower bound slightly *above* zero)
you can get this to work fine.

  I have posted a longer, somewhat obsessive answer at

http://www.math.mcmaster.ca/bolker/misc/rogers2.pdf

 which is an ongoing brain dump/set of notes about fitting
the Rogers random predator equation and related models in R.

  Ben Bolker



More information about the R-help mailing list