Skip to content
Snippets Groups Projects
Commit 78a22af9 authored by nc71qaxa's avatar nc71qaxa
Browse files

visualize distributions

parent 004a1e65
Branches
No related tags found
No related merge requests found
......@@ -16,6 +16,38 @@ models <- list(
"Treated Pred" = MXL_wtp_Treated_Pred_model
)
group_color_mapping <- c(
"Control" = "grey",
"Treated" = "red",
"Optional" = "yellow"
)
# Define line type mapping for prediction status
prediction_line_mapping <- c(
"Not Predicted" = "dashed",
"Predicted" = "solid"
)
# Create a mapping for the groups
group_mapping <- c(
"Control Not Pred" = "Control",
"Control Pred" = "Control",
"Treated Not Pred" = "Treated",
"Treated Pred" = "Treated",
"Opt Not Pred" = "Optional",
"Opt Pred" = "Optional"
)
# Create a mapping for prediction status
prediction_mapping <- c(
"Control Not Pred" = "Not Predicted",
"Control Pred" = "Predicted",
"Treated Not Pred" = "Not Predicted",
"Treated Pred" = "Predicted",
"Opt Not Pred" = "Not Predicted",
"Opt Pred" = "Predicted"
)
# Define the x-range for plotting (1000 values)
x_range <- seq(-20, 100, length.out = 1000)
......@@ -36,22 +68,32 @@ for (i in seq_along(models)) {
y <- dnorm(x_range, mean, sd)
# Create a data frame for this model and append it to the main data frame
temp_data <- data.frame(x = x_range, density = y, model = model_name)
temp_data <- data.frame(
x = x_range,
density = y,
model = model_name,
Group = group_mapping[[model_name]],
Prediction = prediction_mapping[[model_name]]
)
plot_data <- bind_rows(plot_data, temp_data)
}
# Plot using ggplot2
ggplot(plot_data, aes(x = x, y = density, color = model)) +
geom_line() +
# Plot using ggplot2 with custom color and linetype mappings
ggplot(plot_data, aes(x = x, y = density, color = Group, linetype = Prediction)) +
geom_line(size = 1) +
scale_color_manual(values = group_color_mapping) + # Set custom colors for groups
scale_linetype_manual(values = prediction_line_mapping) + # Set custom linetypes for prediction status
labs(
title = "Normal Distributions from Multiple MXL Models",
x = "x",
x = "WTP Naturalness (€/month)",
y = "Density",
color = "Model"
color = "Group",
linetype = "Prediction"
) +
theme_minimal() +
theme(legend.position = "right") +
scale_color_brewer(palette = "Set1")
theme(legend.position = "right")
#### Z-test if distributions are different
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment