[R] error in optim: initial value in 'vmmin' is not finite

garciap garciap at usal.es
Thu Feb 23 22:51:51 CET 2012


Dear r-helpers,

I'm experiencing some problems in fitting a maximum likelihood binomial
model to some of my data. The error is in optim, which founds: Error in
optim(par = c(0.2, 0.5), fn = function (p)  : 
  initial value in 'vmmin' is not finite

Yes, I know it's a common problem, and I've carefully searched and readed
all the posts about the issue, But, I can't find a solution. It looks like
it will be a small piece of my code, but I'm unable to find it. Maybe anyone
could help me...
Here is my data and the code:


> library(bbmle)
Loading required package: stats4
Loading required package: numDeriv
Loading required package: lattice
Loading required package: MASS
Warning message:
package 'bbmle' was built under R version 2.12.2 
> Cov<-read.table("f:/Arribes/NutriaPopMod.csv", header=TRUE, sep=",")
> print(Cov)
      Localidad sizec sizead
1  Villagonzalo     5      3
2  Villagonzalo     7      3
3  Villagonzalo    10      4
4      Riolobos    13     13
5      Riolobos     8      8
6      Riolobos     8      8
7      Riolobos     8      8
8      Riolobos     8      8
9     Salamanca    21      3
10    Salamanca    24      4
11    Salamanca    25      5
12    Salamanca    21      3
13    Salamanca    22      7
14           FA    24      5
15           FA    23      5
16           FA    14      8
17           FA     7      4
18           FA     8      3
19      Juzbado    13      2
20      Juzbado    10      2
21      Juzbado     3      2
22       Cristo     4      2
23       Cristo     4      2
24       Cristo     3      2
25       Cristo     4      2
26        Muñoz     2      2
27        Muñoz     2      2
28      Castraz     2      2
29      Castraz     2      2
30     Saldeana     2      2
31     Saldeana     2      2
32    Merchanas     2      2
33    Merchanas     2      2
34    Merchanas     2      2
35           CR     3      2
36           CR     2      2
37        Béjar     4      4
38        Béjar     8      8
39        Béjar     6      6
40         Gata     2      3
41         Gata     2      3
42   Sta Teresa     4      4
43   Sta Teresa     5      5
44   Sta Teresa     2      2
45   Sta Teresa     2      2
46      Francia     3      2
47      Francia     2      2
48     Navamuño    21     21
49     Navamuño     8      8
50      Ledesma    11      3
51      Ledesma    12      3
52      Ledesma    15      2
53      Ledesma    21      2
54      Ledesma     6      2
55     Monleras     2      2
56     Monleras     2      2
57         Uces     2      2
58         Uces     2      2
59     Molinera     2      2
60     Molinera     2      2
61  Aldeadávila     2      2
62  Aldeadávila     2      2
63      Pelayos     3      3
64      Pelayos     4      3
65      Pelayos     5      3
> Pr<-function(p1,p,n1,n2)
+ {P1=1-(1-p1)
+ POD=1-(1-p)
+ Pr=P1*POD
+ -sum(dbinom(length(Cov$Nt),size=Cov$sizead, prob=POD,
log=TRUE)*dbinom(length(Cov$Nt), size=Cov$sizec, prob=P1,log=TRUE))
+ }
> parnames(Pr)=c("p1","p")
> m1<-mle2(Pr, start=list(p1=0.2, p=0.5),
> data=list(Pr=Cov$Pr,n1=Cov$sizec,n2=Cov$sizead))
> Error in optim(par = c(0.2, 0.5), fn = function (p)  : 
  initial value in 'vmmin' is not finite

Thanks in advance, regards,

Pablo


--
View this message in context: http://r.789695.n4.nabble.com/error-in-optim-initial-value-in-vmmin-is-not-finite-tp4415385p4415385.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list