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-pqa.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)

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)

class_data
## # A tibble: 236 x 9
##    program_ID response_date signal_number sociedad_class
##         <int>         <chr>         <int>          <chr>
##  1          1    2015-07-14             1           <NA>
##  2          1    2015-07-14             2           <NA>
##  3          1    2015-07-14             4           <NA>
##  4          1    2015-07-15             1           <NA>
##  5          1    2015-07-15             2           <NA>
##  6          1    2015-07-15             3           <NA>
##  7          1    2015-07-15             4           <NA>
##  8          1    2015-07-21             1           <NA>
##  9          1    2015-07-21             2           <NA>
## 10          1    2015-07-21             3           <NA>
## # ... with 226 more rows, and 5 more variables:
## #   CLASS_EmotionalSupportEncouragement <dbl>,
## #   CLASS_InstructionalSupport <dbl>, CLASS_Autonomy <int>,
## #   CLASS_STEMConceptualDevelopment <dbl>,
## #   CLASS_ActivityLeaderEnthusiasm <dbl>
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 + learning +
                (1|program_ID) + (1|participant_ID) + (1|beep_ID_new),
            data = df)

summary(m0i)
## Linear mixed model fit by REML ['lmerMod']
## Formula: 
## challenge ~ 1 + learning + (1 | program_ID) + (1 | participant_ID) +  
##     (1 | beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 7817.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9899 -0.6311 -0.0309  0.5566  3.3387 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.07003  0.2646  
##  participant_ID (Intercept) 0.40103  0.6333  
##  program_ID     (Intercept) 0.03732  0.1932  
##  Residual                   0.65414  0.8088  
## Number of obs: 2969, groups:  
## beep_ID_new, 248; participant_ID, 203; program_ID, 9
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept)  1.76093    0.09650   18.25
## learning     0.18618    0.01796   10.37
## 
## Correlation of Fixed Effects:
##          (Intr)
## learning -0.516
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
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
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

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$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
m1i <- lmer(challenge ~ 1 + 
                youth_activity_rc +
                gender_female + 
                race_other +
                (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.02 0.16 <.001
youth_activity_rc (Basic Skills Activity)   0.10 0.06 .115
youth_activity_rc (Creating Product)   0.36 0.07 <.001
youth_activity_rc (Field Trip Speaker)   -0.08 0.13 .513
youth_activity_rc (Lab Activity)   0.21 0.13 .095
youth_activity_rc (Program Staff Led)   -0.11 0.07 .136
gender_female (M)   0.25 0.11 .019
race_other (Black)   0.04 0.16 .826
race_other (Hispanic)   0.09 0.15 .578
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.045
ICCparticipant_ID   0.384
ICCprogram_ID   0.030
Observations   2767
R2 / Ω02   .527 / .520
m1ii <- lmer(relevance ~ 1 + 
                 youth_activity_rc +
                 gender_female + 
                 race_other +
                 (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.43 0.15 <.001
youth_activity_rc (Basic Skills Activity)   0.14 0.04 <.001
youth_activity_rc (Creating Product)   0.22 0.04 <.001
youth_activity_rc (Field Trip Speaker)   0.29 0.08 <.001
youth_activity_rc (Lab Activity)   0.14 0.07 .065
youth_activity_rc (Program Staff Led)   0.15 0.05 <.001
gender_female (M)   0.20 0.10 .048
race_other (Black)   -0.16 0.16 .303
race_other (Hispanic)   -0.01 0.15 .961
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.008
ICCparticipant_ID   0.520
ICCprogram_ID   0.012
Observations   2767
R2 / Ω02   .584 / .582
m1iii <- lmer(learning ~ 1 + 
                  youth_activity_rc +
                  gender_female + 
                  race_other +
                  (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.21 0.05 <.001
youth_activity_rc (Creating Product)   0.12 0.05 .027
youth_activity_rc (Field Trip Speaker)   0.09 0.10 .363
youth_activity_rc (Lab Activity)   0.15 0.10 .107
youth_activity_rc (Program Staff Led)   0.06 0.06 .336
gender_female (M)   0.05 0.10 .646
race_other (Black)   -0.08 0.15 .605
race_other (Hispanic)   0.08 0.14 .560
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.010
ICCparticipant_ID   0.365
ICCprogram_ID   0.000
Observations   2766
R2 / Ω02   .431 / .425
df$positive_affect <- jmRtools::composite_mean_maker(df,
                                                     happy, excited)

m1iv <- lmer(positive_affect ~ 1 + 
                 youth_activity_rc +
                 gender_female + 
                 race_other +
                 (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 + race_other +  
##     (1 | program_ID) + (1 | participant_ID) + (1 | beep_ID_new)
##    Data: df
## 
## REML criterion at convergence: 6798.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4868 -0.4516  0.0529  0.5520  3.4745 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  beep_ID_new    (Intercept) 0.02813  0.1677  
##  participant_ID (Intercept) 0.50178  0.7084  
##  program_ID     (Intercept) 0.09505  0.3083  
##  Residual                   0.54258  0.7366  
## Number of obs: 2767, groups:  
## beep_ID_new, 235; participant_ID, 200; program_ID, 9
## 
## Fixed effects:
##                                         Estimate Std. Error t value
## (Intercept)                             2.622025   0.183953  14.254
## youth_activity_rcBasic Skills Activity  0.027367   0.052663   0.520
## youth_activity_rcCreating Product       0.022836   0.053397   0.428
## youth_activity_rcField Trip Speaker     0.011171   0.103798   0.108
## youth_activity_rcLab Activity           0.077942   0.101236   0.770
## youth_activity_rcProgram Staff Led     -0.054424   0.060824  -0.895
## gender_femaleM                          0.184540   0.109204   1.690
## race_otherBlack                        -0.051718   0.167531  -0.309
## race_otherHispanic                      0.001509   0.157997   0.010
## 
## Correlation of Fixed Effects:
##             (Intr) y__BSA yt__CP y__FTS yt__LA y__PSL gndr_M rc_thB
## yth_ctv_BSA -0.118                                                 
## yth_ctvt_CP -0.103  0.384                                          
## yth_ctv_FTS -0.059  0.235  0.213                                   
## yth_ctvt_LA -0.061  0.197  0.190  0.132                            
## yth_ctv_PSL -0.102  0.410  0.307  0.183  0.179                     
## gender_fmlM -0.358 -0.001 -0.010 -0.003  0.002  0.008              
## rac_thrBlck -0.634  0.000 -0.005 -0.006  0.004 -0.003  0.086       
## rc_thrHspnc -0.659  0.003 -0.005 -0.003  0.000 -0.001  0.082  0.720
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.62 0.18 <.001
youth_activity_rc (Basic Skills Activity)   0.03 0.05 .603
youth_activity_rc (Creating Product)   0.02 0.05 .669
youth_activity_rc (Field Trip Speaker)   0.01 0.10 .914
youth_activity_rc (Lab Activity)   0.08 0.10 .441
youth_activity_rc (Program Staff Led)   -0.05 0.06 .371
gender_female (M)   0.18 0.11 .091
race_other (Black)   -0.05 0.17 .758
race_other (Hispanic)   0.00 0.16 .992
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.024
ICCparticipant_ID   0.430
ICCprogram_ID   0.081
Observations   2767
R2 / Ω02   .585 / .581

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 + 
                race_other +
                (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.44 0.15 <.001
CLASS_Autonomy   0.03 0.01 .016
gender_female (M)   0.21 0.10 .043
race_other (Black)   -0.14 0.15 .372
race_other (Hispanic)   -0.01 0.15 .963
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.014
ICCparticipant_ID   0.516
ICCprogram_ID   0.009
Observations   2748
R2 / Ω02   .587 / .584
m1vi <- lmer(challenge ~ 1 +
                 # CLASS_EmotionalSupportEncouragement +
                 #CLASS_InstructionalSupport +
                 # CLASS_STEMConceptualDevelopment +
                 #CLASS_ActivityLeaderEnthusiasm +
                 CLASS_Autonomy +
                 gender_female + 
                 race_other +
                 (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)   1.84 0.18 <.001
CLASS_Autonomy   0.08 0.02 <.001
gender_female (M)   0.25 0.11 .019
race_other (Black)   0.04 0.16 .790
race_other (Hispanic)   0.08 0.15 .614
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.053
ICCparticipant_ID   0.374
ICCprogram_ID   0.038
Observations   2748
R2 / Ω02   .529 / .522
m1viii <- lmer(learning ~ 1 +
                   # CLASS_EmotionalSupportEncouragement +
                   #CLASS_InstructionalSupport +
                   # CLASS_STEMConceptualDevelopment +
                   #CLASS_ActivityLeaderEnthusiasm +
                   CLASS_Autonomy +
                   gender_female + 
                   race_other +
                   (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.66 0.14 <.001
CLASS_Autonomy   0.02 0.01 .069
gender_female (M)   0.05 0.10 .624
race_other (Black)   -0.08 0.15 .603
race_other (Hispanic)   0.07 0.14 .625
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.013
ICCparticipant_ID   0.361
ICCprogram_ID   0.000
Observations   2747
R2 / Ω02   .431 / .424
m1viv <- lmer(positive_affect ~ 1 +
                  # CLASS_EmotionalSupportEncouragement +
                  #CLASS_InstructionalSupport +
                  # CLASS_STEMConceptualDevelopment +
                  #CLASS_ActivityLeaderEnthusiasm +
                  CLASS_Autonomy +
                  gender_female + 
                  race_other +
                  (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.52 0.19 <.001
CLASS_Autonomy   0.03 0.01 .013
gender_female (M)   0.18 0.11 .104
race_other (Black)   -0.07 0.17 .679
race_other (Hispanic)   -0.01 0.16 .928
Random Parts
Nbeep_ID_new   236
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.022
ICCparticipant_ID   0.432
ICCprogram_ID   0.085
Observations   2748
R2 / Ω02   .588 / .585

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 + 
                race_other +
                (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.21 0.28 <.001
overall_pre_competence_beliefs   -0.28 0.11 .011
overall_pre_interest   0.21 0.10 .043
classroom_versus_field_enrichment   0.14 0.06 .022
gender_female (M)   0.23 0.11 .039
race_other (Black)   0.09 0.17 .577
race_other (Hispanic)   0.12 0.16 .446
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.063
ICCparticipant_ID   0.372
ICCprogram_ID   0.038
Observations   2582
R2 / Ω02   .534 / .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 + 
                 race_other +
                 (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.24 0.28 <.001
overall_pre_competence_beliefs   -0.27 0.11 .011
overall_pre_interest   0.20 0.10 .058
classroom_versus_field_enrichment   0.05 0.06 .459
youth_activity_rc (Basic Skills Activity)   0.10 0.07 .136
youth_activity_rc (Creating Product)   0.32 0.07 <.001
youth_activity_rc (Field Trip Speaker)   -0.08 0.14 .546
youth_activity_rc (Lab Activity)   0.17 0.13 .193
youth_activity_rc (Program Staff Led)   -0.13 0.08 .083
gender_female (M)   0.22 0.11 .048
race_other (Black)   0.09 0.17 .608
race_other (Hispanic)   0.13 0.16 .418
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.049
ICCparticipant_ID   0.383
ICCprogram_ID   0.030
Observations   2551
R2 / Ω02   .530 / .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 + 
                 race_other +
                 (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.27 0.26 <.001
overall_pre_competence_beliefs   -0.04 0.10 .735
overall_pre_interest   0.12 0.10 .215
classroom_versus_field_enrichment   -0.04 0.04 .322
gender_female (M)   0.22 0.11 .046
race_other (Black)   -0.08 0.16 .623
race_other (Hispanic)   0.02 0.16 .881
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.018
ICCparticipant_ID   0.518
ICCprogram_ID   0.012
Observations   2582
R2 / Ω02   .593 / .590
m2iib <- lmer(relevance ~ 1 +
                  #overall_pre_competence_beliefs +
                  overall_pre_interest +
                  #overall_pre_utility_value +
                  youth_activity_rc +
                  classroom_versus_field_enrichment +
                  gender_female + 
                  race_other +
                  (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.25 <.001
overall_pre_interest   0.10 0.06 .129
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.10 0.08 .223
youth_activity_rc (Program Staff Led)   0.15 0.05 .002
classroom_versus_field_enrichment   -0.07 0.04 .076
gender_female (M)   0.22 0.11 .043
race_other (Black)   -0.09 0.16 .568
race_other (Hispanic)   0.02 0.16 .922
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.010
ICCparticipant_ID   0.520
ICCprogram_ID   0.019
Observations   2551
R2 / Ω02   .591 / .589
m2iii <- lmer(learning ~ 1 + 
                  overall_pre_competence_beliefs +
                  overall_pre_interest +
                  #overall_pre_utility_value +
                  classroom_versus_field_enrichment +
                  #youth_activity_rc +
                  gender_female + 
                  race_other +
                  (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.41 0.23 <.001
overall_pre_competence_beliefs   0.04 0.10 .648
overall_pre_interest   0.05 0.09 .586
classroom_versus_field_enrichment   0.01 0.05 .781
gender_female (M)   0.07 0.10 .529
race_other (Black)   -0.02 0.15 .897
race_other (Hispanic)   0.10 0.15 .501
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.013
ICCparticipant_ID   0.358
ICCprogram_ID   0.000
Observations   2581
R2 / Ω02   .423 / .416
m2iiib <- lmer(learning ~ 1 + 
                   overall_pre_competence_beliefs +
                   overall_pre_interest +
                   #overall_pre_utility_value +
                   classroom_versus_field_enrichment +
                   youth_activity_rc +
                   gender_female + 
                   race_other +
                   (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.36 0.24 <.001
overall_pre_competence_beliefs   0.03 0.10 .750
overall_pre_interest   0.05 0.09 .569
classroom_versus_field_enrichment   0.01 0.05 .787
youth_activity_rc (Basic Skills Activity)   0.20 0.05 <.001
youth_activity_rc (Creating Product)   0.10 0.06 .083
youth_activity_rc (Field Trip Speaker)   0.07 0.10 .477
youth_activity_rc (Lab Activity)   0.19 0.10 .057
youth_activity_rc (Program Staff Led)   0.05 0.06 .400
gender_female (M)   0.06 0.10 .543
race_other (Black)   -0.02 0.15 .888
race_other (Hispanic)   0.11 0.15 .468
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.010
ICCparticipant_ID   0.364
ICCprogram_ID   0.000
Observations   2550
R2 / Ω02   .425 / .419
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 + 
                 race_other +
                 (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.15 0.30 <.001
overall_pre_competence_beliefs   -0.05 0.11 .683
overall_pre_interest   0.23 0.11 .039
classroom_versus_field_enrichment   -0.05 0.05 .348
gender_female (M)   0.16 0.12 .179
race_other (Black)   -0.07 0.18 .700
race_other (Hispanic)   -0.01 0.17 .936
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.030
ICCparticipant_ID   0.452
ICCprogram_ID   0.056
Observations   2582
R2 / Ω02   .592 / .588
m2ivb <- lmer(positive_affect ~ 
                  overall_pre_competence_beliefs +
                  overall_pre_interest +
                  classroom_versus_field_enrichment +
                  youth_activity_rc +
                  gender_female + 
                  race_other +
                  (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.18 0.30 <.001
overall_pre_competence_beliefs   -0.05 0.11 .649
overall_pre_interest   0.23 0.11 .039
classroom_versus_field_enrichment   -0.06 0.05 .288
youth_activity_rc (Basic Skills Activity)   -0.00 0.06 .948
youth_activity_rc (Creating Product)   0.02 0.06 .707
youth_activity_rc (Field Trip Speaker)   -0.03 0.11 .786
youth_activity_rc (Lab Activity)   0.07 0.11 .521
youth_activity_rc (Program Staff Led)   -0.08 0.07 .251
gender_female (M)   0.15 0.12 .190
race_other (Black)   -0.07 0.18 .706
race_other (Hispanic)   -0.01 0.17 .956
Random Parts
Nbeep_ID_new   235
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.032
ICCparticipant_ID   0.450
ICCprogram_ID   0.051
Observations   2551
R2 / Ω02   .591 / .587

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 + 
                race_other +
                (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.66 0.09 <.001
challenge   0.02 0.01 .099
relevance   0.37 0.02 <.001
learning   0.18 0.02 <.001
positive_affect   0.27 0.02 <.001
gender_female (M)   -0.04 0.05 .364
race_other (Black)   -0.03 0.07 .678
race_other (Hispanic)   0.00 0.06 .980
Random Parts
Nbeep_ID_new   248
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.034
ICCparticipant_ID   0.093
ICCprogram_ID   0.014
Observations   2917
R2 / Ω02   .585 / .583
m3v <- lmer(overall_engagement ~ 1 + 
                challenge + relevance + learning + positive_affect +
                gender_female + 
                race_other +
                (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.71 0.07 <.001
challenge   0.04 0.01 <.001
relevance   0.24 0.02 <.001
learning   0.27 0.01 <.001
positive_affect   0.27 0.01 <.001
gender_female (M)   -0.06 0.04 .103
race_other (Black)   -0.02 0.06 .729
race_other (Hispanic)   -0.01 0.06 .908
Random Parts
Nbeep_ID_new   248
Nparticipant_ID   200
Nprogram_ID   9
ICCbeep_ID_new   0.032
ICCparticipant_ID   0.196
ICCprogram_ID   0.000
Observations   2917
R2 / Ω02   .740 / .739
m3i_update <- lmer(interest ~ 1 +
                       challenge + relevance + learning + positive_affect +
                       overall_pre_competence_beliefs +
                       overall_pre_interest +
                       classroom_versus_field_enrichment +
                       gender_female + 
                       race_other +
                       (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.56 0.13 <.001
challenge   0.03 0.02 .098
relevance   0.36 0.02 <.001
learning   0.17 0.02 <.001
positive_affect   0.27 0.02 <.001
overall_pre_competence_beliefs   0.00 0.05 .936
overall_pre_interest   0.02 0.04 .642
classroom_versus_field_enrichment   0.08 0.04 .073
gender_female (M)   -0.04 0.05 .465
race_other (Black)   -0.03 0.07 .688
race_other (Hispanic)   0.03 0.07 .664
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.038
ICCparticipant_ID   0.093
ICCprogram_ID   0.013
Observations   2581
R2 / Ω02   .581 / .579
m3v_update <- lmer(overall_engagement ~ 1 + 
                       challenge + relevance + learning + positive_affect + 
                       overall_pre_competence_beliefs +
                       overall_pre_interest +
                       classroom_versus_field_enrichment +
                       gender_female + 
                       race_other +
                       (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.59 0.11 <.001
challenge   0.03 0.01 .007
relevance   0.25 0.02 <.001
learning   0.25 0.01 <.001
positive_affect   0.28 0.01 <.001
overall_pre_competence_beliefs   -0.01 0.04 .807
overall_pre_interest   0.03 0.04 .450
classroom_versus_field_enrichment   0.10 0.03 <.001
gender_female (M)   -0.07 0.04 .126
race_other (Black)   -0.01 0.06 .817
race_other (Hispanic)   -0.01 0.06 .919
Random Parts
Nbeep_ID_new   238
Nparticipant_ID   179
Nprogram_ID   9
ICCbeep_ID_new   0.029
ICCparticipant_ID   0.205
ICCprogram_ID   0.004
Observations   2581
R2 / Ω02   .741 / .741

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