Re: [R] non-numeric argument in mle2

2012-04-19 Thread Ben Bolker
peter dalgaard  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.2624999, 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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] non-numeric argument in mle2

2012-04-19 Thread peter dalgaard

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.2624999, Th3_B = 1.755625)



> 
> For this function to run you need packages: bbmle and emdbook.
> Testdata I pasted here
> 
> N0  FR
> 5   4
> 3   2
> 5   3
> 5   4
> 6   4
> 5   4
> 4   2
> 5   4
> 6   5
> 5   3
> 10  5
> 14  7
> 12  6
> 17  9
> 10  4
> 16  8
> 15  8
> 14  5
> 15  6
> 15  5
> 19  10
> 20  11
> 22  10
> 21  12
> 25  12
> 26  11
> 25  10
> 25  12
> 25  11
> 24  9
> 35  12
> 33  12
> 35  13
> 36  12
> 31  12
> 37  12
> 39  13
> 36  14
> 35  12
> 35  10
> 46  11
> 44  10
> 41  12
> 43  14
> 45  12
> 48  11
> 45  13
> 45  9
> 49  12
> 45  11
> 56  12
> 59  15
> 52  11
> 54  10
> 51  12
> 55  12
> 61  13
> 55  12
> 54  10
> 55  12
> 
> Kind regards,
> Met vriendelijke groeten,
> Joachim
> 
> Don't waste paper! Think about the environment before printing this e-mail
> 
> __
> 
> Joachim Audenaert
> Adviesdienst Gewasbescherming
> Proefcentrum voor Sierteelt
> Schaessestraat 18
> B-9070 Destelbergen
> Belgium
> Tel. +32 9 353 94 71
> Fax +32 9 353 94 95
> E-mail: joachim.audena...@pcsierteelt.be
> www.pcsierteelt.be
> __
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] non-numeric argument in mle2

2012-04-19 Thread Joachim Audenaert
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...

For this function to run you need packages: bbmle and emdbook.
Testdata I pasted here

N0  FR
5   4
3   2
5   3
5   4
6   4
5   4
4   2
5   4
6   5
5   3
10  5
14  7
12  6
17  9
10  4
16  8
15  8
14  5
15  6
15  5
19  10
20  11
22  10
21  12
25  12
26  11
25  10
25  12
25  11
24  9
35  12
33  12
35  13
36  12
31  12
37  12
39  13
36  14
35  12
35  10
46  11
44  10
41  12
43  14
45  12
48  11
45  13
45  9
49  12
45  11
56  12
59  15
52  11
54  10
51  12
55  12
61  13
55  12
54  10
55  12

Kind regards,
Met vriendelijke groeten,
Joachim

Don't waste paper! Think about the environment before printing this e-mail

__

Joachim Audenaert
Adviesdienst Gewasbescherming
Proefcentrum voor Sierteelt
Schaessestraat 18
B-9070 Destelbergen
Belgium
Tel. +32 9 353 94 71
Fax +32 9 353 94 95
E-mail: joachim.audena...@pcsierteelt.be
www.pcsierteelt.be
__
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.