# [R] initial gradient and vmmin not finite

Mon Mar 2 20:59:07 CET 2009

```Hi June:

What does
fr( c(0,0,0,1,0,-25,-0.2) )
return?

Arne

On Monday, 2. March 2009 11:55:56, June Wong wrote:
> Dear Rhelpers
>
> I have the problem with initial values, could you please tell me how to
> solve it? Thank you
> June
>
> > p = summary(maxLik(fr,start=c(0,0,0,1,0,-25,-0.2)))
>
> Error in maxRoutine(fn = logLik, grad = grad, hess = hess, start = start,
> :
>
>   NA in the initial gradient
>
> > p = summary(maxLik(fr,start=c(0,0,0,1,0,-25,-0.2),method="BFGS"))
>
> Error in optim(start, func, gr = gradient, control = control, method =
> "BFGS",  :
>
>   initial value in 'vmmin' is not finite
>
> The codes are as follows
>
> attach(yogurt)
> dim(yogurt)
> choice = yogurt[,2:5]
> price=yogurt[,14:17]
> feature=yogurt[,6:9]
> n = nrow(yogurt)
> constant = rep(1,n)
> yop=cbind(constant,feature[,1],price[,1])
> dan=cbind(constant,feature[,2],price[,2])
> hil=cbind(constant,feature[,3],price[,3])
> wt=cbind(feature[,4],price[,4])
>
> library(maxLik)
> fr <- function(x) {
> con1 = rbind(x,x,x)
> con2 = rbind(x,x,x)
> con3 = rbind(x,x,x)
> con4 = rbind(x,x)
> rho = exp(x)/(1+exp(x))
> ey = exp((yop%*%con1)/rho)
> ed = exp((dan%*%con2)/rho)
> eh = exp((hil%*%con3)/rho)
> ew = exp((wt%*%con4)/rho)
> ev = ey+ed+eh+ew
> den=(ey+ed+eh+ew)
> iv = rho*log(den)
> pp=exp(x+iv)/(1+exp(x+iv))
> pr1 =pp*(ey/den)
> pr2 =pp*(ed/den)
> pr3 =pp*(eh/den)
> pr4 =pp*(ew/den)
> pnp=1/(1+exp(x+iv))
> likelihood =
> (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[,4])+(pr4*yo
>gurt[,4]) lsum = log(likelihood)
> return(colSums(lsum))
> }
> p = summary(maxLik(fr,start=c(0,0,0,1,0,-25,-0.2)))
> p
>
>
>
>
> _________________________________________________________________
>
>
> cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help