knitr::clean_cache()
## NULL
# data <- params$data
targets::tar_load(esm_long)
data <- esm_long

library(brms)
## Loading required package: Rcpp
## Loading 'brms' package (version 2.14.4). Useful instructions
## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').
## 
## Attaching package: 'brms'
## The following object is masked from 'package:stats':
## 
##     ar
library(bayesplot)
## This is bayesplot version 1.8.0
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
##    * Does _not_ affect other ggplot2 plots
##    * See ?bayesplot_theme_set for details on theme setting
data$int_val_change <- data$int_val_post - data$int_val_pre

3. Just post - how do students’ momentary experiences relate to changes in their interest?

base model

bf_1 <- bf(frustrated ~ 1 +
             course + 
             (1|s|number) +
             (1|p|assign))

bf_2 <- bf(confident ~ 1 + 
             course + 
             (1|s|number) +
             (1|p|assign))

bf_3 <- bf(interested ~ 1 + 
             course + 
             (1|s|number) +
             (1|p|assign))

bf_int <- bf(int_val_post ~ course)

m3a_pre <- brm(bf_1 + bf_2 + bf_3 +
             bf_int,
           data = data, 
           chains = 4, cores = 4, iter = 1000, 
           control = list(max_treedepth = 20))
## Setting 'rescor' to TRUE by default for this model
## Warning: In the future, 'rescor' will be set to FALSE by default for all models.
## It is thus recommended to explicitely set 'rescor' via 'set_recor' instead of
## using the default.
## Warning: Rows containing NAs were excluded from the model.
## Compiling Stan program...
## Start sampling
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#tail-ess
m3a_pre
##  Family: MV(gaussian, gaussian, gaussian, gaussian) 
##   Links: mu = identity; sigma = identity
##          mu = identity; sigma = identity
##          mu = identity; sigma = identity
##          mu = identity; sigma = identity 
## Formula: frustrated ~ 1 + course + (1 | s | number) + (1 | p | assign) 
##          confident ~ 1 + course + (1 | s | number) + (1 | p | assign) 
##          interested ~ 1 + course + (1 | s | number) + (1 | p | assign) 
##          int_val_post ~ course 
##    Data: data (Number of observations: 776) 
## Samples: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup samples = 2000
## 
## Group-Level Effects: 
## ~assign (Number of levels: 25) 
##                                                Estimate Est.Error l-95% CI
## sd(frustrated_Intercept)                           0.33      0.06     0.23
## sd(confident_Intercept)                            0.19      0.04     0.12
## sd(interested_Intercept)                           0.15      0.03     0.10
## cor(frustrated_Intercept,confident_Intercept)     -0.88      0.10    -0.99
## cor(frustrated_Intercept,interested_Intercept)    -0.88      0.10    -0.99
## cor(confident_Intercept,interested_Intercept)      0.93      0.07     0.73
##                                                u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(frustrated_Intercept)                           0.47 1.01      568     1000
## sd(confident_Intercept)                            0.28 1.00      676     1106
## sd(interested_Intercept)                           0.22 1.00      677      971
## cor(frustrated_Intercept,confident_Intercept)     -0.61 1.01      559     1028
## cor(frustrated_Intercept,interested_Intercept)    -0.61 1.00      904     1172
## cor(confident_Intercept,interested_Intercept)      1.00 1.00     1421     1734
## 
## ~number (Number of levels: 65) 
##                                                Estimate Est.Error l-95% CI
## sd(frustrated_Intercept)                           1.01      0.10     0.83
## sd(confident_Intercept)                            0.73      0.07     0.60
## sd(interested_Intercept)                           0.57      0.06     0.47
## cor(frustrated_Intercept,confident_Intercept)     -0.56      0.09    -0.73
## cor(frustrated_Intercept,interested_Intercept)    -0.11      0.13    -0.34
## cor(confident_Intercept,interested_Intercept)      0.48      0.11     0.24
##                                                u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(frustrated_Intercept)                           1.22 1.01      253      328
## sd(confident_Intercept)                            0.90 1.00      356      632
## sd(interested_Intercept)                           0.69 1.00      358      593
## cor(frustrated_Intercept,confident_Intercept)     -0.36 1.01      312      555
## cor(frustrated_Intercept,interested_Intercept)     0.15 1.02      362      508
## cor(confident_Intercept,interested_Intercept)      0.66 1.01      376      753
## 
## Population-Level Effects: 
##                          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## frustrated_Intercept         2.56      0.16     2.26     2.87 1.02      170
## confident_Intercept          4.15      0.11     3.94     4.37 1.03      243
## interested_Intercept         4.35      0.08     4.17     4.51 1.02      329
## intvalpost_Intercept         1.18      0.04     1.10     1.26 1.00     2800
## frustrated_courseCOSC111     0.41      0.43    -0.44     1.28 1.02      348
## confident_courseCOSC111     -0.55      0.32    -1.23     0.09 1.02      324
## interested_courseCOSC111    -0.56      0.26    -1.08    -0.06 1.01      457
## intvalpost_courseCOSC111    -0.73      0.14    -1.00    -0.46 1.00     2707
##                          Tail_ESS
## frustrated_Intercept          325
## confident_Intercept           572
## interested_Intercept          551
## intvalpost_Intercept         1524
## frustrated_courseCOSC111      626
## confident_courseCOSC111       738
## interested_courseCOSC111      765
## intvalpost_courseCOSC111     1576
## 
## Family Specific Parameters: 
##                  Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma_frustrated     0.81      0.05     0.73     0.91 1.01      286      506
## sigma_confident      0.73      0.05     0.64     0.84 1.02      242      530
## sigma_interested     0.69      0.05     0.59     0.80 1.02      366      774
## sigma_intvalpost     1.11      0.03     1.05     1.16 1.00     2524     1440
## 
## Residual Correlations: 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## rescor(frustrated,confident)     -0.40      0.07    -0.54    -0.25 1.01
## rescor(frustrated,interested)    -0.33      0.09    -0.49    -0.13 1.01
## rescor(confident,interested)      0.59      0.06     0.47     0.70 1.02
## rescor(frustrated,intvalpost)    -0.37      0.13    -0.59    -0.09 1.01
## rescor(confident,intvalpost)      0.54      0.09     0.33     0.69 1.02
## rescor(interested,intvalpost)     0.71      0.05     0.59     0.79 1.02
##                               Bulk_ESS Tail_ESS
## rescor(frustrated,confident)       265      419
## rescor(frustrated,interested)      262      424
## rescor(confident,interested)       265      345
## rescor(frustrated,intvalpost)      224      424
## rescor(confident,intvalpost)       244      508
## rescor(interested,intvalpost)      360      764
## 
## Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

adding gender and pre self-efficacy

bf_1 <- bf(frustrated ~ 1 +
             gender + 
             course + 
             self_eff + 
             (1|s|number) +
             (1|p|assign))

bf_2 <- bf(confident ~ 1 + 
             gender + 
             course + 
             self_eff + 
             (1|s|number) +
             (1|p|assign))

bf_3 <- bf(interested ~ 1 + 
             gender + 
             course + 
             self_eff + 
             (1|s|number) +
             (1|p|assign))

bf_int <- bf(int_val_post ~ course + gender + self_eff)

m3e_pre <- brm(bf_1 + bf_2 + bf_3 +
             bf_int,
           data = data, 
           chains = 4, cores = 4, iter = 1000, 
           control = list(max_treedepth = 20))
## Setting 'rescor' to TRUE by default for this model
## Warning: In the future, 'rescor' will be set to FALSE by default for all models.
## It is thus recommended to explicitely set 'rescor' via 'set_recor' instead of
## using the default.
## Warning: Rows containing NAs were excluded from the model.
## Compiling Stan program...
## recompiling to avoid crashing R session
## Start sampling
## Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#bulk-ess
## Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## http://mc-stan.org/misc/warnings.html#tail-ess
m3e_pre
##  Family: MV(gaussian, gaussian, gaussian, gaussian) 
##   Links: mu = identity; sigma = identity
##          mu = identity; sigma = identity
##          mu = identity; sigma = identity
##          mu = identity; sigma = identity 
## Formula: frustrated ~ 1 + gender + course + self_eff + (1 | s | number) + (1 | p | assign) 
##          confident ~ 1 + gender + course + self_eff + (1 | s | number) + (1 | p | assign) 
##          interested ~ 1 + gender + course + self_eff + (1 | s | number) + (1 | p | assign) 
##          int_val_post ~ course + gender + self_eff 
##    Data: data (Number of observations: 770) 
## Samples: 4 chains, each with iter = 1000; warmup = 500; thin = 1;
##          total post-warmup samples = 2000
## 
## Group-Level Effects: 
## ~assign (Number of levels: 25) 
##                                                Estimate Est.Error l-95% CI
## sd(frustrated_Intercept)                           0.33      0.06     0.23
## sd(confident_Intercept)                            0.19      0.04     0.12
## sd(interested_Intercept)                           0.15      0.03     0.10
## cor(frustrated_Intercept,confident_Intercept)     -0.86      0.10    -0.99
## cor(frustrated_Intercept,interested_Intercept)    -0.88      0.10    -0.99
## cor(confident_Intercept,interested_Intercept)      0.93      0.07     0.75
##                                                u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(frustrated_Intercept)                           0.47 1.00      518      993
## sd(confident_Intercept)                            0.28 1.00      667     1176
## sd(interested_Intercept)                           0.22 1.00      666     1232
## cor(frustrated_Intercept,confident_Intercept)     -0.59 1.01      510     1120
## cor(frustrated_Intercept,interested_Intercept)    -0.62 1.00      696      920
## cor(confident_Intercept,interested_Intercept)      1.00 1.00     1130     1498
## 
## ~number (Number of levels: 64) 
##                                                Estimate Est.Error l-95% CI
## sd(frustrated_Intercept)                           0.96      0.10     0.79
## sd(confident_Intercept)                            0.63      0.07     0.52
## sd(interested_Intercept)                           0.57      0.06     0.46
## cor(frustrated_Intercept,confident_Intercept)     -0.45      0.11    -0.63
## cor(frustrated_Intercept,interested_Intercept)    -0.09      0.13    -0.33
## cor(confident_Intercept,interested_Intercept)      0.53      0.11     0.30
##                                                u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(frustrated_Intercept)                           1.17 1.00      352      626
## sd(confident_Intercept)                            0.77 1.00      477      908
## sd(interested_Intercept)                           0.70 1.01      517      859
## cor(frustrated_Intercept,confident_Intercept)     -0.21 1.00      398      620
## cor(frustrated_Intercept,interested_Intercept)     0.18 1.01      357      553
## cor(confident_Intercept,interested_Intercept)      0.72 1.01      377      772
## 
## Population-Level Effects: 
##                          Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## frustrated_Intercept         3.11      0.25     2.63     3.59 1.01      312
## confident_Intercept          3.57      0.16     3.27     3.89 1.01      462
## interested_Intercept         4.05      0.15     3.76     4.33 1.00      447
## intvalpost_Intercept         0.79      0.07     0.65     0.93 1.00     2649
## frustrated_genderMale       -0.17      0.31    -0.76     0.44 1.01      318
## frustrated_courseCOSC111     0.34      0.44    -0.47     1.24 1.00      545
## frustrated_self_eff         -0.56      0.16    -0.87    -0.26 1.01      326
## confident_genderMale         0.25      0.21    -0.16     0.66 1.00      338
## confident_courseCOSC111     -0.45      0.30    -1.03     0.17 1.00      428
## confident_self_eff           0.53      0.11     0.32     0.73 1.00      332
## interested_genderMale        0.25      0.19    -0.10     0.63 1.01      389
## interested_courseCOSC111    -0.40      0.27    -0.94     0.12 1.00      479
## interested_self_eff          0.16      0.10    -0.03     0.34 1.01      394
## intvalpost_courseCOSC111    -0.48      0.14    -0.75    -0.21 1.00     2254
## intvalpost_genderMale        0.10      0.09    -0.08     0.29 1.00     2066
## intvalpost_self_eff          0.43      0.05     0.34     0.53 1.00     2282
##                          Tail_ESS
## frustrated_Intercept          539
## confident_Intercept           697
## interested_Intercept          760
## intvalpost_Intercept         1472
## frustrated_genderMale         505
## frustrated_courseCOSC111      813
## frustrated_self_eff           515
## confident_genderMale          390
## confident_courseCOSC111       724
## confident_self_eff            582
## interested_genderMale         459
## interested_courseCOSC111      585
## interested_self_eff           898
## intvalpost_courseCOSC111     1245
## intvalpost_genderMale        1621
## intvalpost_self_eff          1654
## 
## Family Specific Parameters: 
##                  Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma_frustrated     0.76      0.03     0.71     0.84 1.01      306      350
## sigma_confident      0.66      0.03     0.60     0.73 1.01      324      588
## sigma_interested     0.67      0.05     0.57     0.77 1.01      316      555
## sigma_intvalpost     1.01      0.03     0.96     1.07 1.00     2916     1499
## 
## Residual Correlations: 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## rescor(frustrated,confident)     -0.29      0.06    -0.42    -0.18 1.01
## rescor(frustrated,interested)    -0.20      0.10    -0.39     0.01 1.02
## rescor(confident,interested)      0.50      0.07     0.36     0.62 1.01
## rescor(frustrated,intvalpost)    -0.19      0.15    -0.46     0.10 1.02
## rescor(confident,intvalpost)      0.36      0.11     0.14     0.56 1.01
## rescor(interested,intvalpost)     0.68      0.06     0.54     0.78 1.01
##                               Bulk_ESS Tail_ESS
## rescor(frustrated,confident)       240      314
## rescor(frustrated,interested)      210      318
## rescor(confident,interested)       298      658
## rescor(frustrated,intvalpost)      210      304
## rescor(confident,intvalpost)       285      629
## rescor(interested,intvalpost)      302      604
## 
## Samples were drawn using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).