--- title: "4. Subject-by-subject networks" output: rmarkdown::html_vignette: toc: true vignette: > %\VignetteIndexEntry{4. Subject-by-subject networks} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include=FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE, fig.width = 7, fig.height = 5.5 ) ``` ```{r libraries} library(idiographic) data(srl) vars <- c("efficacy", "value", "planning", "monitoring", "effort") has_cograph <- requireNamespace("cograph", quietly = TRUE) ``` When the analysis target is the **idiographic map for every individual**, fit one model per person with `build_var_each()` (OLS) or `graphical_var_each()` (regularized). Each returns a named collection of per-subject results. # One OLS VAR per person ```{r var-each} var_each <- build_var_each(srl, vars = vars, id = "name", scale = TRUE) var_each ``` The collection prints a one-line-per-cohort summary (subjects, variables, edge counts). Reach into one person's result by name and use the usual verbs on it: ```{r var-each-one} grace <- var_each[["Grace"]] head(edges(grace)) matrices(grace) ``` `plot()` draws a chosen subject directly — pass `subject` instead of indexing: ```{r plot-var-each, eval=has_cograph} plot(var_each, subject = "Grace") ``` # One graphical VAR per person `graphical_var_each()` does the same with sparse estimation. Here we fit a handful of students so the example runs quickly; drop the `subset()` to fit everyone. ```{r gvar-each} students <- subset(srl, name %in% c("Grace", "Eve", "Aisha", "Bob")) gvar_each <- graphical_var_each(students, vars = vars, id = "name", n_lambda = 8, gamma = 0) gvar_each summary(gvar_each[["Eve"]]) ``` ```{r plot-gvar-each, eval=has_cograph} plot(gvar_each, subject = "Eve") ```