1

I have run a Nested Logit model in R using the mlogit() package. I am now trying to measure marginal effects/elasticities and continue to run into an error. Here I have recreated the error by modifying the vignette by the package author:

data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
m <- mlogit(mode ~ price | income | catch, data = Fish,
            nests=list(water=c("boat","charter"),
                       land=c("beach","pier")))
# compute a data.frame containing the mean value of the covariates in the sample
 z <- with(Fish, data.frame(price = tapply(price, index(m)$alt, mean), 
                                                         catch = tapply(catch, index(m)$alt, mean), 
                                                        income = mean(income)))
# compute the marginal effects (the second one is an elasticity
 effects(m, covariate = "income", data = z) 

I get the following error:

Error in `colnames<-`(`*tmp*`, value = c("beach", "boat", "charter", "pier" : 
  attempt to set 'colnames' on an object with less than two dimensions
In addition: Warning message:
In cbind(Gb, Gl) :
  number of rows of result is not a multiple of vector length (arg 2)

This works fine when I do not have a nested model (like a regular Multinomial Logit), and that has been covered in some previous stackoverflow questions, but something weird is happening specifically with the step of re-predicting on a changed data frame (in this case the means frame z).

Ill note that the solution here: marginal effects of mlogit in R did not help me.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
royburst
  • 73
  • 1
  • 5
  • Looking at the predict method in mlogit I see the following key line of code: newobject <- update(object, start = coef(object), data = newdata, iterlim = 0, print.level = 0). Looks to me like this is actually trying to refit the model! No wonder it breaks when I try to predict everything out at the means with a nested logit. What do you all think? – royburst May 19 '15 at 21:24

0 Answers0