R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(mlVAR)
## Warning: package 'mlVAR' was built under R version 4.4.3
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

Including Plots

You can also embed plots, for example:

## Estimating temporal and between-subjects effects
##   |                                                                              |                                                                      |   0%  |                                                                              |==============                                                        |  20%  |                                                                              |============================                                          |  40%  |                                                                              |==========================================                            |  60%  |                                                                              |========================================================              |  80%  |                                                                              |======================================================================| 100%
## Warning in lmer_mlVAR(PredModel, augData, idvar, verbose = verbose,
## contemporaneous = contemporaneous, : Zero SD found in mean of following
## variables: suppression - Between-subject effects could not be estimated
## Estimating contemporaneous effects
##   |                                                                              |                                                                      |   0%  |                                                                              |==============                                                        |  20%  |                                                                              |============================                                          |  40%  |                                                                              |==========================================                            |  60%  |                                                                              |========================================================              |  80%  |                                                                              |======================================================================| 100%
## Computing random effects
##   |                                                                              |                                                                      |   0%  |                                                                              |====                                                                  |   6%  |                                                                              |========                                                              |  11%  |                                                                              |============                                                          |  17%  |                                                                              |================                                                      |  22%  |                                                                              |===================                                                   |  28%  |                                                                              |=======================                                               |  33%  |                                                                              |===========================                                           |  39%  |                                                                              |===============================                                       |  44%  |                                                                              |===================================                                   |  50%  |                                                                              |=======================================                               |  56%  |                                                                              |===========================================                           |  61%  |                                                                              |===============================================                       |  67%  |                                                                              |===================================================                   |  72%  |                                                                              |======================================================                |  78%  |                                                                              |==========================================================            |  83%  |                                                                              |==============================================================        |  89%  |                                                                              |==================================================================    |  94%  |                                                                              |======================================================================| 100%
## List of 7
##  $ results:List of 6
##   ..$ mu            :List of 7
##   .. ..- attr(*, "class")= chr [1:2] "mlVARarray" "list"
##   ..$ Gamma_Omega_mu:List of 6
##   .. ..- attr(*, "class")= chr [1:2] "mlVARarray" "list"
##   ..$ Omega_mu      :List of 4
##   .. ..- attr(*, "class")= chr [1:2] "mlVarCov" "list"
##   ..$ Beta          :List of 7
##   .. ..- attr(*, "class")= chr [1:2] "mlVARarray" "list"
##   ..$ Theta         :List of 4
##   .. ..- attr(*, "class")= chr [1:2] "mlVarCov" "list"
##   ..$ Gamma_Theta   :List of 7
##   .. ..- attr(*, "class")= chr [1:2] "mlVARarray" "list"
##  $ output :List of 2
##   ..$ temporal       :List of 5
##   ..$ contemporaneous:List of 5
##  $ fit    :'data.frame': 5 obs. of  3 variables:
##   ..$ var: chr [1:5] "cortisol" "affect_neg" "stress" "reappraisal" ...
##   ..$ aic: num [1:5] 1287 1331 1372 1399 1464
##   ..$ bic: num [1:5] 1422 1466 1508 1535 1600
##  $ data   : tibble [504 × 18] (S3: tbl_df/tbl/data.frame)
##   ..- attr(*, "na.action")= 'omit' Named int [1:126] 1 6 11 16 21 26 31 36 41 46 ...
##   .. ..- attr(*, "names")= chr [1:126] "1" "6" "11" "16" ...
##  $ model  :'data.frame': 45 obs. of  5 variables:
##   ..$ dep   : chr [1:45] "cortisol" "affect_neg" "stress" "reappraisal" ...
##   ..$ pred  : chr [1:45] "cortisol" "cortisol" "cortisol" "cortisol" ...
##   ..$ lag   : num [1:45] 1 1 1 1 1 1 1 1 1 1 ...
##   ..$ type  : chr [1:45] "within" "within" "within" "within" ...
##   ..$ predID: chr [1:45] "Predictor__1" "Predictor__1" "Predictor__1" "Predictor__1" ...
##   ..- attr(*, "out.attrs")=List of 2
##  $ input  :List of 6
##   ..$ vars         : chr [1:5] "cortisol" "affect_neg" "stress" "reappraisal" ...
##   ..$ lags         : num 1
##   ..$ compareToLags: num 1
##   ..$ estimator    : chr "lmer"
##   ..$ temporal     : chr "correlated"
##   ..$ AR           : logi FALSE
##  $ IDs    : chr [1:18] "1" "2" "3" "4" ...
##  - attr(*, "class")= chr "mlVAR"
## [1] "mean"    "SD"      "lower"   "upper"   "SE"      "P"       "subject"
## NULL
## List of 7
##  $ mean   : num [1:5, 1:5, 1] -0.0353 0.0552 0.025 -0.1036 0.069 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ SD     : num [1:5, 1:5, 1] 0.106 0.183 0.199 0.114 0.226 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ lower  : num [1:5, 1:5, 1] -0.1366 -0.0704 -0.1088 -0.216 -0.0802 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ upper  : num [1:5, 1:5, 1] 0.06601 0.18082 0.15892 0.00867 0.21818 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ SE     : num [1:5, 1:5, 1] 0.0517 0.0641 0.0683 0.0573 0.0761 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ P      : num [1:5, 1:5, 1] 0.4945 0.3891 0.714 0.0705 0.3645 ...
##   ..- attr(*, "dimnames")=List of 3
##  $ subject:List of 18
##   ..$ : num [1:5, 1:5, 1] 0.0554 0.0231 -0.0884 -0.111 0.0778 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.04657 -0.10753 -0.25466 0.00448 -0.32942 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0134 0.1691 0.2338 -0.0863 0.1906 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0612 0.2116 0.2004 -0.0218 0.1656 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.127425 0.005682 -0.091337 -0.089221 0.000761 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] 0.0444 -0.1526 -0.1426 -0.0266 0.1583 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.08062 0.02278 0.00364 -0.09773 0.0794 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] 0.00151 -0.0713 -0.1804 -0.14489 -0.04422 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0051 0.0927 0.1218 -0.1524 0.1938 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0333 0.2613 0.0631 -0.233 0.1808 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.1118 0.1459 0.1684 -0.0693 0.2324 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0135 0.1968 0.0801 -0.1976 0.2985 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0831 0.2405 0.1348 -0.0821 0.0148 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] 0.0539 -0.1236 0.0461 -0.2495 0.251 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0522 -0.0809 -0.057 -0.059 -0.0338 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.0915 0.2478 0.2735 -0.0869 0.1286 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] 0.0312 -0.1731 -0.1234 -0.0761 -0.2114 ...
##   .. ..- attr(*, "dimnames")=List of 3
##   ..$ : num [1:5, 1:5, 1] -0.1022 0.0854 0.0629 -0.0868 -0.1114 ...
##   .. ..- attr(*, "dimnames")=List of 3
##  - attr(*, "class")= chr [1:2] "mlVARarray" "list"
## , , 1
## 
##                cortisol  affect_neg       stress reappraisal  suppression
## cortisol    -0.03531390  0.04903194 -0.029656760 -0.05159609  0.024678910
## affect_neg   0.05520219  0.07842568 -0.009902418 -0.10545789  0.089683186
## stress       0.02503876  0.08001153 -0.059000336 -0.07968394  0.066050348
## reappraisal -0.10364378 -0.24789123  0.082064474  0.24699320 -0.018424159
## suppression  0.06901249  0.18675764 -0.069893819 -0.13207991  0.007014656
## Warning: package 'qgraph' was built under R version 4.4.3
##  num [1:5, 1:5, 1] -0.0353 0.0552 0.025 -0.1036 0.069 ...
##  - attr(*, "dimnames")=List of 3
##   ..$ : chr [1:5] "cortisol" "affect_neg" "stress" "reappraisal" ...
##   ..$ : chr [1:5] "cortisol" "affect_neg" "stress" "reappraisal" ...
##   ..$ : chr "1"
##                cortisol  affect_neg       stress reappraisal  suppression
## cortisol    -0.03531390  0.04903194 -0.029656760 -0.05159609  0.024678910
## affect_neg   0.05520219  0.07842568 -0.009902418 -0.10545789  0.089683186
## stress       0.02503876  0.08001153 -0.059000336 -0.07968394  0.066050348
## reappraisal -0.10364378 -0.24789123  0.082064474  0.24699320 -0.018424159
## suppression  0.06901249  0.18675764 -0.069893819 -0.13207991  0.007014656

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

time_labels <- paste0(rep(vars, each = 6), "_t", rep(1:6, times = length(vars)))

# Make block structure: variables at t predict variables at t+1
p <- length(vars)
Tsteps <- 6
bigmat <- matrix(0, p * Tsteps, p * Tsteps)
for (t in 1:(Tsteps - 1)) {
  rows <- ((t - 1) * p + 1):(t * p)
  cols <- (t * p + 1):((t + 1) * p)
  bigmat[rows, cols] <- temporal_matrix
}
rownames(bigmat) <- colnames(bigmat) <- time_labels

qgraph(bigmat,
       layout = "circle",
       theme = "colorblind",
       target = "cortisol_t6",
       labels = time_labels,
       title = "Temporal Dynamics Across 6 Timepoints")
## Warning in qgraph(bigmat, layout = "circle", theme = "colorblind", target =
## "cortisol_t6", : The following arguments are not documented and likely not
## arguments of qgraph and thus ignored: target