## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE,
  fig.width = 7, fig.height = 5.5
)
library(idiographic)
data(srl)
has_cograph <- requireNamespace("cograph", quietly = TRUE)
# fit_mlvar(estimator = "lmer") needs lme4, which is only Suggested.
# Every chunk that fits or inspects the model is gated on it so the
# vignette still builds where lme4 is unavailable (CRAN's noSuggests
# check flavour, for one).
has_lme4 <- requireNamespace("lme4", quietly = TRUE)

## ----vars-audit---------------------------------------------------------------
vars <- c("efficacy", "value", "planning", "monitoring", "effort")
preprocess(srl, vars = vars, id = "name", min_obs = 100)

## ----fit, eval=has_lme4-------------------------------------------------------
mlvar_fit <- fit_mlvar(
  srl, vars = vars, id = "name",
  estimator = "lmer", temporal = "fixed", contemporaneous = "fixed",
  AR = FALSE
)
mlvar_fit

## ----summary, eval=has_lme4---------------------------------------------------
summary(mlvar_fit)

## ----edges-temporal, eval=has_lme4--------------------------------------------
edges(mlvar_fit, network = "temporal", n = 5)

## ----edges-contemporaneous, eval=has_lme4-------------------------------------
edges(mlvar_fit, network = "contemporaneous", n = 5)

## ----edges-between, eval=has_lme4---------------------------------------------
edges(mlvar_fit, network = "between", n = 5)

## ----nodes, eval=has_lme4-----------------------------------------------------
nodes(mlvar_fit)

## ----matrices, eval=has_lme4--------------------------------------------------
matrices(mlvar_fit)

## ----plot-all, eval=has_cograph && has_lme4-----------------------------------
plot(mlvar_fit)

## ----plot-temporal, eval=has_cograph && has_lme4------------------------------
plot(mlvar_fit, layer = "temporal")

## ----plot-contemporaneous, eval=has_cograph && has_lme4-----------------------
plot(mlvar_fit, layer = "contemporaneous")

## ----plot-mixed, eval=has_cograph && has_lme4---------------------------------
plot(mlvar_fit, mixed = TRUE)

## ----plot-between, eval=has_cograph && has_lme4-------------------------------
plot(mlvar_fit, layer = "between")

