Interpretation of ASC shifts in Mixed logit model
Posted: 28 Oct 2024, 22:47
Hello,
Please may I ask for some guidance on interpreting the parameters of the ASC shifts. I have estimated a Mixed logit with deterministic heterogeneity based on socio-demographics, and random heterogeneity for the attributes (Normal / Log Normal for costs). What I am not too sure on is interpreting the ASC shifts (interacted with the socio-demographics). Are they interpreted in comparison to the fixed ASC, or in relation to the base ASC?
Thank you,
My code is as follows:
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
library(readxl)
database= read_excel("~/Desktop/5.PhD Data Analysis/Final data March 24/GEMS_full_data_clean_072024.xlsx")
database <- as.data.frame(database)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c (asc_GDH = 0,
asc_HB_base = -0.417987981078515,
asc_HB_shift_age = -0.000006576788541,
asc_HB_shift_own_home = -0.172911424845596,
asc_HB_shift_time_home = 0.005804949359464,
asc_HB_shift_time_home_exp = 0.011078526872732,
asc_HB_shift_energy_eff = 0.401480915827985,
asc_HB_shift_heat_type_SEB = -0.378367338786279,
asc_HB_shift_vehicle = 0.129490126151764,
asc_SEB_base = 0.036123749627697,
asc_SEB_shift_age = -0.007876528078052,
asc_SEB_shift_hh_size = 0.030708165261368,
asc_SEB_shift_own_home = -0.406770861915822,
asc_SEB_shift_time_home = -0.017861791384544,
asc_SEB_shift_time_home_exp = 0.005958891796782,
asc_SEB_shift_energy_eff = 0.562745824365959,
asc_SEB_shift_heat_type_SEB = 0.931629474692535,
asc_ASHP_base = 0.294174276687739,
asc_ASHP_shift_age = -0.021291954519979,
asc_ASHP_shift_bedrooms = -0.190503565914332,
asc_ASHP_shift_own_home = -0.406627539945095,
asc_ASHP_shift_time_home = -0.024110068663101,
asc_ASHP_shift_time_home_exp = 0.025144789672796,
asc_ASHP_shift_energy_eff = 0.693991577526987,
asc_ASHP_shift_heat_type_ASHP = 0.928449838191297,
b_income = 0.035507623124387,
b_ic_mu = -0.097310888453008,
b_ic_sig = 0.007572013090580,
b_mc_mu = -0.774384919567975,
b_mc_sig = 0.023587111440034,
b_rp_mu = 0.033464397621852,
b_rp_sig = 0.003104653980893,
b_co2_mu = -0.078783918091262,
b_co2_sig = 0.005352128606680,
b_jc_mu = 0.006782241699742,
b_jc_sig = 0.001142904793546)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_GDH")
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 1000,
interNormDraws = c("draws_ic","draws_mc","draws_rp", "draws_co2","draws_jc")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_inv_cost"]] = -exp(b_ic_mu + b_ic_sig * draws_ic)
randcoeff[["b_monthly_cost"]] = -exp(b_mc_mu + b_mc_sig * draws_mc)
randcoeff[["b_replace_period"]] = b_rp_mu + b_rp_sig * draws_rp
randcoeff[["b_CO2"]] = b_co2_mu + b_co2_sig * draws_co2
randcoeff[["b_job"]] = b_jc_mu + b_jc_sig * draws_jc
return(randcoeff)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Create alternative specific constants and coefficients with interactions with socio-demographics
asc_HB = asc_HB_base + asc_HB_shift_age*Q22_age + asc_HB_shift_own_home*Q34_own_home + asc_HB_shift_time_home*Q37_time_home + asc_HB_shift_time_home_exp*Q38_time_home_exp + asc_HB_shift_energy_eff*Q41_energy_eff + asc_HB_shift_heat_type_SEB*Q39_heat_type_SEB + asc_HB_shift_vehicle*Q33_vehicle
asc_SEB = asc_SEB_base + asc_SEB_shift_age*Q22_age + asc_SEB_shift_hh_size*Q25_hh_size + asc_SEB_shift_own_home*Q34_own_home + asc_SEB_shift_time_home*Q37_time_home + asc_SEB_shift_time_home_exp*Q38_time_home_exp + asc_SEB_shift_energy_eff*Q41_energy_eff + asc_SEB_shift_heat_type_SEB*Q39_heat_type_SEB
asc_ASHP = asc_ASHP_base + asc_ASHP_shift_age*Q22_age + asc_ASHP_shift_bedrooms*Q36_bedrooms + asc_ASHP_shift_own_home*Q34_own_home + asc_ASHP_shift_time_home*Q37_time_home + asc_ASHP_shift_time_home_exp*Q38_time_home_exp + asc_ASHP_shift_energy_eff*Q41_energy_eff + asc_ASHP_shift_heat_type_ASHP*Q39_heat_type_ASHP
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[["GDH"]] = asc_GDH + b_inv_cost*(inv_cost_GDH_/1000) + b_monthly_cost*(monthly_cost_GDH_/100) + b_replace_period*replace_period_GDH_ + b_CO2*(CO2_GDH_/1000) + b_job*job_GDH_
V[["HB"]] = asc_HB + + b_inv_cost*(inv_cost_HB_/1000) + b_monthly_cost*(monthly_cost_HB_/100) + b_replace_period*replace_period_HB_ + b_CO2*(CO2_HB_/1000) + b_job*job_HB_ + b_income*(Q32_income/10000)
V[["SEB"]] = asc_SEB + b_inv_cost*(inv_cost_SEB_/1000) + b_monthly_cost*(monthly_cost_SEB_/100) + b_replace_period*replace_period_SEB_ + b_CO2*(CO2_SEB_/1000) + b_job*job_SEB_ + b_income*(Q32_income/10000)
V[["ASHP"]] = asc_ASHP + b_inv_cost*(inv_cost_ASHP_/1000) + b_monthly_cost*(monthly_cost_ASHP_/100) + b_replace_period*replace_period_ASHP_ + b_CO2*(CO2_ASHP_/1000) + b_job*job_ASHP_+ b_income*(Q32_income/10000)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(GDH=1, HB=2, SEB=3, ASHP=4),
choiceVar = choice,
utilities = V
)
### Compute probabilities using MNL model
P[["model"]] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
### Optional speedTest
#speedTest_settings=list(
# nDrawsTry = c(100, 200, 500),
# nCoresTry = c(1,3,5,7),
# nRep = 30
#)
#apollo_speedTest(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, speedTest_settings)
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
# ################################################################# #
##### POST-PROCESSING ####
# ################################################################# #
### Print outputs of additional diagnostics to new output file (remember to close file writing when complete)
apollo_sink()
Please may I ask for some guidance on interpreting the parameters of the ASC shifts. I have estimated a Mixed logit with deterministic heterogeneity based on socio-demographics, and random heterogeneity for the attributes (Normal / Log Normal for costs). What I am not too sure on is interpreting the ASC shifts (interacted with the socio-demographics). Are they interpreted in comparison to the fixed ASC, or in relation to the base ASC?
Thank you,
My code is as follows:
# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #
### Loading data from package
### if data is to be loaded from a file (e.g. called data.csv),
### the code would be: database = read.csv("data.csv",header=TRUE)
library(readxl)
database= read_excel("~/Desktop/5.PhD Data Analysis/Final data March 24/GEMS_full_data_clean_072024.xlsx")
database <- as.data.frame(database)
# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c (asc_GDH = 0,
asc_HB_base = -0.417987981078515,
asc_HB_shift_age = -0.000006576788541,
asc_HB_shift_own_home = -0.172911424845596,
asc_HB_shift_time_home = 0.005804949359464,
asc_HB_shift_time_home_exp = 0.011078526872732,
asc_HB_shift_energy_eff = 0.401480915827985,
asc_HB_shift_heat_type_SEB = -0.378367338786279,
asc_HB_shift_vehicle = 0.129490126151764,
asc_SEB_base = 0.036123749627697,
asc_SEB_shift_age = -0.007876528078052,
asc_SEB_shift_hh_size = 0.030708165261368,
asc_SEB_shift_own_home = -0.406770861915822,
asc_SEB_shift_time_home = -0.017861791384544,
asc_SEB_shift_time_home_exp = 0.005958891796782,
asc_SEB_shift_energy_eff = 0.562745824365959,
asc_SEB_shift_heat_type_SEB = 0.931629474692535,
asc_ASHP_base = 0.294174276687739,
asc_ASHP_shift_age = -0.021291954519979,
asc_ASHP_shift_bedrooms = -0.190503565914332,
asc_ASHP_shift_own_home = -0.406627539945095,
asc_ASHP_shift_time_home = -0.024110068663101,
asc_ASHP_shift_time_home_exp = 0.025144789672796,
asc_ASHP_shift_energy_eff = 0.693991577526987,
asc_ASHP_shift_heat_type_ASHP = 0.928449838191297,
b_income = 0.035507623124387,
b_ic_mu = -0.097310888453008,
b_ic_sig = 0.007572013090580,
b_mc_mu = -0.774384919567975,
b_mc_sig = 0.023587111440034,
b_rp_mu = 0.033464397621852,
b_rp_sig = 0.003104653980893,
b_co2_mu = -0.078783918091262,
b_co2_sig = 0.005352128606680,
b_jc_mu = 0.006782241699742,
b_jc_sig = 0.001142904793546)
### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("asc_GDH")
# ################################################################# #
#### DEFINE RANDOM COMPONENTS ####
# ################################################################# #
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 1000,
interNormDraws = c("draws_ic","draws_mc","draws_rp", "draws_co2","draws_jc")
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_inv_cost"]] = -exp(b_ic_mu + b_ic_sig * draws_ic)
randcoeff[["b_monthly_cost"]] = -exp(b_mc_mu + b_mc_sig * draws_mc)
randcoeff[["b_replace_period"]] = b_rp_mu + b_rp_sig * draws_rp
randcoeff[["b_CO2"]] = b_co2_mu + b_co2_sig * draws_co2
randcoeff[["b_job"]] = b_jc_mu + b_jc_sig * draws_jc
return(randcoeff)
}
# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #
apollo_inputs = apollo_validateInputs()
# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### Function initialisation: do not change the following three commands
### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
### Create list of probabilities P
P = list()
### Create alternative specific constants and coefficients with interactions with socio-demographics
asc_HB = asc_HB_base + asc_HB_shift_age*Q22_age + asc_HB_shift_own_home*Q34_own_home + asc_HB_shift_time_home*Q37_time_home + asc_HB_shift_time_home_exp*Q38_time_home_exp + asc_HB_shift_energy_eff*Q41_energy_eff + asc_HB_shift_heat_type_SEB*Q39_heat_type_SEB + asc_HB_shift_vehicle*Q33_vehicle
asc_SEB = asc_SEB_base + asc_SEB_shift_age*Q22_age + asc_SEB_shift_hh_size*Q25_hh_size + asc_SEB_shift_own_home*Q34_own_home + asc_SEB_shift_time_home*Q37_time_home + asc_SEB_shift_time_home_exp*Q38_time_home_exp + asc_SEB_shift_energy_eff*Q41_energy_eff + asc_SEB_shift_heat_type_SEB*Q39_heat_type_SEB
asc_ASHP = asc_ASHP_base + asc_ASHP_shift_age*Q22_age + asc_ASHP_shift_bedrooms*Q36_bedrooms + asc_ASHP_shift_own_home*Q34_own_home + asc_ASHP_shift_time_home*Q37_time_home + asc_ASHP_shift_time_home_exp*Q38_time_home_exp + asc_ASHP_shift_energy_eff*Q41_energy_eff + asc_ASHP_shift_heat_type_ASHP*Q39_heat_type_ASHP
### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()
V[["GDH"]] = asc_GDH + b_inv_cost*(inv_cost_GDH_/1000) + b_monthly_cost*(monthly_cost_GDH_/100) + b_replace_period*replace_period_GDH_ + b_CO2*(CO2_GDH_/1000) + b_job*job_GDH_
V[["HB"]] = asc_HB + + b_inv_cost*(inv_cost_HB_/1000) + b_monthly_cost*(monthly_cost_HB_/100) + b_replace_period*replace_period_HB_ + b_CO2*(CO2_HB_/1000) + b_job*job_HB_ + b_income*(Q32_income/10000)
V[["SEB"]] = asc_SEB + b_inv_cost*(inv_cost_SEB_/1000) + b_monthly_cost*(monthly_cost_SEB_/100) + b_replace_period*replace_period_SEB_ + b_CO2*(CO2_SEB_/1000) + b_job*job_SEB_ + b_income*(Q32_income/10000)
V[["ASHP"]] = asc_ASHP + b_inv_cost*(inv_cost_ASHP_/1000) + b_monthly_cost*(monthly_cost_ASHP_/100) + b_replace_period*replace_period_ASHP_ + b_CO2*(CO2_ASHP_/1000) + b_job*job_ASHP_+ b_income*(Q32_income/10000)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(GDH=1, HB=2, SEB=3, ASHP=4),
choiceVar = choice,
utilities = V
)
### Compute probabilities using MNL model
P[["model"]] = apollo_mnl(mnl_settings, functionality)
### Take product across observation for same individual
P = apollo_panelProd(P, apollo_inputs, functionality)
### Average across inter-individual draws
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #
### Optional speedTest
#speedTest_settings=list(
# nDrawsTry = c(100, 200, 500),
# nCoresTry = c(1,3,5,7),
# nRep = 30
#)
#apollo_speedTest(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, speedTest_settings)
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs)
# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #
apollo_modelOutput(model)
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
# ################################################################# #
##### POST-PROCESSING ####
# ################################################################# #
### Print outputs of additional diagnostics to new output file (remember to close file writing when complete)
apollo_sink()