Skip to content

Commit 2cb1799

Browse files
committed
make more plots
1 parent 2fcd133 commit 2cb1799

11 files changed

Lines changed: 103 additions & 16 deletions

scripts/hamaker2020_extended/results-plotting.R

Lines changed: 103 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,19 @@ general_scenario_df_beta1 <- final_df %>%
581581
"g.exchangeable2", "g.ar12", "g.independence2",
582582
"g.exchangeable3", "g.ar13", "g.independence3",
583583
"g.exchangeable4", "g.ar14", "g.independence4")),
584+
585+
# Create labels and set factor levels of model to ensure correct order in the plot
584586
predictor.type_str = paste0(predictor.type, " predictor"),
585-
outcome.type_str = paste0(outcome.type, " outcome"),
586-
# Set factor levels of model to ensure correct order in the plot
587587
predictor.type_str = factor(predictor.type_str, levels = c("continuous predictor", "binary predictor")),
588-
outcome.type_str = factor(outcome.type_str, levels = c("continuous outcome", "binary outcome"))
588+
outcome.type_str = paste0(outcome.type, " outcome"),
589+
outcome.type_str = factor(outcome.type_str, levels = c("continuous outcome", "binary outcome")),
590+
T_total_str = paste0("T = ", T_total),
591+
T_total_str = factor(T_total_str, levels = c("T = 5", "T = 10", "T = 20")),
592+
sd.u0_str = paste0("sd.u0 = ", sd.u0),
593+
sd.u0_str = factor(sd.u0_str, levels = c("sd.u0 = 0", "sd.u0 = 1", "sd.u0 = 3"))
589594
) %>%
590595
# remove parametrization 3
591-
filter(!model %in% c("l3a", "g.independence3", "g.ar13", "g.exchangeable3")) %>%
596+
# filter(!model %in% c("l3a", "g.independence3", "g.ar13", "g.exchangeable3")) %>%
592597
# remove any bias values exceeding -100 or 100 (occuring in the GEE models)
593598
filter(beta1_bias > -100 & beta1_bias < 100)
594599

@@ -615,22 +620,80 @@ boxplot_grid_maker_beta1 <- function(df) {
615620
scenario01_df_beta1 <- general_scenario_df_beta1 %>%
616621
filter(N_total == 200, T_total == 20, sdX.between == 0, sd.u0 == 0, g.01 == 0)
617622
boxplot_grid_maker_beta1(scenario01_df_beta1)
623+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario01.pdf"), width = 10, height = 5)
618624

619625
# scenario 02: baseline (with between-person differences in X)
620626
scenario02_df_beta1 <- general_scenario_df_beta1 %>%
621627
filter(N_total == 200, T_total == 20, sdX.between == 1, sd.u0 == 0, g.01 == 0)
622628
boxplot_grid_maker_beta1(scenario02_df_beta1)
629+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario02.pdf"), width = 10, height = 5)
623630

624631
# scenario 1: challenging for parametrization 1, but no random effect, which is good for GEE
625632
scenario1_df_beta1 <- general_scenario_df_beta1 %>%
626633
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 == 0, g.01 == 3)
627634
boxplot_grid_maker_beta1(scenario1_df_beta1) # g.independence1 is out of bounds for cont XY
628-
t# ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario1.pdf"), width = 10, height = 8)
635+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario1.pdf"), width = 10, height = 5)
629636

630637
# scenario 2: challenging for parametrization 1 and GEE (large random effect)
631638
scenario2_df_beta1 <- general_scenario_df_beta1 %>%
632639
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 == 3, g.01 == 3)
633640
boxplot_grid_maker_beta1(scenario2_df_beta1) # g.independence1 is out of bounds for cont XY
641+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario2.pdf"), width = 10, height = 5)
642+
643+
# create 2x2x2 grid of boxplots
644+
boxplot_grid_maker_beta1_3vars <- function(df) {
645+
ggplot(df, aes(x = model, y = beta1_bias, col = model)) +
646+
geom_boxplot() +
647+
geom_hline(yintercept = 0, linetype = "dashed") + # Dashed horizontal line at 0
648+
ylim(-1.5, 1.5) + # Set y-axis limits
649+
labs(x = "Generative Model", y = "Bias") +
650+
facet_grid(predictor.type_str ~ outcome.type_str + T_total_str) +
651+
theme_bw() +
652+
# remove X axis labels
653+
theme(axis.text.x = element_blank(),
654+
axis.ticks.x = element_blank(),
655+
axis.title.x = element_blank())
656+
}
657+
658+
# scenario 3: more comprehensive plot with sd.u0
659+
scenario3_df_beta1 <- general_scenario_df_beta1 %>%
660+
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 %in% c(0, 3), g.01 == 3)
661+
662+
ggplot(scenario3_df_beta1, aes(x = model, y = beta1_bias, col = model)) +
663+
geom_boxplot() +
664+
geom_hline(yintercept = 0, linetype = "dashed") + # Dashed horizontal line at 0
665+
ylim(-1.5, 1.5) + # Set y-axis limits
666+
labs(x = "Generative Model", y = "Bias") +
667+
facet_grid(predictor.type_str ~ outcome.type_str + sd.u0_str) +
668+
theme_bw() +
669+
# remove X axis labels
670+
theme(axis.text.x = element_blank(),
671+
axis.ticks.x = element_blank(),
672+
axis.title.x = element_blank(),
673+
# put legend under
674+
legend.position = "bottom")
675+
676+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario3.pdf"), width = 10, height = 10)
677+
678+
# scenario 4: more comprehensive plot with T_total
679+
scenario4_df_beta1 <- general_scenario_df_beta1 %>%
680+
filter(N_total == 200, T_total %in% c(5, 20), sdX.between == 3, sd.u0 == 0, g.01 == 3)
681+
682+
ggplot(scenario4_df_beta1, aes(x = model, y = beta1_bias, col = model)) +
683+
geom_boxplot() +
684+
geom_hline(yintercept = 0, linetype = "dashed") + # Dashed horizontal line at 0
685+
ylim(-1.5, 1.5) + # Set y-axis limits
686+
labs(x = "Generative Model", y = "Bias") +
687+
facet_grid(T_total_str + predictor.type_str ~ outcome.type_str) +
688+
theme_bw() +
689+
# remove X axis labels
690+
theme(axis.text.x = element_blank(),
691+
axis.ticks.x = element_blank(),
692+
axis.title.x = element_blank(),
693+
# put legend under
694+
legend.position = "bottom")
695+
696+
# ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_within_scenario4.pdf"), width = 10, height = 8)
634697

635698
### CONTEXTUAL EFFECTS PLOTS ### ----
636699

@@ -652,14 +715,18 @@ general_scenario_df_g01 <- final_df %>%
652715
"g.exchangeable2", "g.ar12", "g.independence2",
653716
"g.exchangeable3", "g.ar13", "g.independence3",
654717
"g.exchangeable4", "g.ar14", "g.independence4")),
718+
# Create labels and set factor levels of model to ensure correct order in the plot
655719
predictor.type_str = paste0(predictor.type, " predictor"),
656-
outcome.type_str = paste0(outcome.type, " outcome"),
657-
# Set factor levels of model to ensure correct order in the plot
658720
predictor.type_str = factor(predictor.type_str, levels = c("continuous predictor", "binary predictor")),
659-
outcome.type_str = factor(outcome.type_str, levels = c("continuous outcome", "binary outcome"))
721+
outcome.type_str = paste0(outcome.type, " outcome"),
722+
outcome.type_str = factor(outcome.type_str, levels = c("continuous outcome", "binary outcome")),
723+
T_total_str = paste0("T = ", T_total),
724+
T_total_str = factor(T_total_str, levels = c("T = 5", "T = 10", "T = 20")),
725+
sd.u0_str = paste0("sd.u0 = ", sd.u0),
726+
sd.u0_str = factor(sd.u0_str, levels = c("sd.u0 = 0", "sd.u0 = 1", "sd.u0 = 3"))
660727
) %>%
661728
# remove parametrization 3
662-
filter(!model %in% c("l3a", "g.independence3", "g.ar13", "g.exchangeable3")) %>%
729+
# filter(!model %in% c("l3a", "g.independence3", "g.ar13", "g.exchangeable3")) %>%
663730
# remove any bias values exceeding -100 or 100 (occuring in the GEE models)
664731
filter(g01_bias > -100 & g01_bias < 100)
665732

@@ -682,27 +749,47 @@ boxplot_grid_maker_g01 <- function(df) {
682749
scenario01_df_g01 <- general_scenario_df_g01 %>%
683750
filter(N_total == 200, T_total == 20, sdX.between == 0, sd.u0 == 0, g.01 == 0)
684751
boxplot_grid_maker_g01(scenario01_df_g01)
752+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_contextual_scenario01.pdf"), width = 10, height = 5)
685753

686754
# scenario 02: baseline (with between-person differences in X)
687755
scenario02_df_g01 <- general_scenario_df_g01 %>%
688756
filter(N_total == 200, T_total == 20, sdX.between == 1, sd.u0 == 0, g.01 == 0)
689757
boxplot_grid_maker_g01(scenario02_df_g01)
758+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_contextual_scenario02.pdf"), width = 10, height = 5)
690759

691760
# scenario 1: challenging for parametrization 1, but no random effect, which is good for GEE
692761
scenario1_df_g01 <- general_scenario_df_g01 %>%
693762
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 == 0, g.01 == 3)
694763
boxplot_grid_maker_g01(scenario1_df_g01) # g.independence1 is out of bounds for cont XY
764+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_contextual_scenario1.pdf"), width = 10, height = 5)
695765

696766
# scenario 2: challenging for parametrization 1 and GEE (large random effect)
697767
scenario2_df_g01 <- general_scenario_df_g01 %>%
698768
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 == 3, g.01 == 3)
699769
boxplot_grid_maker_g01(scenario2_df_g01) # g.independence1 is out of bounds for cont XY
700-
701-
702-
# scenario 2b (with large T)
703-
scenario2b_df_g01 <- general_scenario_df_g01 %>%
704-
filter(N_total == 200, T_total == 20, sdX.between == 3, sd.u0 == 0, g.01 == 3)
705-
boxplot_grid_maker_g01(scenario2b_df_g01) # g.independence1 is out of bounds for cont XY
706-
770+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_contextual_scenario2.pdf"), width = 10, height = 5)
771+
772+
# # scenario 2b (with large T)
773+
# scenario2b_df_g01 <- general_scenario_df_g01 %>%
774+
# filter(N_total == 200, T_total == 20, sdX.between == 3, sd.u0 == 0, g.01 == 3)
775+
# boxplot_grid_maker_g01(scenario2b_df_g01) # g.independence1 is out of bounds for cont XY
776+
777+
# scenario 3: more comprehensive plot with sd.u0
778+
scenario3_df_g01 <- general_scenario_df_g01 %>%
779+
filter(N_total == 200, T_total == 5, sdX.between == 3, sd.u0 %in% c(0, 3), g.01 == 3)
780+
ggplot(scenario3_df_g01, aes(x = model, y = g01_bias, col = model)) +
781+
geom_boxplot() +
782+
geom_hline(yintercept = 0, linetype = "dashed") + # Dashed horizontal line at 0
783+
ylim(-1.5, 1.5) + # Set y-axis limits
784+
labs(x = "Generative Model", y = "Bias") +
785+
facet_grid(predictor.type_str ~ outcome.type_str + sd.u0_str) +
786+
theme_bw() +
787+
# remove X axis labels
788+
theme(axis.text.x = element_blank(),
789+
axis.ticks.x = element_blank(),
790+
axis.title.x = element_blank(),
791+
# put legend under
792+
legend.position = "bottom")
793+
ggsave(paste0("simulation_results_glmm/", runname, "/figures/bias_plot_contextual_scenario3.pdf"), width = 10, height = 10)
707794

708795

Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)