1. Loading, setting up

A. Loading packages

B. Loading data

esm <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-esm.csv")
pre_survey_data_processed <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-pre-survey.csv")
post_survey_data_partially_processed <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-post-survey.csv")
video <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-video.csv")

pqa <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-pqa.csv")
attendance <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-attendance.csv")

class_data <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-class-video.csv")
demographics <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-demographics.csv")
# demographics$participant_ID <- ifelse(demographics$participant_ID == 7187, NA, demographics$participant_ID)
# write_csv(demographics, "/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-demographics.csv")
parent <- read_csv("/Users/joshuarosenberg/Google Drive/SCHMIDTLAB/PSE/data/STEM-IE/STEM-IE-parent.csv")
pm <- read_csv("~/Google Drive/1_Research/STEM IE - JJP/STEM-IE/data/final/program_match.csv")

Joining

df <- left_join(esm, pre_survey_data_processed, by = "participant_ID") # esm & pre-survey
df <- left_join(df, post_survey_data_partially_processed, by = "participant_ID") # df & post-survey
df <- left_join(df, video, by = c("program_ID", "response_date", "sociedad_class", "signal_number")) # df & video
df <- left_join(df, demographics, by = c("participant_ID", "program_ID")) # df and demographics

Processing CLASS video data

class_data$sociedad_class <- ifelse(class_data$eighth_math == 1, "8th Math",
                                    ifelse(class_data$seventh_math == 1, "7th Math",
                                           ifelse(class_data$sixth_math == 1, "6th Math",
                                                  ifelse(class_data$robotics == 1, "Robotics",
                                                         ifelse(class_data$dance == 1, "Dance", NA)))))

class_data <- rename(class_data, 
                     response_date = Responsedate,
                     signal_number = r_signal_number,
                     program_ID = SiteIDNumeric)

library(jmRtools)

class_data$CLASS_composite <- jmRtools::composite_mean_maker(class_data, ID, P, AI, ILF, QF, CU)

class_data <- select(class_data,
                     program_ID,
                     response_date,
                     signal_number,
                     sociedad_class,
                     CLASS_EmotionalSupportEncouragement = EmotionalSupportEncouragement,
                     CLASS_InstructionalSupport = InstructionalSupport,
                     CLASS_Autonomy = Autonomy,
                     CLASS_STEMConceptualDevelopment = STEMConceptualDevelopment,
                     CLASS_ActivityLeaderEnthusiasm = ActivityLeaderEnthusiasm)

class_data$response_date <- as.character(class_data$response_date)

df <- mutate(df, response_date = as.character(response_date))

df <- left_join(df, class_data, by = c("program_ID", "response_date", "signal_number", "sociedad_class"))

Further processing

df$participant_ID <- as.factor(df$participant_ID)
df$program_ID <- as.factor(df$program_ID)
df$beep_ID <- as.factor(df$beep_ID)
df$beep_ID_new <- as.factor(df$beep_ID_new)

# Recode problem solving, off task, student presentation, and showing video as other

df$youth_activity_rc <- ifelse(df$youth_activity == "Off Task", "Not Focused", df$youth_activity)

df$youth_activity_rc <- ifelse(df$youth_activity_rc == "Student Presentation" | df$youth_activity_rc == "Problem Solving", "Creating Product", df$youth_activity_rc)

df$youth_activity_rc <- ifelse(df$youth_activity_rc == "Showing Video", "Program Staff Led", df$youth_activity_rc)

df$youth_activity_rc <- as.factor(df$youth_activity_rc)

df$youth_activity_rc <- forcats::fct_relevel(df$youth_activity_rc, "Not Focused")

df$relevance <- jmRtools::composite_mean_maker(df, use_outside, future_goals, important)

# need to move up
video$youth_activity_rc <- ifelse(video$youth_activity == "Off Task", "Not Focused", video$youth_activity)

video$youth_activity_rc <- ifelse(video$youth_activity_rc == "Student Presentation" | video$youth_activity_rc == "Problem Solving", "Creating Product", video$youth_activity_rc)
video$youth_activity_rc <- ifelse(video$youth_activity_rc == "Showing Video", "Program Staff Led", video$youth_activity_rc)

2. Null models (ready)

Note that our normal display presently doesn’t work if there are no predictor variables: it should be fixed in a bit, but for now, we’re just using the standard display.

m0i <- lmer(challenge ~ 1 + 
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

summary(m0i)
## Linear mixed model fit by REML ['lmerMod']
## Formula: challenge ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 |  
##     beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 7917.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8994 -0.6294 -0.0368  0.5688  3.3809 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.08312  0.2883  
##  participant_ID (Intercept) 0.46839  0.6844  
##  program_ID     (Intercept) 0.04290  0.2071  
##  Residual                   0.66705  0.8167  
## Number of obs: 2970, groups:  
## beep_ID_new, 248; participant_ID, 203; program_ID, 9
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.27652    0.08871   25.66
sjstats::icc(m0i)
## Linear mixed model
##  Family: gaussian (identity)
## Formula: challenge ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
## 
##      ICC (beep_ID_new): 0.065888
##   ICC (participant_ID): 0.371307
##       ICC (program_ID): 0.034008
m0ii <- lmer(relevance ~ 1 + 
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

summary(m0ii)
## Linear mixed model fit by REML ['lmerMod']
## Formula: relevance ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 |  
##     beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 6537.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8676 -0.5160  0.0370  0.5953  3.6855 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.017619 0.13274 
##  participant_ID (Intercept) 0.477865 0.69128 
##  program_ID     (Intercept) 0.008374 0.09151 
##  Residual                   0.424016 0.65117 
## Number of obs: 2970, groups:  
## beep_ID_new, 248; participant_ID, 203; program_ID, 9
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  2.57639    0.06003   42.92
sjstats::icc(m0ii)
## Linear mixed model
##  Family: gaussian (identity)
## Formula: relevance ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
## 
##      ICC (beep_ID_new): 0.018988
##   ICC (participant_ID): 0.515011
##       ICC (program_ID): 0.009025
m0iii <- lmer(learning ~ 1 + 
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

summary(m0iii)
## Linear mixed model fit by REML ['lmerMod']
## Formula: learning ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 |  
##     beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 7917.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1195 -0.5609  0.1253  0.5859  2.6793 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.02556  0.1599  
##  participant_ID (Intercept) 0.39406  0.6277  
##  program_ID     (Intercept) 0.00000  0.0000  
##  Residual                   0.70816  0.8415  
## Number of obs: 2969, groups:  
## beep_ID_new, 248; participant_ID, 203; program_ID, 9
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)   2.7680     0.0486   56.95
sjstats::icc(m0iii)
## Linear mixed model
##  Family: gaussian (identity)
## Formula: learning ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
## 
##      ICC (beep_ID_new): 0.022665
##   ICC (participant_ID): 0.349411
##       ICC (program_ID): 0.000000
df$positive_affect <- jmRtools::composite_mean_maker(df,
                                                     happy, excited)

m0iv <- lmer(positive_affect ~ 1 + 
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

summary(m0iv)
## Linear mixed model fit by REML ['lmerMod']
## Formula: positive_affect ~ 1 + (1 | program_ID) + (1 | participant_ID) +  
##     (1 | beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 7258.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7217 -0.4324  0.0572  0.5455  3.4749 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.02362  0.1537  
##  participant_ID (Intercept) 0.49933  0.7066  
##  program_ID     (Intercept) 0.10697  0.3271  
##  Residual                   0.54503  0.7383  
## Number of obs: 2970, groups:  
## beep_ID_new, 248; participant_ID, 203; program_ID, 9
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)    2.699      0.122   22.12
sjstats::icc(m0iv)
## Linear mixed model
##  Family: gaussian (identity)
## Formula: positive_affect ~ 1 + (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
## 
##      ICC (beep_ID_new): 0.020104
##   ICC (participant_ID): 0.424976
##       ICC (program_ID): 0.091043

3. Models for youth activity (ready)

video %>% 
    left_join(pm) %>% 
    count(program_name, youth_activity_rc) %>% 
    filter(!is.na(youth_activity_rc)) %>% 
    spread(youth_activity_rc, n, fill = 0) %>% 
    gather(youth_activity_rc, frequency, -program_name) %>% 
    group_by(program_name) %>% 
    mutate(frequency_prop = frequency / sum(frequency)) %>% 
    ggplot(aes(x = reorder(youth_activity_rc, frequency_prop), y = frequency_prop)) +
    facet_wrap( ~ program_name) +
    geom_col() +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
    ylab("Frequency Proportion") +
    xlab(NULL) +
    ggtitle("Frequency of Youth Activity (Recoded) Codes by Program")

df$youth_activity_rc_fac <- as.factor(df$youth_activity_rc)
dc <- as.tibble(psych::dummy.code(df$youth_activity_rc_fac))
df_ss <- bind_cols(df, dc)

df_ss %>% 
    select(challenge, relevance, learning, positive_affect, 
           `Not Focused`, `Basic Skills Activity`, `Creating Product`, 
           `Field Trip Speaker`, `Lab Activity`, `Program Staff Led`) %>% 
    correlate() %>% 
    shave() %>% 
    fashion()
##                  rowname challenge relevance learning positive_affect
## 1              challenge                                             
## 2              relevance       .39                                   
## 3               learning       .30       .65                         
## 4        positive_affect       .27       .52      .48                
## 5            Not Focused      -.02      -.06     -.05             .04
## 6  Basic Skills Activity      -.01      -.01      .04            -.06
## 7       Creating Product       .12       .08      .04             .05
## 8     Field Trip Speaker      -.04       .01     -.02             .02
## 9           Lab Activity       .00      -.03      .01             .02
## 10     Program Staff Led      -.06       .01     -.00            -.07
##    Not.Focused Basic.Skills.Activity Creating.Product Field.Trip.Speaker
## 1                                                                       
## 2                                                                       
## 3                                                                       
## 4                                                                       
## 5                                                                       
## 6         -.35                                                          
## 7         -.33                  -.25                                    
## 8         -.15                  -.11             -.11                   
## 9         -.14                  -.11             -.10               -.05
## 10        -.27                  -.21             -.20               -.09
##    Lab.Activity Program.Staff.Led
## 1                                
## 2                                
## 3                                
## 4                                
## 5                                
## 6                                
## 7                                
## 8                                
## 9                                
## 10         -.09
demographics %>% count(race)
## # A tibble: 6 x 2
##          race     n
##         <chr> <int>
## 1       Asian    14
## 2       Black    72
## 3    Hispanic    97
## 4 Multiracial     5
## 5       White    13
## 6        <NA>     3
df$urm <- ifelse(df$race %in% c("White", "Asian"), 0, 1)
df$race <- as.factor(df$race)
df$race <- fct_lump(df$race, n = 2)
df$race_other <- fct_relevel(df$race, "Other")
df$gender_female <- as.factor(df$gender) # female is comparison_group
df$gender_female <- ifelse(df$gender_female == "F", 1, 
                           ifelse(df$gender_female == "M", 0, NA))
m1i <- lmer(challenge ~ 1 + 
                youth_activity_rc +
                gender_female + 
                urm +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

sjPlot::sjt.lmer(m1i, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    challenge
    B std. Error p
Fixed Parts
(Intercept)   2.20 0.16 <.001
youth_activity_rc (Basic Skills Activity)   0.10 0.06 .136
youth_activity_rc (Creating Product)   0.36 0.06 <.001
youth_activity_rc (Field Trip Speaker)   -0.09 0.13 .500
youth_activity_rc (Lab Activity)   0.21 0.13 .094
youth_activity_rc (Program Staff Led)   -0.11 0.07 .147
gender_female   -0.26 0.11 .013
urm   0.16 0.15 .310
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.045
ICCparticipant_ID   0.382
ICCprogram_ID   0.031
Observations   2791
R2 / Ω02   .527 / .521
m1ii <- lmer(relevance ~ 1 + 
                 youth_activity_rc +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

sjPlot::sjt.lmer(m1ii, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    relevance
    B std. Error p
Fixed Parts
(Intercept)   2.63 0.15 <.001
youth_activity_rc (Basic Skills Activity)   0.15 0.04 <.001
youth_activity_rc (Creating Product)   0.21 0.04 <.001
youth_activity_rc (Field Trip Speaker)   0.29 0.07 <.001
youth_activity_rc (Lab Activity)   0.14 0.07 .060
youth_activity_rc (Program Staff Led)   0.15 0.05 <.001
gender_female   -0.22 0.10 .036
urm   -0.06 0.15 .699
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.007
ICCparticipant_ID   0.520
ICCprogram_ID   0.016
Observations   2791
R2 / Ω02   .587 / .584
m1iii <- lmer(learning ~ 1 + 
                  youth_activity_rc +
                  gender_female + 
                  urm +
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

sjPlot::sjt.lmer(m1iii, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    learning
    B std. Error p
Fixed Parts
(Intercept)   2.66 0.14 <.001
youth_activity_rc (Basic Skills Activity)   0.22 0.05 <.001
youth_activity_rc (Creating Product)   0.13 0.05 .016
youth_activity_rc (Field Trip Speaker)   0.10 0.10 .313
youth_activity_rc (Lab Activity)   0.16 0.10 .088
youth_activity_rc (Program Staff Led)   0.07 0.06 .213
gender_female   -0.05 0.10 .582
urm   0.06 0.14 .668
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.010
ICCparticipant_ID   0.360
ICCprogram_ID   0.003
Observations   2790
R2 / Ω02   .427 / .420
df$positive_affect <- jmRtools::composite_mean_maker(df,
                                                     happy, excited)

m1iv <- lmer(positive_affect ~ 1 + 
                 youth_activity_rc +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             na.action="na.omit",
             data = df)

summary(m1iv)
## Linear mixed model fit by REML ['lmerMod']
## Formula: positive_affect ~ 1 + youth_activity_rc + gender_female + urm +  
##     (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 6885.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4684 -0.4547  0.0540  0.5503  3.4496 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.02719  0.1649  
##  participant_ID (Intercept) 0.49484  0.7034  
##  program_ID     (Intercept) 0.09956  0.3155  
##  Residual                   0.55039  0.7419  
## Number of obs: 2791, groups:  
## beep_ID_new, 235; participant_ID, 201; program_ID, 9
## 
## Fixed effects:
##                                         Estimate Std. Error t value
## (Intercept)                             2.772173   0.185362  14.955
## youth_activity_rcBasic Skills Activity  0.030727   0.052411   0.586
## youth_activity_rcCreating Product       0.010813   0.053189   0.203
## youth_activity_rcField Trip Speaker     0.008905   0.103356   0.086
## youth_activity_rcLab Activity           0.076327   0.100887   0.757
## youth_activity_rcProgram Staff Led     -0.052792   0.060497  -0.873
## gender_female                          -0.186570   0.108352  -1.722
## urm                                     0.024590   0.157946   0.156
## 
## Correlation of Fixed Effects:
##             (Intr) y__BSA yt__CP y__FTS yt__LA y__PSL gndr_f
## yth_ctv_BSA -0.117                                          
## yth_ctvt_CP -0.110  0.384                                   
## yth_ctv_FTS -0.060  0.235  0.213                            
## yth_ctvt_LA -0.056  0.197  0.190  0.132                     
## yth_ctv_PSL -0.095  0.410  0.307  0.183  0.179              
## gender_feml -0.233  0.001  0.010  0.003 -0.002 -0.008       
## urm         -0.695  0.002 -0.003 -0.004 -0.001 -0.002 -0.083
sjPlot::sjt.lmer(m1iv, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    positive_affect
    B std. Error p
Fixed Parts
(Intercept)   2.77 0.19 <.001
youth_activity_rc (Basic Skills Activity)   0.03 0.05 .558
youth_activity_rc (Creating Product)   0.01 0.05 .839
youth_activity_rc (Field Trip Speaker)   0.01 0.10 .931
youth_activity_rc (Lab Activity)   0.08 0.10 .449
youth_activity_rc (Program Staff Led)   -0.05 0.06 .383
gender_female   -0.19 0.11 .085
urm   0.02 0.16 .876
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.023
ICCparticipant_ID   0.422
ICCprogram_ID   0.085
Observations   2791
R2 / Ω02   .578 / .575

A multi-level model using brms, that accounts for auto-correlation of residuals: not run (nor ready).

# 
# library(brms)
# 
# m1 <- brm(positive_affect ~ 1 + 
#               youth_activity_rc +
#               (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
#           control = list(adapt_delta = 0.999),
#           # autocor = cor_ar(TIME_POINT | PROGRAM, cov = TRUE),
#           data = df)
# 
# summary(m1)
# fit_brm <- brm(Y | se(sei) ~ X1 + X2 + (1|Area),
#                data = spacetime,
#                autocor = cor_ar(~ Time | Area, cov = TRUE),
#                prior = c(set_prior("normal(0,1)", class = "ar"),
#                          set_prior("normal(0,5)", class = "b")))

4. CLASS models (not ready)

df %>% 
    select(CLASS_EmotionalSupportEncouragement, CLASS_InstructionalSupport, CLASS_STEMConceptualDevelopment, CLASS_ActivityLeaderEnthusiasm, CLASS_Autonomy,
           challenge, relevance, learning, positive_affect) %>%  
    correlate() %>% 
    shave() %>% 
    fashion()
##                               rowname CLASS_EmotionalSupportEncouragement
## 1 CLASS_EmotionalSupportEncouragement                                    
## 2          CLASS_InstructionalSupport                                 .39
## 3     CLASS_STEMConceptualDevelopment                                 .28
## 4      CLASS_ActivityLeaderEnthusiasm                                 .63
## 5                      CLASS_Autonomy                                 .29
## 6                           challenge                                 .03
## 7                           relevance                                -.01
## 8                            learning                                 .00
## 9                     positive_affect                                 .01
##   CLASS_InstructionalSupport CLASS_STEMConceptualDevelopment
## 1                                                           
## 2                                                           
## 3                        .89                                
## 4                        .77                             .63
## 5                        .50                             .51
## 6                        .06                             .04
## 7                        .05                             .04
## 8                        .07                             .07
## 9                        .06                             .05
##   CLASS_ActivityLeaderEnthusiasm CLASS_Autonomy challenge relevance
## 1                                                                  
## 2                                                                  
## 3                                                                  
## 4                                                                  
## 5                            .52                                   
## 6                            .07            .06                    
## 7                            .04            .01       .39          
## 8                            .05            .02       .30       .65
## 9                            .09            .02       .27       .52
##   learning positive_affect
## 1                         
## 2                         
## 3                         
## 4                         
## 5                         
## 6                         
## 7                         
## 8                         
## 9      .48
m1v <- lmer(relevance ~ 1 + 
                # CLASS_EmotionalSupportEncouragement +
                # CLASS_InstructionalSupport +
                # CLASS_STEMConceptualDevelopment +
                # CLASS_ActivityLeaderEnthusiasm +
                CLASS_Autonomy +
                gender_female + 
                urm +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

sjPlot::sjt.lmer(m1v, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    relevance
    B std. Error p
Fixed Parts
(Intercept)   2.64 0.15 <.001
CLASS_Autonomy   0.03 0.01 .013
gender_female   -0.22 0.10 .031
urm   -0.05 0.15 .753
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.013
ICCparticipant_ID   0.517
ICCprogram_ID   0.011
Observations   2772
R2 / Ω02   .589 / .586
m1vi <- lmer(challenge ~ 1 +
                 # CLASS_EmotionalSupportEncouragement +
                 #CLASS_InstructionalSupport +
                 # CLASS_STEMConceptualDevelopment +
                 #CLASS_ActivityLeaderEnthusiasm +
                 CLASS_Autonomy +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

sjPlot::sjt.lmer(m1vi, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    challenge
    B std. Error p
Fixed Parts
(Intercept)   2.00 0.18 <.001
CLASS_Autonomy   0.08 0.02 <.001
gender_female   -0.26 0.11 .013
urm   0.16 0.15 .287
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.052
ICCparticipant_ID   0.373
ICCprogram_ID   0.038
Observations   2772
R2 / Ω02   .529 / .522
m1viii <- lmer(learning ~ 1 +
                   # CLASS_EmotionalSupportEncouragement +
                   #CLASS_InstructionalSupport +
                   # CLASS_STEMConceptualDevelopment +
                   #CLASS_ActivityLeaderEnthusiasm +
                   CLASS_Autonomy +
                   gender_female + 
                   urm +
                   (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
               data = df)

sjPlot::sjt.lmer(m1viii, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    learning
    B std. Error p
Fixed Parts
(Intercept)   2.65 0.15 <.001
CLASS_Autonomy   0.03 0.01 .040
gender_female   -0.06 0.10 .563
urm   0.06 0.14 .655
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.013
ICCparticipant_ID   0.357
ICCprogram_ID   0.001
Observations   2771
R2 / Ω02   .427 / .420
m1viv <- lmer(positive_affect ~ 1 +
                  # CLASS_EmotionalSupportEncouragement +
                  #CLASS_InstructionalSupport +
                  # CLASS_STEMConceptualDevelopment +
                  #CLASS_ActivityLeaderEnthusiasm +
                  CLASS_Autonomy +
                  gender_female + 
                  urm +
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

sjPlot::sjt.lmer(m1viv, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    positive_affect
    B std. Error p
Fixed Parts
(Intercept)   2.67 0.19 <.001
CLASS_Autonomy   0.03 0.01 .022
gender_female   -0.18 0.11 .096
urm   0.02 0.16 .901
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.022
ICCparticipant_ID   0.425
ICCprogram_ID   0.088
Observations   2772
R2 / Ω02   .582 / .579

5. Pre-survey measures (ready)

df %>% 
    select(overall_pre_competence_beliefs, overall_pre_interest, overall_pre_utility_value,
           challenge, relevance, learning, positive_affect) %>%  
    correlate() %>% 
    shave() %>% 
    fashion()
##                          rowname overall_pre_competence_beliefs
## 1 overall_pre_competence_beliefs                               
## 2           overall_pre_interest                            .73
## 3      overall_pre_utility_value                            .60
## 4                      challenge                           -.12
## 5                      relevance                            .03
## 6                       learning                            .09
## 7                positive_affect                            .08
##   overall_pre_interest overall_pre_utility_value challenge relevance
## 1                                                                   
## 2                                                                   
## 3                  .64                                              
## 4                 -.00                      -.03                    
## 5                  .09                       .11       .39          
## 6                  .08                       .09       .30       .65
## 7                  .20                       .04       .27       .52
##   learning positive_affect
## 1                         
## 2                         
## 3                         
## 4                         
## 5                         
## 6                         
## 7      .48
m2i <- lmer(challenge ~ 1 + 
                overall_pre_competence_beliefs +
                overall_pre_interest +
                overall_pre_utility_value +
                classroom_versus_field_enrichment +
                #youth_activity_rc +
                gender_female + 
                urm +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

sjPlot::sjt.lmer(m2i, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    challenge
    B std. Error p
Fixed Parts
(Intercept)   2.36 0.31 <.001
overall_pre_competence_beliefs   -0.29 0.11 .008
overall_pre_interest   0.21 0.12 .070
overall_pre_utility_value   0.02 0.11 .882
classroom_versus_field_enrichment   0.15 0.06 .016
gender_female   -0.24 0.11 .036
urm   0.18 0.16 .248
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.061
ICCparticipant_ID   0.372
ICCprogram_ID   0.039
Observations   2603
R2 / Ω02   .533 / .526
m2ib <- lmer(challenge ~ 1 +
                 overall_pre_competence_beliefs +
                 overall_pre_interest +
                 overall_pre_utility_value +
                 classroom_versus_field_enrichment +
                 youth_activity_rc +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

sjPlot::sjt.lmer(m2ib, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    challenge
    B std. Error p
Fixed Parts
(Intercept)   2.36 0.31 <.001
overall_pre_competence_beliefs   -0.29 0.11 .008
overall_pre_interest   0.19 0.12 .098
overall_pre_utility_value   0.03 0.11 .785
classroom_versus_field_enrichment   0.05 0.06 .394
youth_activity_rc (Basic Skills Activity)   0.09 0.07 .159
youth_activity_rc (Creating Product)   0.32 0.07 <.001
youth_activity_rc (Field Trip Speaker)   -0.08 0.14 .553
youth_activity_rc (Lab Activity)   0.17 0.13 .196
youth_activity_rc (Program Staff Led)   -0.13 0.08 .087
gender_female   -0.23 0.11 .043
urm   0.18 0.16 .253
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.048
ICCparticipant_ID   0.382
ICCprogram_ID   0.031
Observations   2572
R2 / Ω02   .529 / .523
m2ii <- lmer(relevance ~ 1 + 
                 overall_pre_competence_beliefs +
                 overall_pre_interest +
                 overall_pre_utility_value +
                 # youth_activity_rc +
                 classroom_versus_field_enrichment +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

sjPlot::sjt.lmer(m2ii, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    relevance
    B std. Error p
Fixed Parts
(Intercept)   2.26 0.29 <.001
overall_pre_competence_beliefs   -0.08 0.11 .443
overall_pre_interest   0.06 0.11 .580
overall_pre_utility_value   0.17 0.11 .109
classroom_versus_field_enrichment   -0.04 0.04 .267
gender_female   -0.24 0.11 .028
urm   -0.01 0.16 .951
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.017
ICCparticipant_ID   0.514
ICCprogram_ID   0.018
Observations   2603
R2 / Ω02   .595 / .592
m2iib <- lmer(relevance ~ 1 +
                  overall_pre_competence_beliefs +
                  overall_pre_interest +
                  overall_pre_utility_value +
                  youth_activity_rc +
                  classroom_versus_field_enrichment +
                  gender_female + 
                  urm +
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

sjPlot::sjt.lmer(m2iib, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    relevance
    B std. Error p
Fixed Parts
(Intercept)   2.16 0.30 <.001
overall_pre_competence_beliefs   -0.08 0.11 .454
overall_pre_interest   0.06 0.11 .621
overall_pre_utility_value   0.18 0.11 .101
youth_activity_rc (Basic Skills Activity)   0.13 0.04 .002
youth_activity_rc (Creating Product)   0.22 0.04 <.001
youth_activity_rc (Field Trip Speaker)   0.23 0.08 .004
youth_activity_rc (Lab Activity)   0.09 0.08 .234
youth_activity_rc (Program Staff Led)   0.15 0.05 .002
classroom_versus_field_enrichment   -0.07 0.04 .061
gender_female   -0.24 0.11 .030
urm   -0.02 0.16 .920
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.009
ICCparticipant_ID   0.517
ICCprogram_ID   0.026
Observations   2572
R2 / Ω02   .593 / .591
m2iii <- lmer(learning ~ 1 + 
                  overall_pre_competence_beliefs +
                  overall_pre_interest +
                  overall_pre_utility_value +
                  classroom_versus_field_enrichment +
                  #youth_activity_rc +
                  gender_female + 
                  urm +
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

sjPlot::sjt.lmer(m2iii, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    learning
    B std. Error p
Fixed Parts
(Intercept)   2.33 0.27 <.001
overall_pre_competence_beliefs   0.01 0.10 .887
overall_pre_interest   0.03 0.10 .749
overall_pre_utility_value   0.07 0.10 .457
classroom_versus_field_enrichment   0.02 0.05 .716
gender_female   -0.07 0.10 .480
urm   0.11 0.15 .451
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.013
ICCparticipant_ID   0.354
ICCprogram_ID   0.000
Observations   2602
R2 / Ω02   .418 / .412
m2iiib <- lmer(learning ~ 1 + 
                   overall_pre_competence_beliefs +
                   overall_pre_interest +
                   overall_pre_utility_value +
                   classroom_versus_field_enrichment +
                   youth_activity_rc +
                   gender_female + 
                   urm +
                   (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
               data = df)

sjPlot::sjt.lmer(m2iiib, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    learning
    B std. Error p
Fixed Parts
(Intercept)   2.25 0.28 <.001
overall_pre_competence_beliefs   0.01 0.10 .934
overall_pre_interest   0.04 0.10 .690
overall_pre_utility_value   0.07 0.10 .518
classroom_versus_field_enrichment   0.02 0.05 .723
youth_activity_rc (Basic Skills Activity)   0.21 0.05 <.001
youth_activity_rc (Creating Product)   0.11 0.06 .056
youth_activity_rc (Field Trip Speaker)   0.08 0.10 .399
youth_activity_rc (Lab Activity)   0.20 0.10 .041
youth_activity_rc (Program Staff Led)   0.06 0.06 .280
gender_female   -0.07 0.10 .475
urm   0.12 0.15 .429
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.009
ICCparticipant_ID   0.358
ICCprogram_ID   0.003
Observations   2571
R2 / Ω02   .419 / .413
df$positive_affect <- jmRtools::composite_mean_maker(df, happy, excited)

m2iv <- lmer(positive_affect ~ 
                 overall_pre_competence_beliefs +
                 overall_pre_interest +
                 overall_pre_utility_value +
                 classroom_versus_field_enrichment +
                 # youth_activity_rc +
                 gender_female + 
                 urm +
                 (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
             data = df)

sjPlot::sjt.lmer(m2iv, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    positive_affect
    B std. Error p
Fixed Parts
(Intercept)   2.35 0.32 <.001
overall_pre_competence_beliefs   -0.04 0.11 .748
overall_pre_interest   0.28 0.12 .025
overall_pre_utility_value   -0.09 0.12 .457
classroom_versus_field_enrichment   -0.05 0.05 .282
gender_female   -0.16 0.12 .177
urm   0.04 0.17 .814
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.029
ICCparticipant_ID   0.450
ICCprogram_ID   0.050
Observations   2603
R2 / Ω02   .585 / .581
m2ivb <- lmer(positive_affect ~ 
                  overall_pre_competence_beliefs +
                  overall_pre_interest +
                  overall_pre_utility_value +
                  classroom_versus_field_enrichment +
                  youth_activity_rc +
                  gender_female + 
                  urm +
                  (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
              data = df)

sjPlot::sjt.lmer(m2ivb, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    positive_affect
    B std. Error p
Fixed Parts
(Intercept)   2.38 0.32 <.001
overall_pre_competence_beliefs   -0.04 0.11 .718
overall_pre_interest   0.28 0.12 .024
overall_pre_utility_value   -0.09 0.12 .442
classroom_versus_field_enrichment   -0.06 0.05 .268
youth_activity_rc (Basic Skills Activity)   -0.00 0.06 .994
youth_activity_rc (Creating Product)   0.01 0.06 .869
youth_activity_rc (Field Trip Speaker)   -0.04 0.11 .756
youth_activity_rc (Lab Activity)   0.07 0.11 .501
youth_activity_rc (Program Staff Led)   -0.07 0.07 .252
gender_female   -0.15 0.12 .187
urm   0.04 0.17 .798
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.030
ICCparticipant_ID   0.448
ICCprogram_ID   0.047
Observations   2572
R2 / Ω02   .584 / .580

6. Situational experiences (ready)

df$overall_engagement <- jmRtools::composite_mean_maker(df, hard_working, concentrating, enjoy)

df %>% 
    select(overall_engagement, interest, challenge, relevance, learning, positive_affect) %>%  
    correlate() %>% 
    shave() %>% 
    fashion()
##              rowname overall_engagement interest challenge relevance
## 1 overall_engagement                                                
## 2           interest                .69                             
## 3          challenge                .31      .28                    
## 4          relevance                .65      .61       .39          
## 5           learning                .68      .56       .30       .65
## 6    positive_affect                .65      .56       .27       .52
##   learning positive_affect
## 1                         
## 2                         
## 3                         
## 4                         
## 5                         
## 6      .48
m3i <- lmer(interest ~ 1 +
                challenge + relevance + learning + positive_affect +
                gender_female + 
                urm +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

sjPlot::sjt.lmer(m3i, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    interest
    B std. Error p
Fixed Parts
(Intercept)   0.63 0.09 <.001
challenge   0.02 0.01 .104
relevance   0.36 0.02 <.001
learning   0.17 0.02 <.001
positive_affect   0.28 0.02 <.001
gender_female   0.05 0.05 .285
urm   -0.02 0.06 .786
Random Parts
Nbeep_ID_new   248
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.033
ICCparticipant_ID   0.099
ICCprogram_ID   0.014
Observations   2941
R2 / Ω02   .584 / .582
m3v <- lmer(overall_engagement ~ 1 + 
                challenge + relevance + learning + positive_affect +
                gender_female + 
                urm +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

sjPlot::sjt.lmer(m3v, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    overall_engagement
    B std. Error p
Fixed Parts
(Intercept)   0.67 0.07 <.001
challenge   0.04 0.01 <.001
relevance   0.23 0.02 <.001
learning   0.27 0.01 <.001
positive_affect   0.28 0.01 <.001
gender_female   0.07 0.04 .072
urm   -0.03 0.06 .618
Random Parts
Nbeep_ID_new   248
Nparticipant_ID   201
Nprogram_ID   9
ICCbeep_ID_new   0.029
ICCparticipant_ID   0.201
ICCprogram_ID   0.000
Observations   2941
R2 / Ω02   .737 / .736
m3i_update <- lmer(interest ~ 1 +
                       challenge + relevance + learning + positive_affect +
                       overall_pre_competence_beliefs +
                       overall_pre_interest +
                       classroom_versus_field_enrichment +
                       gender_female + 
                       urm +
                       (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
                   data = df)

sjPlot::sjt.lmer(m3i_update, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    interest
    B std. Error p
Fixed Parts
(Intercept)   0.51 0.14 <.001
challenge   0.03 0.02 .104
relevance   0.35 0.02 <.001
learning   0.17 0.02 <.001
positive_affect   0.28 0.02 <.001
overall_pre_competence_beliefs   0.02 0.05 .732
overall_pre_interest   0.02 0.05 .727
classroom_versus_field_enrichment   0.07 0.04 .097
gender_female   0.04 0.05 .402
urm   -0.00 0.07 .987
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   180
Nprogram_ID   9
ICCbeep_ID_new   0.037
ICCparticipant_ID   0.101
ICCprogram_ID   0.014
Observations   2605
R2 / Ω02   .580 / .578
m3v_update <- lmer(overall_engagement ~ 1 + 
                       challenge + relevance + learning + positive_affect + 
                       overall_pre_competence_beliefs +
                       overall_pre_interest +
                       classroom_versus_field_enrichment +
                       gender_female + 
                       urm +
                       (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
                   data = df)

sjPlot::sjt.lmer(m3v_update, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    overall_engagement
    B std. Error p
Fixed Parts
(Intercept)   0.54 0.11 <.001
challenge   0.03 0.01 .005
relevance   0.24 0.02 <.001
learning   0.25 0.01 <.001
positive_affect   0.28 0.01 <.001
overall_pre_competence_beliefs   -0.00 0.04 .950
overall_pre_interest   0.03 0.04 .507
classroom_versus_field_enrichment   0.09 0.03 <.001
gender_female   0.07 0.04 .099
urm   -0.02 0.06 .780
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   180
Nprogram_ID   9
ICCbeep_ID_new   0.027
ICCparticipant_ID   0.213
ICCprogram_ID   0.002
Observations   2605
R2 / Ω02   .738 / .738

7. Outcomes (not ready)

participant_df <-df %>% 
    select(participant_ID, challenge, relevance, learning, positive_affect, good_at) %>% 
    group_by(participant_ID) %>% 
    mutate_at(vars(challenge, relevance, learning, positive_affect, good_at), funs(mean, sd)) %>%
    select(participant_ID, contains("mean"), contains("sd")) %>% 
    distinct()

df_ss <- left_join(df, participant_df)

df_ss <- select(df_ss, 
                participant_ID, program_ID,
                challenge_mean, relevance_mean, learning_mean, positive_affect_mean, good_at_mean,
                challenge_sd, relevance_sd, learning_sd, positive_affect_sd, good_at_sd,
                overall_post_interest, overall_pre_interest,
                future_goals)

df_ss <- distinct(df_ss)

df_ss$program_ID <- as.integer(df_ss$program_ID)

df_ss <- left_join(df_ss, pm)

# df_ss <- left_join(df_ss, m)

m4ia <- lmer(overall_post_interest ~ 1 + 
                 #challenge_mean + challenge_sd +
                 #learning_mean + 
                 relevance_mean + 
                 #positive_affect_mean + 
                 overall_pre_interest +
                 
                 (1|program_ID),
             data = df_ss)

sjPlot::sjt.lmer(m4ia, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    overall_post_interest
    B std. Error p
Fixed Parts
(Intercept)   0.94 0.22 <.001
relevance_mean   0.22 0.05 <.001
overall_pre_interest   0.51 0.05 <.001
Random Parts
Nprogram_ID   9
ICCprogram_ID   0.111
Observations   427
R2 / Ω02   .427 / .427
m4ib <- lmer(overall_post_interest ~ 1 + 
                 challenge_mean + challenge_sd +
                 learning_mean + learning_sd +
                 relevance_mean + relevance_sd +
                 positive_affect_mean + positive_affect_sd +
                 overall_pre_interest +
                 (1|program_ID),
             data = df_ss)

sjPlot::sjt.lmer(m4ib, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    overall_post_interest
    B std. Error p
Fixed Parts
(Intercept)   0.69 0.27 .011
challenge_mean   -0.07 0.06 .275
challenge_sd   -0.50 0.13 <.001
learning_mean   0.51 0.11 <.001
learning_sd   0.05 0.13 .701
relevance_mean   -0.25 0.12 .037
relevance_sd   0.31 0.18 .087
positive_affect_mean   0.16 0.07 .022
positive_affect_sd   0.07 0.13 .570
overall_pre_interest   0.47 0.05 <.001
Random Parts
Nprogram_ID   9
ICCprogram_ID   0.110
Observations   425
R2 / Ω02   .492 / .492
m4iia <- lmer(future_goals ~ 1 + 
                  challenge_mean + 
                  learning_mean + 
                  relevance_mean +
                  positive_affect_mean + 
                  overall_pre_interest +
                  (1|program_ID),
              data = df_ss)

sjPlot::sjt.lmer(m4iia, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    future_goals
    B std. Error p
Fixed Parts
(Intercept)   1.27 0.27 <.001
challenge_mean   0.07 0.08 .351
learning_mean   -0.15 0.15 .302
relevance_mean   0.62 0.15 <.001
positive_affect_mean   -0.05 0.08 .556
overall_pre_interest   -0.00 0.05 .941
Random Parts
Nprogram_ID   9
ICCprogram_ID   0.000
Observations   529
R2 / Ω02   .092 / .092
m4iib <- lmer(future_goals ~ 1 + 
                  challenge_mean + challenge_sd +
                  learning_mean + learning_sd +
                  relevance_mean + relevance_sd +
                  positive_affect_mean + positive_affect_sd +
                  overall_pre_interest +
                  (1|program_ID),
              data = df_ss)

sjPlot::sjt.lmer(m4iib, p.kr = F, show.re.var = F, show.ci = F, show.se = T)
    future_goals
    B std. Error p
Fixed Parts
(Intercept)   1.29 0.33 <.001
challenge_mean   0.06 0.08 .443
challenge_sd   -0.09 0.16 .582
learning_mean   -0.13 0.15 .408
learning_sd   0.06 0.18 .753
relevance_mean   0.61 0.15 <.001
relevance_sd   -0.15 0.25 .559
positive_affect_mean   -0.04 0.08 .624
positive_affect_sd   0.08 0.17 .632
overall_pre_interest   -0.01 0.05 .818
Random Parts
Nprogram_ID   9
ICCprogram_ID   0.000
Observations   528
R2 / Ω02   .091 / .091