Mixed logit model with socio demographics data
Posted: 23 Jun 2021, 00:13
Hello Prof. Hess,
I specified a model in MNL form with socio demographics data. I would like to develop that in MMNL to compare the results. Just wondering if there is any sample on that to have a look? In my MMNL not sure where I'm doing wrong that I get NAs. Which is not the case in MNL.
BTW, I'm working with dummy values for now until I receive the data, so Rho-square may not make sense.
Regards,
Maisie
RESULTS:
Estimation method : bfgs
Model diagnosis : iteration limit exceeded
Number of individuals : 12
Number of rows in database : 108
Number of modelled outcomes : 108
Number of cores used : 4
Number of inter-individual draws : 100 (halton)
Number of intra-individual draws : 100 (mlhs)
LL(start) : -141.8176
LL(0) : -74.8599
LL(final) : -69.67577
Rho-square (0) : 0.0693
Adj.Rho-square (0) : -0.1979
AIC : 179.35
BIC : 232.99
Estimated parameters : 20
Time taken (hh:mm:ss) : 00:26:44.84
pre-estimation : 00:00:20.36
estimation : 00:26:23.15
post-estimation : 00:00:1.33
Iterations : 202 (iteration limit exceeded )
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
mu_log_b_pc -15.060869 NA NA NA NA
sigma_log_b_pc -1.327230 NA NA NA NA
mu_log_b_pt 4.628390 NA NA NA NA
sigma_log_b_pt -0.003218 NA NA NA NA
sigma_log_b_pt_inter 0.001371 NA NA NA NA
sigma_log_b_pt_intera -0.039830 NA NA NA NA
mu_log_b_es 4.702541 NA NA NA NA
sigma_log_b_es 0.004531 NA NA NA NA
mu_log_b_eb -7.692006 NA NA NA NA
sigma_log_b_eb -0.005519 NA NA NA NA
mu_log_b_rs -7.939968 NA NA NA NA
sigma_log_b_rs 0.072400 NA NA NA NA
mu_log_b_cs 4.414534 NA NA NA NA
sigma_log_b_cs 0.010955 NA NA NA NA
b_cost_shift_female -8.9257e-04 NA NA NA NA
b_cost_shift_age 0.004253 NA NA NA NA
b_pt_shift_car_availability -113.129184 NA NA NA NA
b_pt_shift_child -20.178565 NA NA NA NA
b_cost_shift_disability -0.009708 NA NA NA NA
b_cost_shift_income -1.6089e-04 NA NA NA NA
MODEL:
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
mu_log_b_pc =-2,
sigma_log_b_pc = 0,
mu_log_b_pt =2,
sigma_log_b_pt = 0,
sigma_log_b_pt_inter = 0,
sigma_log_b_pt_intera = 0,
mu_log_b_es =2,
sigma_log_b_es = 0,
mu_log_b_eb =2,
sigma_log_b_eb = 0,
mu_log_b_rs =2,
sigma_log_b_rs = 0,
mu_log_b_cs =2,
sigma_log_b_cs = 0,
b_cost_shift_female = 0,
b_cost_shift_age = 0,
b_pt_shift_car_availability = 0,
b_pt_shift_child = 0,
b_cost_shift_disability = 0,
b_cost_shift_income = 0)
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 100,
interUnifDraws = c("draws_pc"),
interNormDraws = c("draws_pt","draws_es","draws_eb","draws_rs","draws_cs"),
intraDrawsType = "mlhs",
intraNDraws = 100,
intraUnifDraws = c(),
intraNormDraws = c("draws_pt_intra")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_pc"]] = -exp( mu_log_b_pc + sigma_log_b_pc * draws_pc )
randcoeff[["b_pt"]] = exp( mu_log_b_pt + sigma_log_b_pt * draws_pt
+ sigma_log_b_pt_inter * draws_pt ^2
+ sigma_log_b_pt_intera * draws_pt_intra)
randcoeff[["b_es"]] = exp( mu_log_b_es + sigma_log_b_es * draws_es )
randcoeff[["b_eb"]] = exp( mu_log_b_eb + sigma_log_b_eb * draws_eb )
randcoeff[["b_rs"]] = exp( mu_log_b_rs + sigma_log_b_rs * draws_rs )
randcoeff[["b_cs"]] = exp( mu_log_b_cs + sigma_log_b_cs * draws_cs )
return(randcoeff)
}
.....
### Create alternative specific constants and coefficients using interactions with socio-demographics
b_pc_value= b_pc + b_cost_shift_female*female + b_cost_shift_age*age_cate + b_cost_shift_disability*disability + b_cost_shift_income *income_adj
b_pt_value= b_pt + b_pt_shift_car_availability*car_availability + b_pt_shift_child*child
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['alt1']] = b_pc_value *( pc1 + b_pt_value * pt1 + b_es * es1 + b_eb * eb1 + b_rs * rs1 + b_cs * cs1)
V[['alt2']] = b_pc_value *( pc2 + b_pt_value * pt2 + b_es * es2 + b_eb * eb2 + b_rs * rs2 + b_cs * cs2)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V
)
I specified a model in MNL form with socio demographics data. I would like to develop that in MMNL to compare the results. Just wondering if there is any sample on that to have a look? In my MMNL not sure where I'm doing wrong that I get NAs. Which is not the case in MNL.
BTW, I'm working with dummy values for now until I receive the data, so Rho-square may not make sense.
Regards,
Maisie
RESULTS:
Estimation method : bfgs
Model diagnosis : iteration limit exceeded
Number of individuals : 12
Number of rows in database : 108
Number of modelled outcomes : 108
Number of cores used : 4
Number of inter-individual draws : 100 (halton)
Number of intra-individual draws : 100 (mlhs)
LL(start) : -141.8176
LL(0) : -74.8599
LL(final) : -69.67577
Rho-square (0) : 0.0693
Adj.Rho-square (0) : -0.1979
AIC : 179.35
BIC : 232.99
Estimated parameters : 20
Time taken (hh:mm:ss) : 00:26:44.84
pre-estimation : 00:00:20.36
estimation : 00:26:23.15
post-estimation : 00:00:1.33
Iterations : 202 (iteration limit exceeded )
Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
mu_log_b_pc -15.060869 NA NA NA NA
sigma_log_b_pc -1.327230 NA NA NA NA
mu_log_b_pt 4.628390 NA NA NA NA
sigma_log_b_pt -0.003218 NA NA NA NA
sigma_log_b_pt_inter 0.001371 NA NA NA NA
sigma_log_b_pt_intera -0.039830 NA NA NA NA
mu_log_b_es 4.702541 NA NA NA NA
sigma_log_b_es 0.004531 NA NA NA NA
mu_log_b_eb -7.692006 NA NA NA NA
sigma_log_b_eb -0.005519 NA NA NA NA
mu_log_b_rs -7.939968 NA NA NA NA
sigma_log_b_rs 0.072400 NA NA NA NA
mu_log_b_cs 4.414534 NA NA NA NA
sigma_log_b_cs 0.010955 NA NA NA NA
b_cost_shift_female -8.9257e-04 NA NA NA NA
b_cost_shift_age 0.004253 NA NA NA NA
b_pt_shift_car_availability -113.129184 NA NA NA NA
b_pt_shift_child -20.178565 NA NA NA NA
b_cost_shift_disability -0.009708 NA NA NA NA
b_cost_shift_income -1.6089e-04 NA NA NA NA
MODEL:
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta=c(
mu_log_b_pc =-2,
sigma_log_b_pc = 0,
mu_log_b_pt =2,
sigma_log_b_pt = 0,
sigma_log_b_pt_inter = 0,
sigma_log_b_pt_intera = 0,
mu_log_b_es =2,
sigma_log_b_es = 0,
mu_log_b_eb =2,
sigma_log_b_eb = 0,
mu_log_b_rs =2,
sigma_log_b_rs = 0,
mu_log_b_cs =2,
sigma_log_b_cs = 0,
b_cost_shift_female = 0,
b_cost_shift_age = 0,
b_pt_shift_car_availability = 0,
b_pt_shift_child = 0,
b_cost_shift_disability = 0,
b_cost_shift_income = 0)
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 100,
interUnifDraws = c("draws_pc"),
interNormDraws = c("draws_pt","draws_es","draws_eb","draws_rs","draws_cs"),
intraDrawsType = "mlhs",
intraNDraws = 100,
intraUnifDraws = c(),
intraNormDraws = c("draws_pt_intra")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_pc"]] = -exp( mu_log_b_pc + sigma_log_b_pc * draws_pc )
randcoeff[["b_pt"]] = exp( mu_log_b_pt + sigma_log_b_pt * draws_pt
+ sigma_log_b_pt_inter * draws_pt ^2
+ sigma_log_b_pt_intera * draws_pt_intra)
randcoeff[["b_es"]] = exp( mu_log_b_es + sigma_log_b_es * draws_es )
randcoeff[["b_eb"]] = exp( mu_log_b_eb + sigma_log_b_eb * draws_eb )
randcoeff[["b_rs"]] = exp( mu_log_b_rs + sigma_log_b_rs * draws_rs )
randcoeff[["b_cs"]] = exp( mu_log_b_cs + sigma_log_b_cs * draws_cs )
return(randcoeff)
}
.....
### Create alternative specific constants and coefficients using interactions with socio-demographics
b_pc_value= b_pc + b_cost_shift_female*female + b_cost_shift_age*age_cate + b_cost_shift_disability*disability + b_cost_shift_income *income_adj
b_pt_value= b_pt + b_pt_shift_car_availability*car_availability + b_pt_shift_child*child
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[['alt1']] = b_pc_value *( pc1 + b_pt_value * pt1 + b_es * es1 + b_eb * eb1 + b_rs * rs1 + b_cs * cs1)
V[['alt2']] = b_pc_value *( pc2 + b_pt_value * pt2 + b_es * es2 + b_eb * eb2 + b_rs * rs2 + b_cs * cs2)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = choice,
V = V
)