@@ -357,7 +357,10 @@ for(i in 1:nrow(settings)) {
357357
358358 # For the within-person effect
359359 ggplot(plot_df_beta1 , aes(x = method_type , y = beta1_bias , col = estimation_type )) +
360- geom_boxplot() +
360+ geom_boxplot() + # Suppress default outlier points
361+ # geom_boxplot(position = position_dodge(width = 0.75)) + # align boxplots
362+ # geom_point(position = position_jitterdodge(jitter.width = 0.15, dodge.width = 0.75),
363+ # alpha = 0.01, size = 0.8) +
361364 geom_hline(yintercept = 0 , linetype = " dashed" ) + # Dashed horizontal line at 0 +
362365 coord_cartesian(ylim = c(- 1.5 , 1.5 )) +
363366 scale_y_continuous(breaks = seq(- 1.5 , 1.5 , by = 0.5 )) +
@@ -1128,6 +1131,75 @@ library(patchwork)
11281131combined_plot <- (plot1 + plot2 ) / (plot3 + plot4 ) / (plot5 + plot6 )
11291132combined_plot
11301133
1131-
1132-
11331134
1135+ plot_df_beta1 <- plotting_bias_df %> %
1136+ select(- ends_with(" _g.01_bias" )) %> %
1137+ # turn the bias variables into long format, with a new column indicating the model name
1138+ pivot_longer(cols = ends_with(" _bias" ), names_to = " model" , values_to = " beta1_bias" ) %> %
1139+ # remove the "_g.10_bias" suffix from the model names
1140+ mutate(model = str_remove(model , " _g.10_bias" )) %> %
1141+ # remove models with a 3 in the name
1142+ filter(! str_detect(model , " 3" )) %> %
1143+ # change model names
1144+ mutate(model = recode(model ,
1145+ " l1" = " M1" ,
1146+ " l2" = " M2" ,
1147+ " l4" = " M3" ,
1148+ " g.independence1" = " G1.independence" ,
1149+ " g.exchangeable1" = " G1.exchangeable" ,
1150+ " g.ar11" = " G1.AR1" ,
1151+ " g.independence2" = " G2.independence" ,
1152+ " g.exchangeable2" = " G2.exchangeable" ,
1153+ " g.ar12" = " G2.AR1" ,
1154+ " g.independence4" = " G3.independence" ,
1155+ " g.exchangeable4" = " G3.exchangeable" ,
1156+ " g.ar14" = " G3.AR1" )) %> %
1157+ # set factor levels of model to ensure correct order in the plot
1158+ mutate(model = factor (model , levels = c(" M1" , " G1.independence" , " G1.exchangeable" , " G1.AR1" ,
1159+ " M2" , " G2.independence" , " G2.exchangeable" , " G2.AR1" ,
1160+ " M3" , " G3.independence" , " G3.exchangeable" , " G3.AR1"
1161+ ))) %> %
1162+ # Turn variables into labels
1163+ mutate(sd.u0_label = factor (sd.u0 ,
1164+ levels = c(1 , 3 ),
1165+ labels = c(expression(sigma [u ] == 1 ), expression(sigma [u ] == 3 )))) %> %
1166+ mutate(T_total_label = factor (T_total ,
1167+ levels = c(5 , 20 ),
1168+ labels = c(" T == 5" , " T == 20" ))) %> %
1169+ # create new variable indicating method type (so M1 and G1 are "Method 1")
1170+ mutate(method_type = case_when(
1171+ str_detect(model , " M1" ) ~ " UC" ,
1172+ str_detect(model , " M2" ) ~ " CWC" ,
1173+ str_detect(model , " M3" ) ~ " MuCo" ,
1174+ str_detect(model , " G1" ) ~ " UC" ,
1175+ str_detect(model , " G2" ) ~ " CWC" ,
1176+ str_detect(model , " G3" ) ~ " MuCo"
1177+ )) %> %
1178+ mutate(estimation_type = case_when(
1179+ str_detect(model , " M1" ) ~ " GLMM" ,
1180+ str_detect(model , " M2" ) ~ " GLMM" ,
1181+ str_detect(model , " M3" ) ~ " GLMM" ,
1182+ str_detect(model , " independence" ) ~ " GEE-indep" ,
1183+ str_detect(model , " exchangeable" ) ~ " GEE-exch" ,
1184+ str_detect(model , " AR1" ) ~ " GEE-AR1"
1185+ )) %> %
1186+ # set factor levels of method_type to ensure correct order in the plot
1187+ mutate(method_type = factor (method_type , levels = c(" UC" , " CWC" , " MuCo" )),
1188+ estimation_type = factor (estimation_type , levels = c(" GLMM" , " GEE-indep" , " GEE-exch" , " GEE-AR1" ))) %> %
1189+ # select cases with sigma_u = 3 nd T = 20
1190+ filter(sd.u0 == 3 , T_total == 5 , model == " G1.independence" )
1191+
1192+ # create density of the estimates of beta1
1193+ ggplot(plot_df_beta1 , aes(x = beta1_bias )) +
1194+ geom_density(aes(fill = model ), alpha = 0.5 ) +
1195+ labs(x = " Bias" , y = " Density" ) +
1196+ theme_bw()
1197+
1198+ # create normal histogram
1199+ ggplot(plot_df_beta1 , aes(x = beta1_bias )) +
1200+ geom_histogram(aes(fill = model ), alpha = 0.5 , bins = 30 ) +
1201+ labs(x = " Bias" , y = " Density" ) +
1202+ theme_bw() +
1203+ facet_wrap(~ model , ncol = 3 )
1204+
1205+ summary(plot_df_beta1 $ beta1_bias )
0 commit comments