Page 1 of 1

Getting error in Binary logit model

Posted: 09 Sep 2022, 06:45
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.

Re: Getting error in Binary logit model

Posted: 09 Sep 2022, 11:20
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

Re: Getting error in Binary logit model

Posted: 10 Sep 2022, 10:38
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
>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Re: Getting error in Binary logit model

Posted: 10 Sep 2022, 21:20
by stephanehess
This is not using Apollo, so not for this forum