After trying to run such a model I get information that the parameter b_revisit_c1 does not influence the log-likelihood of my model. Can you check, please, where the problem could be?
Code: Select all
## scaled variables
apollo_beta = c(asc_car_c1 = 0,
asc_taxi_c1 = 0,
asc_bus_c1 = 0,
asc_metro_c1 = 0,
b_cost_c1 = 0,
b_in_veh_c1 = 0,
b_park_P_c1 = 0,
b_park_A_c1 = 0,
b_park_G_c1 = 0,
b_wait_c1 = 0,
b_walk_c1 = 0,
b_transfer_c1 = 0,
b_crowd_P_c1 = 0,
b_crowd_A_c1 = 0,
b_crowd_G_c1 = 0,
b_carown_c1 = 0,
b_carmode_c1 = 0,
b_taximode_c1 = 0,
b_PTmode_c1 = 0,
b_green_PT_c1 = 0,
b_revisit_c1=0,
lambda_A_c1 = 1,
lambda_B_c1 = 0.5,
lambda_C_c1 = 1,
delta_c1 = 0,
gamma_education_c1=0,
gamma_employ_c1=0,
gamma_income_c1=0,
gamma_purpose_c1=0,
gamma_gender_c1=0,
gamma_days_c1=0,
gamma_age_c1=0,
gamma_types_c1=0,
asc_car_c2 = 0,
asc_taxi_c2 = 0,
asc_bus_c2 = 0,
asc_metro_c2 = 0,
b_cost_c2 = 0,
b_in_veh_c2 = 0,
b_park_P_c2 = 0,
b_park_A_c2 = 0,
b_park_G_c2 = 0,
b_wait_c2 = 0,
b_walk_c2 = 0,
b_transfer_c2 = 0,
b_crowd_P_c2 = 0,
b_crowd_A_c2 = 0,
b_crowd_G_c2 = 0,
b_carown_c2 = 0,
b_carmode_c2 = 0,
b_taximode_c2 = 0,
b_PTmode_c2 = 0,
b_green_PT_c2 = 0,
b_revisit_c2=0,
lambda_A_c2 = 0.5,
lambda_B_c2 = 1,
lambda_C_c2 = 1,
gamma_education_c2=0,
gamma_employ_c2=0,
gamma_income_c2=0,
gamma_purpose_c2=0,
gamma_gender_c2=0,
gamma_days_c2=0,
gamma_age_c2=0,
gamma_types_c2=0,
delta_c2 = 0)
apollo_fixed = c("asc_car_c1","asc_car_c2","delta_c2","gamma_education_c2","gamma_employ_c2","gamma_income_c2","gamma_purpose_c2","gamma_gender_c2","gamma_days_c2","gamma_age_c2","gamma_types_c2","b_crowd_P_c1","b_crowd_P_c2","b_park_P_c1","b_park_P_c2","lambda_A_c1","lambda_C_c1","lambda_B_c2","lambda_C_c2")
#"lambda_A_c1","lambda_A_c2"
## Define latent class components
apollo_lcPars = function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["b_cost"]] = list(b_cost_c1,b_cost_c2)
lcpars[["b_in_veh"]] = list(b_in_veh_c1,b_in_veh_c2)
lcpars[["b_park_P"]] = list(b_park_P_c1,b_park_P_c2)
lcpars[["b_park_A"]] = list(b_park_A_c1,b_park_A_c2)
lcpars[["b_park_G"]] = list(b_park_G_c1,b_park_G_c2)
lcpars[["b_wait"]] = list(b_wait_c1,b_wait_c2)
lcpars[["b_walk"]] = list(b_walk_c1, b_walk_c2)
lcpars[["b_transfer"]] = list(b_transfer_c1, b_transfer_c2)
lcpars[["b_crowd_P"]] = list(b_crowd_P_c1,b_crowd_P_c2)
lcpars[["b_crowd_A"]] = list(b_crowd_A_c1,b_crowd_A_c2)
lcpars[["b_crowd_G"]] = list(b_crowd_G_c1,b_crowd_G_c2)
lcpars[["asc_taxi"]] = list(asc_taxi_c1,asc_taxi_c2)
lcpars[["asc_bus"]] = list(asc_bus_c1,asc_bus_c2)
lcpars[["asc_metro"]] = list(asc_metro_c1,asc_metro_c2)
lcpars[["b_carown"]] = list(b_carown_c1,b_carown_c2)
lcpars[["b_carmode"]] = list(b_carmode_c1,b_carmode_c2)
lcpars[["b_taximode"]] = list(b_taximode_c1,b_taximode_c2)
lcpars[["b_PTmode"]] = list(b_PTmode_c1,b_PTmode_c2)
lcpars[["b_green_PT"]] = list(b_green_PT_c1,b_green_PT_c2)
lcpars[["b_revisit"]] = list(b_revisit_c1,b_revisit_c2)
#Utilities of class allocation model
V = list()
V[["class_1"]] = delta_c1+ gamma_education_c1* education+ gamma_employ_c1* employ+ gamma_income_c1* income +gamma_purpose_c1*purpose+ gamma_gender_c1*gender+gamma_days_c1*days+gamma_age_c1*age+gamma_types_c1*types
V[["class_2"]] = delta_c2+ gamma_education_c2* education+ gamma_employ_c2* employ+ gamma_income_c2* income +gamma_purpose_c2*purpose+ gamma_gender_c2*gender+gamma_days_c2*days+gamma_age_c2*age+gamma_types_c2*types
classAlloc_settings = list(
classes = c(class_1=1, class_2=2),
utilities = V
)
lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
return(lcpars)
}
#V[["class_1"]] = delta_c1 + gamma_gender_c1 * gender
#V[["class_2"]] = delta_c2 + gamma_gender_c2 * gender
### Group and validate inputs
apollo_inputs = apollo_validateInputs()
### Define model and likelihood function
apollo_probabilities = function(apollo_beta, apollo_inputs, functionality = "estimate"){
## 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()
### Specify nests for NL model
nlNests = list()
nlNests[[1]] = list(root=1, A_c1=lambda_A_c1, B_c1 = lambda_B_c1, C_c1 = lambda_C_c1)
nlNests[[2]] = list(root=1,A_c2=lambda_A_c2, B_c2 = lambda_B_c2, C_c2 = lambda_C_c2)
nlStructure = list()
nlStructure[[1]] = list()
nlStructure[[2]] = list()
nlStructure[[1]][["root"]] = c("A_c1","B_c1","C_c1")
nlStructure[[2]][["root"]] = c("A_c2","B_c2","C_c2")
nlStructure[[1]][["A_c1"]] = c("bus")
nlStructure[[1]][["B_c1"]] = c("car","metro")
nlStructure[[1]][["C_c1"]] = c("taxi")
nlStructure[[2]][["A_c2"]] = c("car","bus")
nlStructure[[2]][["B_c2"]] = c("taxi")
nlStructure[[2]][["C_c2"]] = c("metro")
nl_settings <- list(
alternatives = c(car=1, taxi=2, bus=3, metro=4),
avail = list(car=av_car, taxi=av_taxi, bus=av_bus, metro=av_metro),
choiceVar = choice,
nlNests = nlNests,
nlStructure = nlStructure
)
### Loop over classes
s=1
while(s<=2){
### Compute class-specific utilities
V=list()
V[['car']] = b_cost[[s]] * cost_car + b_crowd_A[[s]] * (crowd_car==2) +b_crowd_G[[s]] * (crowd_car==3) + b_in_veh[[s]] * in_veh_car + b_park_A[[s]] * (park_car==2)+ b_park_G[[s]] * (park_car==3) + b_carown[[s]] * (carown==1) + b_carmode[[s]] * (mianmode==1) + b_revisit[[s]] * (times==1)
V[['taxi']] = asc_taxi[[s]] + b_cost[[s]] * cost_taxi + b_crowd_A[[s]] * (crowd_taxi==2) +b_crowd_G[[s]] * (crowd_taxi==3) + b_in_veh[[s]] * in_veh_taxi + b_wait[[s]] * wait_taxi + b_taximode[[s]] * (mianmode==2) + b_revisit[[s]] * (times==1)
V[['bus']] = asc_bus[[s]] + b_cost[[s]] * cost_bus + b_crowd_A[[s]] * (crowd_bus==2) +b_crowd_G[[s]] * (crowd_bus==3) + b_in_veh[[s]] * in_veh_bus + b_wait[[s]] * wait_bus + b_walk[[s]] * walk_bus + b_transfer[[s]] * transfer_bus +b_green_PT[[s]] * (green==1) + b_PTmode[[s]] * (mianmode==3) + b_revisit[[s]] * (times==1)
V[['metro']] = asc_metro[[s]] +b_cost[[s]] * cost_metro + b_crowd_A[[s]] * (crowd_metro==2) +b_crowd_G[[s]] * (crowd_metro==3) + b_in_veh[[s]] * in_veh_metro+ b_wait[[s]] * wait_metro + b_walk[[s]] * walk_metro + b_transfer[[s]] * transfer_metro +b_green_PT[[s]] * (green==1) + b_PTmode[[s]] * (mianmode==3) + b_revisit[[s]] * (times==1)
nl_settings$V = V
nl_settings$nlNests = nlNests[[s]]
nl_settings$nlStructure = nlStructure[[s]]
P[[s]] = apollo_nl(nl_settings, functionality)
P[[s]] = apollo_panelProd(P[[s]],apollo_inputs,functionality)
s=s+1
}
lc_settings = list(inClassProb = P, classProb=pi_values)
P[["model"]] = apollo_lc(lc_settings,apollo_inputs,functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
#apollo_control$worklnLogs=TRUE
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities,apollo_inputs)
apollo_modelOutput(model,modelOutput_settings = list(printPVal=TRUE))