Dear r helpers I run the following code for nested logit and got a message that Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite What does this mean? and how can I correct it? Thank you June> yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 12784 25> choice = yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=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])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ 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[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[,4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite_________________________________________________________________ [[alternative HTML version deleted]]
On Wed, 28 Jan 2009, June Wong wrote:> > Dear r helpers > > I run the following code for nested logit and got a message that > > Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite > What does this mean? and how can I correct it?It means that your function at your starting values is evaluating to a non-finite value (+/-Inf, NA, NaN). Your example is unreadable, and we don't have the file so cannot help you debug this.> > Thank you > June > >> yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 12784 25> choice = yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=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])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ 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[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[!,!> 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite > > _________________________________________________________________ > > > > [[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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Hi all, I have two vectors like this: x <- c( "Y", "H", NA, NA ) y <- c( NA, "H", NA, "B" ) And would like to make one vector with the common elements, and the element available only in one of the vectors. res <- c( "Y", "H", NA, "B" ) Thanks, Patricia> From: neptune545@hotmail.com > To: r-help@r-project.org > Date: Wed, 28 Jan 2009 14:15:20 +0000 > Subject: [R] initial value in 'vmmin' is not finite > > > Dear r helpers > > I run the following code for nested logit and got a message that > > Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite > What does this mean? and how can I correct it? > > Thank you > June > > > yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)> dim(yogurt)[1] 12784 25> choice = yogurt[,2:5]> price=yogurt[,14:17]> feature=yogurt[,6:9]> n = nrow(yogurt)> constant = rep(1,each=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])> > fr <- function(x) { + x1 = x[1]+ x2 = x[2]+ x3 = x[3]+ x4 = x[4]+ x5 = x[5]+ x6 = x[6]+ x7 = x[7]+ con1 = rbind(x[1],x[5],x[6])+ con2 = rbind(x[2],x[5],x[6])+ con3 = rbind(x[3],x[5],x[6])+ con4 = rbind(x[5],x[6])+ rho=exp(x[7])/(1+exp(x[7]))+ 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[4]+iv)/(1+exp(x[4]+iv))+ pr1 =pp* ey/den+ pr2 =pp* ed/den+ pr3 =pp* eh/den+ pr4 =pp* ew/den+ pnp=1/(1+exp(x[4]+iv))+ likelihood = (pnp*yogurt[,1])+(pr1*yogurt[,2])+(pr2*yogurt[,3])+(pr3*yogurt[,! > 4])+(pr4*yogurt[,4])+ lsum = log(likelihood)+ return(-colSums(lsum))+ }> p = optim(c(0,0,0,0,0.1,-2,-0.2),fr, hessian = TRUE, method = "BFGS")Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite > > _________________________________________________________________ > > > > [[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._________________________________________________________________ [[alternative HTML version deleted]]
Is position important? The vectors always have the same length? They always have the same entry if both are not NA? If yes, yes and yes, then res <- ifelse( is.na(x), y, x) does what you want. Otherwise please explain better what you want. Gabor On Wed, Jan 28, 2009 at 3:54 PM, patricia garc?a gonz?lez <kurtney_84 at hotmail.com> wrote:> > Hi all, > > I have two vectors like this: > > > x <- c( "Y", "H", NA, NA ) > > y <- c( NA, "H", NA, "B" ) > > And would like to make one vector with the common elements, and the element available only in one of the vectors. > > > res <- c( "Y", "H", NA, "B" ) > > > Thanks, > > Patricia >-- Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM