R mlogit marginal effects with alternative-invariant variables only

#1
Hi everyone,

can someone explain how to calculate the marginal effects of a multinomial logit model with alternative-invariant variables (e.g. income) only. A similar question was asked here but not answered sufficiently. The calculation works only, if I also include alternative-variant variables (e.g. catch rate and price). See mlogit standard example:

Example including alternative-invariant and -variant variables (works):

Code:
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")

m1 <- mlogit(mode ~ price | income | catch, data = Fish)

z1 <- with(Fish, data.frame(price = tapply(price, index(m1)$alt, mean), 
                           catch = tapply(catch, index(m1)$alt, mean), 
                           income = mean(income)))

effects(m1, covariate = "income", data = z1)
It does not work, if I include "income" only.

Example including alternative-variant variables only (does not work)

Code:
m2 <- mlogit(mode ~ 0 | income, data = Fish)
z2 <- ??? # I think this is the problem to calculate
effects(m2, covariate = "income", data = z2)
Does someone know how to specify the z2 function?

Best regards
Thomas
 
Last edited:
#2
Ok, found the solution. The data.frame z simply needs to be a data.frame with the mean of the alternative-invarianbe variable (i.e., income) repeated as many times as there are alternatives (i.e., four times in this case). Make sure the name of the variable in the data.frame is the same as in the mlogit model (i.e., income).

Code:
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")

m2 <- mlogit(mode ~ 0 | income, data = Fish)
z2 <- data.frame(income = rep(mean(Fish$income),4))
effects(m2, covariate = "income", data = z2)
Best regards
Thomas