[R] 2-parameter MLE problems

From: Tyler Schartel <tes164_at_msstate.edu>
Date: Tue, 12 Apr 2011 11:20:27 -0500


Hi all,

Sorry for the re-post, I sent my previous e-mail before it was complete. I am trying to model seroprevalence using the differential equation: dP/dt = beta*seronegative*.001*(seropositive)-0.35*(0.999)*(seropositive)-r*seropositive. I would like to estimate my two parameters, beta and r, using maximum likelihood methods. I have included my code below:

summary=read.delim('summary.txt',header=T) summary
  Year N SeroPos SeroNeg

1    1  75       1      74
2    2  12       3       9
3    3 139      11     128
4    4 178      22     156
5    5 203      18     185
6    6 244      37     207

attach(summary)
poisNLL=function(P){
lambda=P[1]*SeroNeg*0.001*SeroPos-0.35*0.999*SeroPos-P[2]*SeroPos v=-sum(dpois(SeroNeg,lambda=lambda,log=TRUE)) if (!is.finite(v)) v<- -2000000
v
}
opt1=optim(poisNLL,start=c(10,.1),method='BFGS')

I receive the following error from this code: "Error in optim(poisNLL, start = c(10, 0.1), method = "BFGS") :
  cannot coerce type 'closure' to vector of type 'double'"

Any assistance provided would be greatly appreciated!

Best,
Tyler

        [[alternative HTML version deleted]]



R-help_at_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. Received on Tue 12 Apr 2011 - 22:25:04 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 Tue 12 Apr 2011 - 22:50:30 GMT.

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

list of date sections of archive