I’m using the mlogit package in R to estimate a mixed logit model with a log-normal parameter. The package runs fine, but is there a way to extact the random coefficients, particularly for non-normally distributed parameters?
Using an example from “Kenneth Train’s exercises using the mlogit package for R”, p 22,
library(mlogit)
data("Electricity", package = "mlogit")
Electr <- mlogit.data(Electricity, id = "id", choice = "choice",
varying = 3:26, shape = "wide", sep = "")
Electr$rev.tod <- -1*Electr$tod # Reverse sign on tod parameter
Elec.mxl <- mlogit(choice ~ pf + cl + loc + wk + rev.tod + seas | 0, data=Electr,
rpar = c(cl = "n", loc = "n", wk = "u", rev.tod = "ln", seas = "n"),
R = 100, halton = NA, print.level = 0, panel = TRUE)
summary(Elec.mxl)
Generates this (truncated) output:
Coefficients :
Estimate Std. Error t-value Pr(>|t|)
pf -0.866325 0.032452 -26.696 < 2.2e-16 ***
cl -0.203770 0.013411 -15.194 < 2.2e-16 ***
loc 2.038715 0.079918 25.510 < 2.2e-16 ***
wk 1.481339 0.065181 22.727 < 2.2e-16 ***
rev.tod 2.105324 0.033971 61.973 < 2.2e-16 ***
seas -8.490331 0.279262 -30.403 < 2.2e-16 ***
sd.cl 0.360140 0.017474 20.610 < 2.2e-16 ***
sd.loc 1.575765 0.089507 17.605 < 2.2e-16 ***
sd.wk 1.600303 0.122982 13.012 < 2.2e-16 ***
sd.rev.tod 0.390088 0.021940 17.780 < 2.2e-16 ***
sd.seas 1.997713 0.106031 18.841 < 2.2e-16 ***
random coefficients
Min. 1st Qu. Median Mean 3rd Qu. Max.
cl -Inf -0.4466810 -0.2037701 -0.2037701 0.03914082 Inf
loc -Inf 0.9758776 2.0387151 2.0387151 3.10155255 Inf
wk -0.1189636 0.6811879 1.4813394 1.4813394 2.28149087 3.081642
rev.tod 0.0000000 6.3104924 8.2097637 8.8587752 10.68065958 Inf
seas -Inf -9.8377681 -8.4903311 -8.4903311 -7.14289412 Inf
Is there any way to extract the mean of these random coefficients? This is mainly an issue for the non-normally distributed parameters. As pointed out by Train & Croissant, you can use the following code to calculate the mean coefficient for a log-normally distributed parameter, but I’m wondering if there is a more straightforward (and simpler!) approach.
-exp(coef(Elec.mxl)["rev.tod"]+(0.5*(coef(Elec.mxl)["sd.rev.tod"])**2))
Actually … it generates no output. You must have also executed
summary(Elec.mxl). The other problem besides not telling us the source of the output is that the mean of a sequence that includes -Inf is going to be either -Inf or undefined depending on the pleasures of the authors of the system. If you mean the column named “Mean” then (after looking at the structure of the summary object) this should do the trick:You did say you wanted only the random coefficients, right? (Aren’t you a bit worried about a logit model that is producing coeffocients on the order of 8? at least in regular logit models it generally indicates a data situation that is creating pathological results.)