## ----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)
vars <- c("efficacy", "value", "planning", "monitoring", "effort")
has_cograph <- requireNamespace("cograph", quietly = TRUE)
has_lavaan <- requireNamespace("lavaan", quietly = TRUE)
can_fit_usem <- has_lavaan && !is.na(parallel::detectCores())

## ----audit--------------------------------------------------------------------
preprocess(srl, vars = vars, id = "name", subject = "Grace")

## ----fit, eval=can_fit_usem---------------------------------------------------
usem_fit <- fit_usem(srl, vars = vars, id = "name", time = "day",
                     subject = "Grace", temporal = "all",
                     contemporaneous = "all", trim = TRUE)
usem_fit

## ----summary, eval=can_fit_usem-----------------------------------------------
summary(usem_fit)

## ----edges-temporal, eval=can_fit_usem----------------------------------------
edges(usem_fit, network = "temporal", n = 5)

## ----edges-contemp, eval=can_fit_usem-----------------------------------------
edges(usem_fit, network = "contemporaneous", n = 5)

## ----nodes, eval=can_fit_usem-------------------------------------------------
nodes(usem_fit)

## ----matrices, eval=can_fit_usem----------------------------------------------
matrices(usem_fit)

## ----plot-contemporaneous, eval=can_fit_usem && has_cograph-------------------
plot(usem_fit, layer = "contemporaneous")

## ----plot-mixed, eval=can_fit_usem && has_cograph-----------------------------
plot(usem_fit, mixed = TRUE)

