@@ -128,6 +128,7 @@ library(htmlTable) # for descriptive table
128128# library(colorblindr)
129129library(MetBrewer )
130130library(RColorBrewer )
131+ library(merDeriv )
131132
132133# ```
133134# Warning in install.packages :
@@ -633,11 +634,17 @@ plot_model(model11_z_scored,
633634
634635# Jess' version
635636plot_fig_2 <- function () {
636- coefsmodel11z <- summary(model11_z_scored )$ coef
637- cis <- confint(model11_z_scored )
638- b0 <- coefsmodel11z [1 ]
639- b1 <- coefsmodel11z [2 ]
640- se <- coefsmodel11z [4 ]
637+
638+ # fixme
639+ # coefsmodel11z <- summary(model11_z_scored)$coef
640+ # cis <- confint(model11_z_scored)
641+ # b0 <- coefsmodel11z[1]
642+ # b1 <- coefsmodel11z[2]
643+ # se <- coefsmodel11z[4]
644+ m2_params <- parameters :: model_parameters(model11_z_scored )
645+ b0 <- m2_params $ Coefficient [1 ]
646+ b1 <- m2_params $ Coefficient [2 ]
647+ se <- m2_params $ SE [2 ] # also confirm we use this
641648
642649 # bootstrap ci ribbon
643650 iterations = 1000
@@ -652,13 +659,20 @@ plot_fig_2 <- function() {
652659 a [i ,3 ] <- lme4 :: fixef(mdl )[2 ]
653660 }
654661
662+ ll <- mean(a $ beta ) - (2 * sd(a $ beta ))
663+ ul <- mean(a $ beta ) + (2 * sd(a $ beta ))
664+
665+ print(sum(a $ beta < ul & a $ beta > ll ))
666+ # sum(a$beta<ul & a$beta>ll) #this should be ~950 if iterations=1000
667+
668+ a <- filter(a , beta < ul & beta > ll )
655669
656670 # create df for annotation
657671 label_text <- data.frame (
658- label = c(paste(" \u 03b2 = " , digit_display(b1 ),
659- " \n SE = " , digit_display(se ),
660- " \n CI = [" , digit_display(cis [5 ,1 ]), " - " , digit_display(cis [5 ,2 ]), " ]" ,
661- " \n p " , tinyps(coefsmodel11z [10 ]), sep = " " )),
672+ # label = c(paste("\u03b2 = ", digit_display(b1),
673+ # "\nSE = ", digit_display(se),
674+ # "\nCI = [", digit_display(cis[5,1]), " - ", digit_display(cis[5,2]), "]",
675+ # "\np ", tinyps(coefsmodel11z[10]), sep="")),
662676 scaaredSoc_z = c(- 1.1 ),
663677 # words_with_hes_rate_z = c(4.5)) #location for plot with all datapoints
664678 words_with_hes_rate_z = c(0.75 )) # location for plot with limited y-axis
@@ -674,7 +688,8 @@ plot_fig_2 <- function() {
674688
675689 p <- p + geom_abline(intercept = b0 , slope = b1 , color = rwe_palette [14 ], linewidth = 1 ) +
676690 guides(color = FALSE , shape = FALSE ) +
677- geom_label(data = label_text , aes(x = scaaredSoc_z , y = words_with_hes_rate_z , label = label ), size = 3 ) +
691+ # geom_label(data=label_text,
692+ # aes(x=scaaredSoc_z, y=words_with_hes_rate_z), size=3) +
678693 ylim(- 0.9 , 0.9 ) + # remove this line for plot with all datapoints
679694 theme_bw() +
680695 theme(plot.title = element_text(size = 18 , hjust = 0.05 , face = ' bold' ),
@@ -972,20 +987,24 @@ plot_model(f_model24_z_scored,
972987# Jess' version, wip
973988plot_fig_3 <- function () {
974989 # determine degrees of purple needed for this variable
975- rwe_palette_custom <- brewer.pal(4 , " Purples" )
976- number_of_values <-
977- pull(errorDat , words_with_hes_rate_z ) %> %
978- unique %> %
979- length
980-
981- rwe_palette_custom <- colorRampPalette(rwe_palette_custom )(number_of_values + 3 )
982- rwe_palette_custom <- rwe_palette_custom [4 : (number_of_values + 3 )]
983-
984- coefsmodel11z <- summary(f_model24_z_scored )$ coef
985- cis <- confint(f_model24_z_scored )
986- b0 <- coefsmodel11z [1 ]
987- b1 <- coefsmodel11z [2 ]
988- se <- coefsmodel11z [4 ]
990+ # rwe_palette_custom <- brewer.pal(4, "Purples")
991+ # number_of_values <-
992+ # pull(errorDat, scaaredSoc_z) %>% # RERUN NOW THAT I'VE FIXED THIS
993+ # unique %>%
994+ # length
995+ #
996+ # rwe_palette_custom <- colorRampPalette(rwe_palette_custom)(number_of_values+3)
997+ # rwe_palette_custom <- rwe_palette_custom[4:(number_of_values+3)]
998+ #
999+ # coefsmodel11z <- summary(f_model24_z_scored)$coef
1000+ # cis <- confint(f_model24_z_scored)
1001+ # b0 <- coefsmodel11z[1]
1002+ # b1 <- coefsmodel11z[2]
1003+ # se <- coefsmodel11z[4]
1004+ m2_params <- parameters :: model_parameters(model11_z_scored )
1005+ b0 <- m2_params $ Coefficient [1 ]
1006+ b1 <- m2_params $ Coefficient [2 ]
1007+ se <- m2_params $ SE [2 ] # also confirm we use this
9891008
9901009 # bootstrap ci ribbon
9911010 iterations = 1000
@@ -1000,28 +1019,37 @@ plot_fig_3 <- function() {
10001019 a [i ,3 ] <- lme4 :: fixef(mdl )[2 ]
10011020 }
10021021
1022+ ll <- mean(a $ beta ) - (2 * sd(a $ beta ))
1023+ ul <- mean(a $ beta ) + (2 * sd(a $ beta ))
1024+
1025+ print(sum(a $ beta < ul & a $ beta > ll ))
1026+ # sum(a$beta<ul & a$beta>ll) #this should be ~950 if iterations=1000
1027+
1028+ a <- filter(a , beta < ul & beta > ll )
10031029
10041030 # create df for annotation
10051031 label_text <- data.frame (
1006- label = c(paste(" \u 03b2 = " , digit_display(b1 ),
1007- " \n SE = " , digit_display(se ),
1008- " \n CI = [" , digit_display(cis [5 ,1 ]), " - " , digit_display(cis [5 ,2 ]), " ]" ,
1009- " \n p " , tinyps(coefsmodel11z [10 ]), sep = " " )),
1032+ # label = c(paste("\u03b2 = ", digit_display(b1),
1033+ # "\nSE = ", digit_display(se),
1034+ # "\nCI = [", digit_display(cis[5,1]), " - ", digit_display(cis[5,2]), "]",
1035+ # "\np ", tinyps(coefsmodel11z[10]), sep="")),
10101036 words_with_hes_rate_z = c(- 1.1 ),
1037+ # words_with_hes_rate_z = c(4.5)) #location for plot with all datapoints
10111038 words_with_misprod_rate_z = c(0.75 )) # location for plot with limited y-axis
10121039
1040+
10131041 # plot
10141042 p <- ggplot(errorDat , aes(x = words_with_hes_rate_z , y = words_with_misprod_rate_z )) +
10151043 geom_jitter(aes(color = factor (words_with_hes_rate_z )), alpha = 0.5 , width = 0.05 , show.legend = FALSE ) +
1016- scale_color_manual(values = rwe_palette_custom )
1044+ scale_color_manual(values = rwe_palette )
10171045
10181046 for (i in 1 : nrow(a )){ # add bootstrapped lines to show confidence interval
10191047 p <- p + geom_abline(intercept = as.numeric(a [i ,2 ]), slope = as.numeric(a [i ,3 ]), color = rwe_palette_custom [3 ], alpha = 0.1 )
10201048 }
10211049
1022- p <- p + geom_abline(intercept = b0 , slope = b1 , color = rwe_palette_custom [ number_of_values ], linewidth = 1 ) +
1050+ p <- p + geom_abline(intercept = b0 , slope = b1 , color = rwe_palette [ 14 ], linewidth = 1 ) +
10231051 guides(color = FALSE , shape = FALSE ) +
1024- geom_label(data = label_text , aes(x = words_with_hes_rate_z , y = words_with_misprod_rate_z , label = label ), size = 3 ) +
1052+ geom_label(data = label_text , aes(x = words_with_hes_rate_z , y = words_with_misprod_rate_z ), size = 3 ) +
10251053 ylim(- 0.9 , 0.9 ) + # remove this line for plot with all datapoints
10261054 theme_bw() +
10271055 theme(plot.title = element_text(size = 18 , hjust = 0.05 , face = ' bold' ),
0 commit comments