The following object is masked from 'package:dplyr':
group_rows
Code
# Create a data frame with model names, AIC, BIC, and log-likelihood (LLout)model_names <-c("Quadratic Utility Function","Log Utility Function","Linear Utility Function","Box Cox Utility Function","Log-Linear Utility Function")# Extract AIC, BIC, and LLout values from the modelsaic_values <-c(mxl_access$AIC, mxl_access_log$AIC, mxl_access_linear$AIC, mxl_box_cox$AIC, mxl_access_log_linear$AIC)bic_values <-c(mxl_access$BIC, mxl_access_log$BIC, mxl_access_linear$BIC, mxl_box_cox$BIC, mxl_access_log_linear$BIC)ll_values <-c(mxl_access$LLout, mxl_access_log$LLout, mxl_access_linear$LLout, mxl_box_cox$LLout, mxl_access_log_linear$LLout)# Combine into a data framemodel_table <-data.frame(Model = model_names, AIC = aic_values, BIC = bic_values, LLout = ll_values)# Round the values to 2 decimal placesmodel_table$AIC <-round(model_table$AIC, 2)model_table$BIC <-round(model_table$BIC, 2)model_table$LLout <-round(model_table$LLout, 2)# Find the min and max for AIC, BIC, and LLoutmin_aic <-min(model_table$AIC)max_aic <-max(model_table$AIC)min_bic <-min(model_table$BIC)max_bic <-max(model_table$BIC)min_ll <-min(model_table$LLout)max_ll <-max(model_table$LLout)# Use cell_spec to color only the cells with min/max valuesmodel_table$AIC <-cell_spec(model_table$AIC, "html", color =ifelse(model_table$AIC == min_aic, "green", ifelse(model_table$AIC == max_aic, "red", "black")))model_table$BIC <-cell_spec(model_table$BIC, "html", color =ifelse(model_table$BIC == min_bic, "green", ifelse(model_table$BIC == max_bic, "red", "black")))model_table$LLout <-cell_spec(model_table$LLout, "html", color =ifelse(model_table$LLout == min_ll, "red", ifelse(model_table$LLout == max_ll, "green", "black")))# Create the table with kable and format the cellsmodel_table %>%kable("html", escape = F) %>%kable_styling(full_width = F)
So far: WTP for all cells up to 15km is aggregated
WTP within cell only depends on endowment not on distance
Distance could enter in step 1 and/or 4/5 of aggregation?
Ideally enters in step 4/5, marginal cell WTP only dependent on endowment but cells that benefit from change within one cell should be selected based on distance
Close cells have a higher WTP than cells further away with WTP = 0 after some distance
Integrate Income
How to Intergrate Income?
Income can have effect on marginal utility of income, on utility derived from NC attributes or on both
Effect of income on NC attributes
Code
linear_inc <-apollo_loadModel("Results/MXL/Income_interactions/MXL wtp linear radius income")
Successfully loaded
/home/sc.uni-leipzig.de/nc71qaxa/valugaps/Results/MXL/Income_interactions/MXL
wtp linear radius income_model.rds
Code
plot_wtp_income <-function(model, param) {library(ggplot2)# get coefficients b <-if (!is.null(model$estimate)) model$estimate else model# mapping for your current model names name_map <-list(pa =list(base ="beta_pa", inc ="pa_inc", label ="PA"),hnv =list(base ="beta_hnv", inc ="hnv_inc", label ="HNV"),pa_half =list(base ="pa_half_access", inc ="pa_half_inc", label ="PA half access"),pa_full =list(base ="pa_full_access", inc ="pa_full_inc", label ="PA full access"),hnv_visible =list(base ="hnv_visible", inc ="hnv_vis_inc", label ="HNV visible") )if (!param %in%names(name_map)) {stop(paste0("param must be one of: ",paste(names(name_map), collapse =", ") )) } base_name <- name_map[[param]]$base inc_name <- name_map[[param]]$inc lab <- name_map[[param]]$labelif (!base_name %in%names(b)) stop(paste("Missing coefficient:", base_name))if (!inc_name %in%names(b)) stop(paste("Missing coefficient:", inc_name)) income_seq <-seq(-3000, 3000, by =50) df <-data.frame(income = income_seq,wtp =unname(b[base_name]) +unname(b[inc_name]) * income_seq )ggplot(df, aes(x = income, y = wtp)) +geom_line(linewidth =1.2) +geom_hline(yintercept =0, linetype ="dashed", color ="grey50") +geom_vline(xintercept =0, linetype ="dotted", color ="grey50") +labs(title =paste("WTP over monthly income:", lab),x ="Monthly income (mean-centered)",y ="Willingness to pay" ) +theme_minimal(base_size =13) +theme(plot.title =element_text(face ="bold"),panel.grid.minor =element_blank() )}plot_wtp_income(linear_inc, "pa")