[R] Question for help

93354504 93354504 at nccu.edu.tw
Mon Sep 8 12:18:36 CEST 2008


clotting <- data.frame(u = c(5,10,15,20,30,40,60,80,100), lot1 =
c(118,58,42,35,27,25,21,19,18), lot2 = c(69,35,26,21,18,16,13,12,12));
lot=c(clotting$lot1,clotting$lot2);
uu=c(clotting$u,clotting$u);
x=uu;
y=lot;
n=length(y);
x=cbind(rep(1,n),x);
c=2;
neg_loglikehood=function(theta){
   -1*(c*sum(log(x%*%theta))+(c-1)*sum(log(y))-c*sum(y*(x%*%theta)));
}
g=glm(lot ~ log(uu),  family=Gamma);
optimization=optim(g$coef,neg_loglikehood)




and got the warning message:

Warning messages:
1: In log(x %*% theta) : NaNs produced
2: In log(x %*% theta) : NaNs produced
3: In log(x %*% theta) : NaNs produced
4: In log(x %*% theta) : NaNs produced
5: In log(x %*% theta) : NaNs produced
6: In log(x %*% theta) : NaNs produced
7: In log(x %*% theta) : NaNs produced
8: In log(x %*% theta) : NaNs produced


However,  everything in the x %*% theta matrix is positive:

x %*% theta
           [,1]
[1,] 0.01515921
[2,] 0.01909599
[3,] 0.02303277
[4,] 0.02696955
[5,] 0.03484312
[6,] 0.04271668
[7,] 0.05846380
[8,] 0.07421093
[9,] 0.08995805
[10,] 0.01515921
[11,] 0.01909599
[12,] 0.02303277
[13,] 0.02696955
[14,] 0.03484312
[15,] 0.04271668
[16,] 0.05846380
[17,] 0.07421093
[18,] 0.08995805

and it also gave me the minimizer below:

theta=optimization$par
theta
(Intercept)      log(uu) 
0.0112224301 0.0007873562 

Can anyone tell me why the I that warning message?
Thank you very much.



More information about the R-help mailing list