Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Getting error in Binary logit model

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
Post Reply
sethyash52
Posts: 11
Joined: 09 Sep 2022, 06:38

Getting error in Binary logit model

Post by sethyash52 »

I am getting an error showing " initial value of vmmin is not finite" in the constant-only binary choice model. I have tried updating my software and putting Hessian = FALSE but still showing the same error.
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Getting error in Binary logit model

Post by stephanehess »

Hi

it's impossible to help you with this without seeing the code, so could you please post the code, along with the output you see

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
sethyash52
Posts: 11
Joined: 09 Sep 2022, 06:38

Re: Getting error in Binary logit model

Post by sethyash52 »

I forgot to attach the output so I am attaching my console window here

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rm(list=ls())
>
> setwd("D:\\PROJECT\\MNL_Analysis") ## set your working directory
>
> getwd() # check whether the working directory you have set is correct; make sure that the code and dataset are in this directory
[1] "D:/PROJECT/MNL_Analysis"
>
> #---------------------------------- install required packages and load the corresponding libraries --------------------------#
>
> #install.packages("reshape") # you need not install a package again if already installed
> library(reshape) # load the corresponding library you require
> #install.packages("optimx")
> library(optimx)
>
>
>
> #------------------------------------------- reading in data ---------------------------------------------------------------#
> Data = read.csv("fourWheelerFaceToFace_V1(coded)_working.csv") # read the data file: your data must be in csv formatto use this command
>
>
> Dmat = as.matrix(Data) # convert the data file into a matrix
>
>
> #number of rows in the data; no. of rows excluding the header: this is the no. of individuals in a case-format data file
> NCS = nrow(Dmat)
>
> # specify the number of choice alternatives
> numuoalt = 2; #can be greater than or equal to 2
>
>
> #------------------------------------ specification of dependent variables ---------------------------------------------------#
> ### extract the columns from your data; be sure that the column number is correct, and in order of the utility you specify below
>
> IDDEP = as.matrix(Dmat[,c(3,4)])
>
>
> #------------------------------------ specification of utlities --------------------------------------------------------------#
> ## please be sure to extract the correct column from the data file using the column number
> ## define for the number of alts. in the model
>
>
> alt1_x = as.matrix(Dmat[,c(5)])
> at1 = t(alt1_x)
>
> alt2_x = as.matrix(Dmat[,c(6)])
> at2 = t(alt2_x)
> #------------------------------------ create a matrix of all explanatory variables based on your utility specification above --------------------------------------------------------------#
>
>
> alt_x = as.matrix(cbind(at1,at2))
>
>
> #-----------------------: specify a vector of starting values: here, all starting values have been kept as 0
> #-----------------------: the number of elements here should be equal to the number of parameters to be estimated
>
> nvar = ncol(at1)
> startv =matrix(0,1,1)
>
>
> #-------------------------------------- loglikelihood function: this is generic; does not depend on number of choice alt -----------------------------------------------------------#
>
> logit.lf <- function(beta) {
+ p = matrix(0, nrow=NCS, ncol=1) ### create a vector for choice prob
+ v1 = matrix(0, NCS, numuoalt) ### matrix of utilities: size NCS*numuoalt
+ v1 = t(beta)%*% alt_x ### compute V = beta*X
+ v1 = matrix(v1, nrow = numuoalt, byrow = TRUE) ### we need an NCS*1 row vector for each alternative
+ v1 = t(v1)
+ v1=exp(v1) ### calculate exp(V)
+ den = as.matrix(rowSums(v1)) ### denominator of logit choice prob.
+ vchoice = v1*IDDEP ### deterministic comp. for chosen alt. only: numerator in logit choice prob.
+ p = rowSums(vchoice)/den ### choice prob.
+ logl = -sum(log(p)) ### calculate log-likelihood
+ return(logl)
+ }
>
>
> #--------------------------------------------------- Model estimation --------------------------------------------------------------#
>
> logitmodel <- optim(startv, logit.lf, method="BFGS", control=list(trace=TRUE, REPORT=1),hessian=TRUE) # calling an R routine for optimization
Error in optim(startv, logit.lf, method = "BFGS", control = list(trace = TRUE, :
initial value in 'vmmin' is not finite
>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Getting error in Binary logit model

Post by stephanehess »

This is not using Apollo, so not for this forum
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply