## ----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)

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

## ----fit-var-bayes------------------------------------------------------------
var_bayes_fit <- fit_var_bayes(
  srl, vars = vars, id = "name", subject = "Grace",
  n_iter = 1000, n_chains = 2, seed = 1
)
var_bayes_fit

## ----fit-mlvar-bayes----------------------------------------------------------
mlvar_bayes_fit <- fit_mlvar_bayes(
  srl, vars = vars, id = "name", temporal = "fixed",
  n_iter = 1000, n_chains = 2, seed = 1
)
mlvar_bayes_fit

## ----fit-mplus, eval=FALSE----------------------------------------------------
# mplus_fit <- fit_mlvar_mplus(
#   srl, vars = vars, id = "name",
#   temporal = "fixed", contemporaneous = "fixed"
# )

## ----output-var-bayes---------------------------------------------------------
summary(var_bayes_fit)
edges(var_bayes_fit, n = 12)
nodes(var_bayes_fit)
matrices(var_bayes_fit)

## ----output-mlvar-bayes-------------------------------------------------------
summary(mlvar_bayes_fit)
edges(mlvar_bayes_fit, n = 12)
nodes(mlvar_bayes_fit)
matrices(mlvar_bayes_fit)

## ----plot-var-bayes, eval=has_cograph-----------------------------------------
plot(var_bayes_fit)
plot(var_bayes_fit, layer = "temporal")
plot(var_bayes_fit, layer = "contemporaneous")

## ----plot-mlvar-bayes, eval=has_cograph---------------------------------------
plot(mlvar_bayes_fit)
plot(mlvar_bayes_fit, layer = "temporal")
plot(mlvar_bayes_fit, layer = "contemporaneous")
plot(mlvar_bayes_fit, layer = "between")

