Skip to content
Snippets Groups Projects
Commit 226f946d authored by Marder's avatar Marder
Browse files

clogit no protest

parent efe4cbb6
Branches
No related tags found
1 merge request!3clogit no protest
Showing with 1116 additions and 0 deletions
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Treatment==3 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_A_Control",
modelDescr = "clogit_wtp_Case_A_Control",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Treatment==2 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_A_Opt_Treatment",
modelDescr = "clogit_wtp_Case_A_Opt_Treatment",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Treatment==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_A_Treated",
modelDescr = "clogit_wtp_Case_A_Treated",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Control_Not_Pred==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Control_Not_Pred",
modelDescr = "clogit_wtp_Case_M_Control_Not_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Control_Not_Pred==0 & Dummy_Treated_Pred==0 &
Dummy_Treated_Not_Pred == 0 & Dummy_Opt_Treat_Pred==0 &
Dummy_Opt_Treat_Not_Pred == 0)
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Control_Pred",
modelDescr = "clogit_wtp_Case_M_Control_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Opt_Treat_Not_Pred==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Opt_Not_Treat_Pred",
modelDescr = "clogit_wtp_Case_M_Opt_Not_Treat_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Opt_Treat_Pred==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Opt_Treat_Pred",
modelDescr = "clogit_wtp_Case_M_Opt_Treat_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Treated_Not_Pred==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Not_Treated_Pred",
modelDescr = "clogit_wtp_Case_M_Not_Treated_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
#### Apollo standard script #####
library(apollo) # Load apollo package
data_predictions1 <- readRDS("Data/predictions.RDS")
data_predictions2 <- readRDS("Data/predictions_labeled.RDS")
data_predictions <- bind_rows(data_predictions1, data_predictions2)
database <- left_join(database_full, data_predictions, by="id")
database <- database %>%
filter(!is.na(Treatment_new)) %>%
mutate(Dummy_Treated = case_when(Treatment_new == 1|Treatment_new == 2 ~ 1, TRUE ~ 0),
Dummy_Vol_Treated = case_when(Treatment_new == 5 |Treatment_new == 4 ~ 1, TRUE ~ 0),
Dummy_no_info = case_when(Treatment_new == 3 ~ 1, TRUE~0)) %>%
mutate(Dummy_Treated_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Treated_Not_Pred = case_when(Dummy_Treated == 1 & PredictedGroup == 0 ~1, TRUE~0)) %>%
mutate(Dummy_Control_Not_Pred = case_when(Treatment_new == 6 & PredictedGroup == 0 ~1, TRUE~0),
Dummy_Opt_Treat_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 1 ~1, TRUE~0),
Dummy_Opt_Treat_Not_Pred = case_when(Treatment_A == "Vol_Treated" & PredictedGroup == 0 ~1, TRUE~0))
table(database$Treatment)
database<- filter(database,Dummy_Treated_Pred==1 )
database<- filter(database,count_choosen_3!=10 )
#initialize model
apollo_initialise()
### Set core controls
apollo_control = list(
modelName = "clogit_wtp_Case_M_Treated_Pred",
modelDescr = "clogit_wtp_Case_M_Treated_Pred",
indivID ="id",
mixing = FALSE,
HB= FALSE,
nCores = n_cores,
outputDirectory = "Estimation_results/clogit/split/no_protest"
)
##### Define model parameters depending on your attributes and model specification! ####
# set values to 0 for conditional logit model
apollo_beta=c(b_natural = 15,
b_walking = -1,
b_rent = 0,
b_ASC_sq = 0
)
### specify parameters that should be kept fixed, here = none
apollo_fixed = c()
### validate
apollo_inputs = apollo_validateInputs()
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()
#### List of utilities (later integrated in mnl_settings below) ####
# Define utility functions here:
V = list()
V[['alt1']] = -b_rent *(b_natural*Naturalness_1 + b_walking*WalkingDistance_1 - Rent_1)
V[['alt2']] = -b_rent *(b_natural*Naturalness_2 + b_walking*WalkingDistance_2 - Rent_2)
V[['alt3']] = -b_rent *(b_ASC_sq +b_natural*Naturalness_3 + b_walking*WalkingDistance_3 - Rent_3)
### Define settings for MNL model component
mnl_settings = list(
alternatives = c(alt1=1, alt2=2, alt3=3),
avail = 1, # all alternatives are available in every choice
choiceVar = choice,
V = V#, # tell function to use list vector defined above
)
### 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)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
# ################################################################# #
#### MODEL ESTIMATION ##
# ################################################################# #
# estimate model with bfgs algorithm
model = apollo_estimate(apollo_beta, apollo_fixed,
apollo_probabilities, apollo_inputs,
estimate_settings=list(maxIterations=400,
estimationRoutine="bfgs",
hessianRoutine="analytic"))
# ################################################################# #
#### MODEL OUTPUTS ##
# ################################################################# #
apollo_saveOutput(model)
apollo_modelOutput(model)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment