@@ -299,13 +299,15 @@ for(i in 1:nrow(settings)) {
299299 str_detect(model , " M1" ) ~ " GLMM" ,
300300 str_detect(model , " M2" ) ~ " GLMM" ,
301301 str_detect(model , " M3" ) ~ " GLMM" ,
302- str_detect(model , " independence" ) ~ " GEE-independence " ,
303- str_detect(model , " exchangeable" ) ~ " GEE-exchangeable " ,
302+ str_detect(model , " independence" ) ~ " GEE-indep " ,
303+ str_detect(model , " exchangeable" ) ~ " GEE-exch " ,
304304 str_detect(model , " AR1" ) ~ " GEE-AR1"
305305 )) %> %
306306 # set factor levels of method_type to ensure correct order in the plot
307307 mutate(method_type = factor (method_type , levels = c(" UC" , " CWC" , " MuCo" )),
308- estimation_type = factor (estimation_type , levels = c(" GLMM" , " GEE-independence" , " GEE-exchangeable" , " GEE-AR1" )))
308+ estimation_type = factor (estimation_type , levels = c(" GLMM" , " GEE-indep" , " GEE-exch" , " GEE-AR1" ))) %> %
309+ # remove all bias values exceeding 100
310+ mutate(beta1_bias = ifelse(abs(beta1_bias ) > 100 , NA , beta1_bias ))
309311
310312
311313 plot_df_g01 <- plot_df %> %
@@ -334,25 +336,32 @@ for(i in 1:nrow(settings)) {
334336 str_detect(model , " M1" ) ~ " GLMM" ,
335337 str_detect(model , " M2" ) ~ " GLMM" ,
336338 str_detect(model , " M3" ) ~ " GLMM" ,
337- str_detect(model , " independence" ) ~ " GEE-independence " ,
338- str_detect(model , " exchangeable" ) ~ " GEE-exchangeable " ,
339+ str_detect(model , " independence" ) ~ " GEE-indep " ,
340+ str_detect(model , " exchangeable" ) ~ " GEE-exch " ,
339341 str_detect(model , " AR1" ) ~ " GEE-AR1"
340342 )) %> %
341343 # set factor levels of method_type to ensure correct order in the plot
342- mutate(estimation_type = factor (estimation_type , levels = c(" GLMM" , " GEE-independence " , " GEE-exchangeable " , " GEE-AR1" ))) %> %
344+ mutate(estimation_type = factor (estimation_type , levels = c(" GLMM" , " GEE-indep " , " GEE-exch " , " GEE-AR1" ))) %> %
343345 # Turn label variables (sdX.between, g.01 and sd.u0) into strings with an underscore
344346 mutate(sd.u0_label = factor (sd.u0 ,
345347 levels = c(1 , 3 ),
346348 labels = c(expression(sigma [u ] == 1 ), expression(sigma [u ] == 3 )))) %> %
347349 mutate(T_total_label = factor (T_total ,
348350 levels = c(5 , 20 ),
349- labels = c(" T == 5" , " T == 20" )))
351+ labels = c(" T == 5" , " T == 20" ))) %> %
352+ # remove all bias values exceeding 100
353+ mutate(g01_bias = ifelse(abs(g01_bias ) > 100 , NA , g01_bias ))
354+
355+ # The palette with grey:
356+ # cbPalette <- c("#E69F00", "#56B4E9", "#009E73", "#CC79A7")
350357
351358 # For the within-person effect
352359 ggplot(plot_df_beta1 , aes(x = method_type , y = beta1_bias , col = estimation_type )) +
353360 geom_boxplot() +
354- geom_hline(yintercept = 0 , linetype = " dashed" ) + # Dashed horizontal line at 0
355- ylim(- 1.5 , 1.5 ) + # Set y-axis limits
361+ geom_hline(yintercept = 0 , linetype = " dashed" ) + # Dashed horizontal line at 0 +
362+ coord_cartesian(ylim = c(- 1.5 , 1.5 )) +
363+ scale_y_continuous(breaks = seq(- 1.5 , 1.5 , by = 0.5 )) +
364+ # ylim(-3, 3) + # Set y-axis limits
356365 labs(x = " Disaggregation Method" , y = " Bias" ) +
357366 facet_grid(sd.u0_label ~ T_total_label , labeller = label_parsed ) + # Show T and N values in labels
358367 theme_bw() +
@@ -376,19 +385,21 @@ for(i in 1:nrow(settings)) {
376385 legend.title = element_text(size = 13 )
377386 ) +
378387 # change legend title to "Estimation"
379- scale_color_discrete (name = " Estimation" )
388+ scale_color_brewer (name = " Estimation" , palette = " Spectral " )
380389
381390 # save for test for main direct
382391 # ggsave("bias_plot_T_total-vs-sd.u0_within.pdf", width = 14, height = 8)
383392
384393 # save
385- ggsave(paste0(" simulation_results_glmm/" , runname , " /figures/" , type , " bias_plot_T_total-vs-sd.u0_within.pdf" ), width = 10 , height = 8 )
394+ ggsave(paste0(" simulation_results_glmm/" , runname , " /figures/" , type , " bias_plot_T_total-vs-sd.u0_within.pdf" ), width = 12 , height = 6.5 )
386395
387396 # For the contextual effect
388397 ggplot(plot_df_g01 , aes(x = estimation_type , y = g01_bias , col = estimation_type )) +
389398 geom_boxplot() +
390399 geom_hline(yintercept = 0 , linetype = " dashed" ) + # Dashed horizontal line at 0
391- ylim(- 1.5 , 1.5 ) + # Set y-axis limits
400+ coord_cartesian(ylim = c(- 1.5 , 1.5 )) + # Set y-axis limits
401+ # add tick mark at Y for every 0.5
402+ scale_y_continuous(breaks = seq(- 1.5 , 1.5 , by = 0.5 )) +
392403 labs(x = " Generative Model" , y = " Bias" ) +
393404 facet_grid(sd.u0_label ~ T_total_label , labeller = label_parsed ) + # Show T and N values in labels
394405 theme_bw() +
@@ -409,13 +420,14 @@ for(i in 1:nrow(settings)) {
409420 legend.title = element_text(size = 13 )
410421 ) +
411422 # change legend title to "Estimation"
412- scale_color_discrete(name = " Estimation" )
423+ scale_color_brewer(name = " Estimation" , palette = " Spectral" )
424+ # scale_color_manual(name = "Estimation", values = cbPalette)
413425
414426 # save for test for main direct
415427 # ggsave("bias_plot_T_total-vs-sd.u0_contextual.pdf", width = 14, height = 8)
416428
417429 # save
418- ggsave(paste0(" simulation_results_glmm/" , runname , " /figures/" , type , " bias_plot_T_total-vs-sd.u0_contextual.pdf" ), width = 10 , height = 8 )
430+ ggsave(paste0(" simulation_results_glmm/" , runname , " /figures/" , type , " bias_plot_T_total-vs-sd.u0_contextual.pdf" ), width = 12 , height = 6 )
419431
420432 # combine plots native with gridextra
421433 # p_combined <- ggarrange(p_within, p_contextual, ncol = 1, nrow = 2, common.legend = TRUE, legend = "right")
0 commit comments