diff --git a/Scripts/clogit/split/clogit_caseA_Control_no_protest.R b/Scripts/clogit/split/clogit_caseA_Control_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..72c919bc8415cc3663a6909b89c13d0c234557ea --- /dev/null +++ b/Scripts/clogit/split/clogit_caseA_Control_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseA_Opt_Treatment_no_protest.R b/Scripts/clogit/split/clogit_caseA_Opt_Treatment_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..c5dd1fc34644c9ec5db895686711843020fd1d3c --- /dev/null +++ b/Scripts/clogit/split/clogit_caseA_Opt_Treatment_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseA_Treated_no_protest.R b/Scripts/clogit/split/clogit_caseA_Treated_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..5ee55c1f2d04c1e824d30289062411128aeb6f91 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseA_Treated_no_protest.R @@ -0,0 +1,122 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Control_Not_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Control_Not_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..5755033cb9475e750715650fb2704ea37c818273 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Control_Not_Pred_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Control_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Control_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..d24fcd4c65695df5b90add02e45ae95c489a9730 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Control_Pred_no_protest.R @@ -0,0 +1,126 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Opt_Treat_Not_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Opt_Treat_Not_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..e995d201a219919413e02f3a11f2514659e10b91 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Opt_Treat_Not_Pred_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Opt_Treat_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Opt_Treat_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..e0457182596a90b94ec23ee94e1ec05bfcb0ac07 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Opt_Treat_Pred_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Treated_Not_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Treated_Not_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..a9eba59625ad06d07826fa49f335e263d9bd712d --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Treated_Not_Pred_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) + diff --git a/Scripts/clogit/split/clogit_caseM_Treated_Pred_no_protest.R b/Scripts/clogit/split/clogit_caseM_Treated_Pred_no_protest.R new file mode 100644 index 0000000000000000000000000000000000000000..684e9cb9a600d562fbbb3bd436bb2cb131e1e039 --- /dev/null +++ b/Scripts/clogit/split/clogit_caseM_Treated_Pred_no_protest.R @@ -0,0 +1,124 @@ + +#### 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) +