MNL model with socio demographics
Posted: 25 Oct 2021, 08:23
Hello,
I need help with the specification of my model. I would like to analyze my data by age groups, gender, income and area character (Gebietstyp). However, I need help to integrate them in the code. So far I have always received errors.
I already tried to integrate the age. Alter = age
Can you please help me to find the problem?
Thank you very much,
Nina
choiceAnalysis_settings <- list(
alternatives = c(altA=1, altB=2, statusquo=3),
avail = list(altA = 1, altB = 1, statusquo = 1),
choiceVar = database$choice,
explanators = database[, c("Gebietstyp")]
)
apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database)
## Parameter
apollo_beta <- c(
b10 = 0,
b11 = 0,
b12 = 0,
b10_shift_Alter = 0,
b11_shift_Alter = 0,
b12_shift_Alter = 0,
b20 = 0,
b21 = 0,
b22 = 0,
b23 = 0,
b20_shift_Alter = 0,
b21_shift_Alter = 0,
b22_shift_Alter = 0,
b23_shift_Alter = 0,
b30 = 0,
b30_shift_Alter = 0,
b40 = 0,
b41 = 0,
b42 = 0,
b40_shift_Alter = 0,
b41_shift_Alter = 0,
b42_shift_Alter = 0,
b50 = 0,
b50_shift_Alter = 0,
b60 = 0)
apollo_fixed = c("b12", "b23", "b42")
apollo_inputs <- apollo_validateInputs()
apollo_probabilities <- function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
## Modell
P <- list()
b10_value = b10 + b10_shift_Alter * Alter
b11_value = b11 + b11_shift_Alter * Alter
b12_value = b12 + b12_shift_Alter * Alter
b20_value = b20 + b20_shift_Alter * Alter
b21_value = b21 + b21_shift_Alter * Alter
b22_value = b22 + b22_shift_Alter * Alter
b23_value = b23 + b23_shift_Alter * Alter
b30_value = b30 + b30_shift_Alter * Alter
b40_value = b40 + b40_shift_Alter * Alter
b41_value = b41 + b41_shift_Alter * Alter
b42_value = b42 + b42_shift_Alter * Alter
b50_value = b50 + b50_shift_Alter * Alter
V <- list()
V[["altA"]] = (b10_value*(Parkraumangebot_1==0) + b11_value*(Parkraumangebot_1==1) + b12_value*(Parkraumangebot_1==2) +
b20_value*(Alternativnutzung_1==0) + b21_value*(Alternativnutzung_1==1) + b22_value*(Alternativnutzung_1==2) + b23_value*(Alternativnutzung_1==3) +
b30_value*Entfernung_1 +
b40_value*(Verkehrsberuhigung_1==0) + b41_value*(Verkehrsberuhigung_1==1) + b42_value*(Verkehrsberuhigung_1==2) +
b50_value*(Stellplatzreduktion_1)
)
V[["altB"]] = (b10_value*(Parkraumangebot_2==0) + b11_value*(Parkraumangebot_2==1) + b12_value*(Parkraumangebot_2==2) +
b20_value*(Alternativnutzung_2==0) + b21_Value*(Alternativnutzung_2==1) + b22_value*(Alternativnutzung_2==2) + b23_value*(Alternativnutzung_2==3) +
b30_value*Entfernung_2 +
b40_value*(Verkehrsberuhigung_2==0) + b41_value*(Verkehrsberuhigung_2==1) + b42_value*(Verkehrsberuhigung_2==2) +
b50_value*(Stellplatzreduktion_2)
)
V[["statusquo"]] = b60
mnl_settings = list(
alternatives = c(altA = 1, altB = 2, statusquo = 3),
avail = 1,
choiceVar = choice,
V = V
)
P[["model"]] <- apollo_mnl(mnl_settings, functionality)
P <- apollo_panelProd(P, apollo_inputs, functionality)
P <- apollo_prepareProb(P, apollo_inputs, functionality)
return (P)
}
#### Modell Schaetzung
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
apollo_modelOutput(model, list(printPVal = TRUE))
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
Error:
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
object 'apollo_inputs' not found
> apollo_modelOutput(model, list(printPVal = TRUE))
Error in apollo_modelOutput(model, list(printPVal = TRUE)) :
object 'model' not found
I need help with the specification of my model. I would like to analyze my data by age groups, gender, income and area character (Gebietstyp). However, I need help to integrate them in the code. So far I have always received errors.
I already tried to integrate the age. Alter = age
Can you please help me to find the problem?
Thank you very much,
Nina
choiceAnalysis_settings <- list(
alternatives = c(altA=1, altB=2, statusquo=3),
avail = list(altA = 1, altB = 1, statusquo = 1),
choiceVar = database$choice,
explanators = database[, c("Gebietstyp")]
)
apollo_choiceAnalysis(choiceAnalysis_settings, apollo_control, database)
## Parameter
apollo_beta <- c(
b10 = 0,
b11 = 0,
b12 = 0,
b10_shift_Alter = 0,
b11_shift_Alter = 0,
b12_shift_Alter = 0,
b20 = 0,
b21 = 0,
b22 = 0,
b23 = 0,
b20_shift_Alter = 0,
b21_shift_Alter = 0,
b22_shift_Alter = 0,
b23_shift_Alter = 0,
b30 = 0,
b30_shift_Alter = 0,
b40 = 0,
b41 = 0,
b42 = 0,
b40_shift_Alter = 0,
b41_shift_Alter = 0,
b42_shift_Alter = 0,
b50 = 0,
b50_shift_Alter = 0,
b60 = 0)
apollo_fixed = c("b12", "b23", "b42")
apollo_inputs <- apollo_validateInputs()
apollo_probabilities <- function(apollo_beta, apollo_inputs, functionality="estimate"){
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
## Modell
P <- list()
b10_value = b10 + b10_shift_Alter * Alter
b11_value = b11 + b11_shift_Alter * Alter
b12_value = b12 + b12_shift_Alter * Alter
b20_value = b20 + b20_shift_Alter * Alter
b21_value = b21 + b21_shift_Alter * Alter
b22_value = b22 + b22_shift_Alter * Alter
b23_value = b23 + b23_shift_Alter * Alter
b30_value = b30 + b30_shift_Alter * Alter
b40_value = b40 + b40_shift_Alter * Alter
b41_value = b41 + b41_shift_Alter * Alter
b42_value = b42 + b42_shift_Alter * Alter
b50_value = b50 + b50_shift_Alter * Alter
V <- list()
V[["altA"]] = (b10_value*(Parkraumangebot_1==0) + b11_value*(Parkraumangebot_1==1) + b12_value*(Parkraumangebot_1==2) +
b20_value*(Alternativnutzung_1==0) + b21_value*(Alternativnutzung_1==1) + b22_value*(Alternativnutzung_1==2) + b23_value*(Alternativnutzung_1==3) +
b30_value*Entfernung_1 +
b40_value*(Verkehrsberuhigung_1==0) + b41_value*(Verkehrsberuhigung_1==1) + b42_value*(Verkehrsberuhigung_1==2) +
b50_value*(Stellplatzreduktion_1)
)
V[["altB"]] = (b10_value*(Parkraumangebot_2==0) + b11_value*(Parkraumangebot_2==1) + b12_value*(Parkraumangebot_2==2) +
b20_value*(Alternativnutzung_2==0) + b21_Value*(Alternativnutzung_2==1) + b22_value*(Alternativnutzung_2==2) + b23_value*(Alternativnutzung_2==3) +
b30_value*Entfernung_2 +
b40_value*(Verkehrsberuhigung_2==0) + b41_value*(Verkehrsberuhigung_2==1) + b42_value*(Verkehrsberuhigung_2==2) +
b50_value*(Stellplatzreduktion_2)
)
V[["statusquo"]] = b60
mnl_settings = list(
alternatives = c(altA = 1, altB = 2, statusquo = 3),
avail = 1,
choiceVar = choice,
V = V
)
P[["model"]] <- apollo_mnl(mnl_settings, functionality)
P <- apollo_panelProd(P, apollo_inputs, functionality)
P <- apollo_prepareProb(P, apollo_inputs, functionality)
return (P)
}
#### Modell Schaetzung
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
apollo_modelOutput(model, list(printPVal = TRUE))
# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #
apollo_saveOutput(model)
Error:
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
object 'apollo_inputs' not found
> apollo_modelOutput(model, list(printPVal = TRUE))
Error in apollo_modelOutput(model, list(printPVal = TRUE)) :
object 'model' not found