Loading packages

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.0.0     ✔ readr   1.1.1
## ✔ tibble  1.4.2     ✔ purrr   0.2.5
## ✔ tidyr   0.8.1     ✔ stringr 1.3.1
## ✔ ggplot2 3.0.0     ✔ forcats 0.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following object is masked from 'package:tidyr':
## 
##     expand
library(lmerTest)
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library(sjstats)
library(jmRtools)
library(MuMIn)
library(konfound)
## Sensitivity analysis as described in Frank, Maroulis, Duong, and Kelcey (2013) and in Frank (2000).
## For more information visit https://jmichaelrosenberg.shinyapps.io/shinykonfound/.

Loading data

imuscle_esm <- read_csv("iMUScLE-esm.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   TEACHID = col_integer(),
##   PERIOD = col_integer(),
##   MONTH = col_integer(),
##   DAY = col_integer(),
##   YEAR = col_integer(),
##   time = col_integer(),
##   timepoint = col_integer(),
##   STUDID = col_integer(),
##   ENJOY = col_integer(),
##   group = col_integer(),
##   brain = col_integer(),
##   grade = col_integer(),
##   ESF_counts = col_integer(),
##   Uti7T = col_integer(),
##   Uti7S = col_integer(),
##   Uti79TS = col_integer(),
##   Uti7T9B = col_integer(),
##   Use_r = col_integer(),
##   Uful_r = col_integer(),
##   Ugroup = col_integer()
##   # ... with 4 more columns
## )
## See spec(...) for full column specifications.
## Warning in rbind(names(probs), probs_f): number of columns of result is not
## a multiple of vector length (arg 1)
## Warning: 7029 parsing failures.
## row # A tibble: 5 x 5 col     row col   expected   actual file              expected   <int> <chr> <chr>      <chr>  <chr>             actual 1  3172 Uti7T an integer NaN    'iMUScLE-esm.csv' file 2  3172 Uti7S an integer NaN    'iMUScLE-esm.csv' row 3  3173 Uti7T an integer NaN    'iMUScLE-esm.csv' col 4  3173 Uti7S an integer NaN    'iMUScLE-esm.csv' expected 5  3174 Uti7T an integer NaN    'iMUScLE-esm.csv'
## ... ................. ... ................................................. ........ ................................................. ...... ................................................. .... ................................................. ... ................................................. ... ................................................. ........ .................................................
## See problems(...) for more details.
imuscle_student_survey <- read_csv("iMUScLE-student-survey.csv")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   STUDID = col_integer(),
##   TEACH_ID = col_integer(),
##   gender = col_integer(),
##   immigstatus = col_integer(),
##   immigrant = col_integer(),
##   school = col_integer(),
##   race_r = col_integer(),
##   pared = col_integer(),
##   period_mean = col_integer(),
##   group = col_integer(),
##   focal = col_integer(),
##   absent = col_integer(),
##   ABSENT_7_9 = col_integer(),
##   brainology = col_integer(),
##   TUndermine = col_integer(),
##   MS_Quarter1_SCI_7thgrade = col_character(),
##   MS_Quarter2_SCI_7thgrade = col_character(),
##   MS_Quarter3_SCI_7thgrade = col_character(),
##   MS_Quarter4_SCI_7thgrade = col_character(),
##   MS_Notes_grade7 = col_character()
##   # ... with 108 more columns
## )
## See spec(...) for full column specifications.

Creating variables

imuscle_esm$classroom<-paste(imuscle_esm$TEACHID, imuscle_esm$PERIOD)
imuscle_esm$uv_intervention<-ifelse(imuscle_esm$group == 2, 1,
                                    ifelse(imuscle_esm$group == 4, 0, NA))
imuscle_student_survey$grade_binary <- ifelse(imuscle_student_survey$grade == 9, 1,
                                              ifelse(imuscle_student_survey$grade == 7, 0, NA))
imuscle_student_survey$urm <- ifelse(imuscle_student_survey$race == 1, 0,
                                     ifelse(imuscle_student_survey$race == 4, 0,
                                            ifelse(imuscle_student_survey$race == 14, 0, 1)))
imuscle_student_survey$female <-ifelse(imuscle_student_survey$gender == 2, 1, 0)

Join data

imuscle_all <- left_join(imuscle_student_survey, imuscle_esm, by = "STUDID")

Predicting momentary interest

M1 <- lmer(INTEREST ~ 
             female + 
             urm +
             grade_binary +
             uv_intervention +
             t_week +
             #t_week*uv_intervention +
             t_week*SKILL*uv_intervention +
             SKILL +
             (1|STUDID) + (1|classroom), data = imuscle_all)
summary(M1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## INTEREST ~ female + urm + grade_binary + uv_intervention + t_week +  
##     t_week * SKILL * uv_intervention + SKILL + (1 | STUDID) +  
##     (1 | classroom)
##    Data: imuscle_all
## 
## REML criterion at convergence: 7144
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.86922 -0.65608 -0.01205  0.64137  3.13681 
## 
## Random effects:
##  Groups    Name        Variance Std.Dev.
##  STUDID    (Intercept) 0.25756  0.5075  
##  classroom (Intercept) 0.05714  0.2390  
##  Residual              0.65368  0.8085  
## Number of obs: 2743, groups:  STUDID, 292; classroom, 16
## 
## Fixed effects:
##                                Estimate Std. Error         df t value
## (Intercept)                   7.977e-01  1.502e-01  6.532e+01   5.313
## female                       -1.471e-01  6.821e-02  2.827e+02  -2.156
## urm                           2.107e-01  8.230e-02  2.839e+02   2.561
## grade_binary                 -1.459e-01  1.423e-01  1.568e+01  -1.025
## uv_intervention               1.913e-01  1.775e-01  4.052e+01   1.078
## t_week                       -6.685e-03  7.117e-03  2.512e+03  -0.939
## SKILL                         3.870e-01  3.601e-02  2.696e+03  10.747
## t_week:SKILL                  5.297e-04  3.186e-03  2.523e+03   0.166
## uv_intervention:t_week       -1.901e-02  1.000e-02  2.541e+03  -1.901
## uv_intervention:SKILL        -5.465e-02  5.292e-02  2.711e+03  -1.033
## uv_intervention:t_week:SKILL  7.290e-03  4.684e-03  2.537e+03   1.556
##                              Pr(>|t|)    
## (Intercept)                   1.4e-06 ***
## female                         0.0319 *  
## urm                            0.0110 *  
## grade_binary                   0.3209    
## uv_intervention                0.2875    
## t_week                         0.3477    
## SKILL                         < 2e-16 ***
## t_week:SKILL                   0.8680    
## uv_intervention:t_week         0.0574 .  
## uv_intervention:SKILL          0.3018    
## uv_intervention:t_week:SKILL   0.1197    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) female urm    grd_bn uv_ntr t_week SKILL  t_:SKI uv_n:_
## female      -0.254                                                        
## urm         -0.426 -0.013                                                 
## grade_binry -0.335  0.030 -0.049                                          
## uv_intrvntn -0.522  0.007  0.037 -0.083                                   
## t_week      -0.371  0.004  0.010  0.018  0.303                            
## SKILL       -0.471  0.027  0.002  0.009  0.389  0.573                     
## t_wek:SKILL  0.311 -0.006 -0.005 -0.002 -0.259 -0.888 -0.641              
## uv_ntrvnt:_  0.255  0.011 -0.003 -0.003 -0.447 -0.712 -0.408  0.632       
## uv_nt:SKILL  0.306 -0.004  0.009  0.011 -0.576 -0.390 -0.680  0.436  0.603
## uv_:_:SKILL -0.205 -0.014  0.002 -0.001  0.377  0.604  0.436 -0.680 -0.884
##             u_:SKI
## female            
## urm               
## grade_binry       
## uv_intrvntn       
## t_week            
## SKILL             
## t_wek:SKILL       
## uv_ntrvnt:_       
## uv_nt:SKILL       
## uv_:_:SKILL -0.654
ranova(M1)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## INTEREST ~ female + urm + grade_binary + uv_intervention + t_week + 
##     SKILL + (1 | STUDID) + (1 | classroom) + t_week:SKILL + uv_intervention:t_week + 
##     uv_intervention:SKILL + uv_intervention:t_week:SKILL
##                 npar  logLik    AIC    LRT Df Pr(>Chisq)    
## <none>            14 -3572.0 7172.0                         
## (1 | STUDID)      13 -3798.6 7623.2 453.18  1  < 2.2e-16 ***
## (1 | classroom)   13 -3597.5 7220.9  50.88  1  9.809e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
sjstats::icc(M1)
## 
## Linear mixed model
## 
## Family : gaussian (identity)
## Formula: INTEREST ~ female + urm + grade_binary + uv_intervention + t_week + t_week * SKILL * uv_intervention + SKILL + (1 | STUDID) + (1 | classroom)
## 
##      ICC (STUDID): 0.2660
##   ICC (classroom): 0.0590
sjPlot::plot_model(M1, type = "int", swap.pred = FALSE)
## Warning in (function (object, newdata = NULL, newparams = NULL, re.form =
## NULL, : unused arguments ignored

#konfound::konfound(M33_33, female)
#M33_33r<-r2glmm::r2beta(M33_33, method = "nsj")
#M33_33r
#MuMIn::r.squaredGLMM(M33_33)

Predicting momentary boredom

M3 <- lmer(BORED ~ 
             female + 
             urm +
             grade_binary +
             uv_intervention +
             t_week +
             #t_week*uv_intervention +
             t_week*SKILL*uv_intervention +
             SKILL +
             (1|STUDID) + (1|classroom), data = imuscle_all)
summary(M3)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: BORED ~ female + urm + grade_binary + uv_intervention + t_week +  
##     t_week * SKILL * uv_intervention + SKILL + (1 | STUDID) +  
##     (1 | classroom)
##    Data: imuscle_all
## 
## REML criterion at convergence: 7807.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.81565 -0.64217 -0.07159  0.68149  2.95309 
## 
## Random effects:
##  Groups    Name        Variance Std.Dev.
##  STUDID    (Intercept) 0.40302  0.6348  
##  classroom (Intercept) 0.05301  0.2302  
##  Residual              0.83848  0.9157  
## Number of obs: 2722, groups:  STUDID, 292; classroom, 17
## 
## Fixed effects:
##                                Estimate Std. Error         df t value
## (Intercept)                   1.729e+00  1.673e-01  8.396e+01  10.332
## female                        1.176e-01  8.362e-02  2.819e+02   1.406
## urm                          -2.132e-01  1.008e-01  2.834e+02  -2.115
## grade_binary                  1.151e-01  1.467e-01  1.575e+01   0.785
## uv_intervention              -7.979e-02  1.909e-01  4.696e+01  -0.418
## t_week                       -4.221e-03  8.069e-03  2.428e+03  -0.523
## SKILL                        -1.767e-01  4.111e-02  2.658e+03  -4.297
## t_week:SKILL                  1.390e-03  3.614e-03  2.491e+03   0.385
## uv_intervention:t_week        7.081e-03  1.134e-02  2.495e+03   0.624
## uv_intervention:SKILL        -2.639e-02  6.049e-02  2.676e+03  -0.436
## uv_intervention:t_week:SKILL  3.867e-04  5.328e-03  2.507e+03   0.073
##                              Pr(>|t|)    
## (Intercept)                   < 2e-16 ***
## female                         0.1607    
## urm                            0.0353 *  
## grade_binary                   0.4444    
## uv_intervention                0.6778    
## t_week                         0.6010    
## SKILL                         1.8e-05 ***
## t_week:SKILL                   0.7006    
## uv_intervention:t_week         0.5324    
## uv_intervention:SKILL          0.6626    
## uv_intervention:t_week:SKILL   0.9421    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) female urm    grd_bn uv_ntr t_week SKILL  t_:SKI uv_n:_
## female      -0.276                                                        
## urm         -0.467 -0.014                                                 
## grade_binry -0.315  0.035 -0.059                                          
## uv_intrvntn -0.514  0.006  0.043 -0.081                                   
## t_week      -0.377  0.003  0.009  0.019  0.320                            
## SKILL       -0.483  0.025  0.002  0.011  0.413  0.572                     
## t_wek:SKILL  0.317 -0.005 -0.004 -0.003 -0.274 -0.889 -0.638              
## uv_ntrvnt:_  0.258  0.012 -0.003 -0.001 -0.474 -0.711 -0.406  0.632       
## uv_nt:SKILL  0.312 -0.001  0.009  0.013 -0.613 -0.388 -0.679  0.433  0.601
## uv_:_:SKILL -0.208 -0.015  0.001 -0.003  0.400  0.603  0.432 -0.678 -0.885
##             u_:SKI
## female            
## urm               
## grade_binry       
## uv_intrvntn       
## t_week            
## SKILL             
## t_wek:SKILL       
## uv_ntrvnt:_       
## uv_nt:SKILL       
## uv_:_:SKILL -0.650
ranova(M3)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## BORED ~ female + urm + grade_binary + uv_intervention + t_week + 
##     SKILL + (1 | STUDID) + (1 | classroom) + t_week:SKILL + uv_intervention:t_week + 
##     uv_intervention:SKILL + uv_intervention:t_week:SKILL
##                 npar  logLik    AIC    LRT Df Pr(>Chisq)    
## <none>            14 -3903.6 7835.2                         
## (1 | STUDID)      13 -4180.7 8387.5 554.25  1  < 2.2e-16 ***
## (1 | classroom)   13 -3915.0 7856.1  22.82  1  1.783e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
sjstats::icc(M3)
## 
## Linear mixed model
## 
## Family : gaussian (identity)
## Formula: BORED ~ female + urm + grade_binary + uv_intervention + t_week + t_week * SKILL * uv_intervention + SKILL + (1 | STUDID) + (1 | classroom)
## 
##      ICC (STUDID): 0.3113
##   ICC (classroom): 0.0409
sjPlot::plot_model(M3, type = "int", swap.pred = FALSE)
## Warning in (function (object, newdata = NULL, newparams = NULL, re.form =
## NULL, : unused arguments ignored

#konfound::konfound(M33_33, female)
#M33_33r<-r2glmm::r2beta(M33_33, method = "nsj")
#M33_33r
#MuMIn::r.squaredGLMM(M33_33)

Predicting post-interest

M2 <- lmer(interest3 ~ 
             female + 
             urm +
             grade_binary +
             uv_intervention +
             (1|classroom), data = imuscle_all)
summary(M2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: interest3 ~ female + urm + grade_binary + uv_intervention + (1 |  
##     classroom)
##    Data: imuscle_all
## 
## REML criterion at convergence: 9636.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.03393 -0.82010  0.09875  0.73611  2.73074 
## 
## Random effects:
##  Groups    Name        Variance Std.Dev.
##  classroom (Intercept) 0.3508   0.5923  
##  Residual              3.2335   1.7982  
## Number of obs: 2390, groups:  classroom, 17
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)        4.57237    0.24407   16.66091  18.734 1.26e-12 ***
## female            -0.38509    0.07474 2378.98346  -5.152 2.79e-07 ***
## urm               -0.79683    0.08829 2380.79556  -9.025  < 2e-16 ***
## grade_binary      -0.08791    0.31642   13.14210  -0.278    0.785    
## uv_intervention    0.14941    0.30871   13.33579   0.484    0.636    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) female urm    grd_bn
## female      -0.160                     
## urm         -0.278 -0.014              
## grade_binry -0.435  0.012 -0.018       
## uv_intrvntn -0.525  0.004  0.025 -0.091
ranova(M2)
## ANOVA-like table for random-effects: Single term deletions
## 
## Model:
## interest3 ~ female + urm + grade_binary + uv_intervention + (1 | 
##     classroom)
##                 npar  logLik    AIC    LRT Df Pr(>Chisq)    
## <none>             7 -4818.2 9650.4                         
## (1 | classroom)    6 -4894.8 9801.6 153.24  1  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#sjstats::icc(M1)
#sjPlot::plot_model(M1, type = "int", swap.pred = FALSE)
#konfound::konfound(M33_33, female)
#M33_33r<-r2glmm::r2beta(M33_33, method = "nsj")
#M33_33r
#MuMIn::r.squaredGLMM(M33_33)