## ----setup, include = FALSE---------------------------------------------------
has_tna <- requireNamespace("tna", quietly = TRUE)
has_cograph <- requireNamespace("cograph", quietly = TRUE)
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7,
                      fig.height = 6, warning = FALSE, message = FALSE,
                      eval = has_tna)
library(psychnets)
if (has_tna) {
  data("group_regulation_long", package = "tna")
  event_log <- data.frame(group_regulation_long)
}

## ----data-preview-------------------------------------------------------------
head(event_log)

## ----fit-actor-network--------------------------------------------------------
actor_net <- psychnet(data = event_log, actor = "Actor")
actor_net

## ----summarize-actor-network--------------------------------------------------
summary(actor_net)

## ----certify-actor-network----------------------------------------------------
certificate(actor_net)

## ----plot-actor-network, eval = has_tna && has_cograph------------------------
cograph::splot(actor_net, psych_styling = TRUE)

## ----fit-group-networks-------------------------------------------------------
achievement_nets <- psychnet(data = event_log, actor = "Actor", group = "Achiever")
achievement_nets

## ----summarize-group-networks-------------------------------------------------
summary(achievement_nets)

## ----group-centrality---------------------------------------------------------
net_centralities(achievement_nets)

## ----plot-group-networks, eval = has_tna && has_cograph, fig.width = 11, fig.height = 5.5----
cograph::splot(achievement_nets, psych_styling = TRUE)

## ----fit-within-network-------------------------------------------------------
within_net <- psychnet(data = event_log, actor = "Actor", time = "Time", time_threshold = 300)
within_net

## ----summarize-within-network-------------------------------------------------
summary(within_net)

## ----certify-within-network---------------------------------------------------
certificate(within_net)

## ----plot-within-network, eval = has_tna && has_cograph-----------------------
cograph::splot(within_net, psych_styling = TRUE)

## ----fit-multilevel-networks--------------------------------------------------
multilevel_nets <- psychnet(data = event_log, actor = "Actor", time = "Time", time_threshold = 300, standardize = FALSE)
multilevel_nets

## ----plot-multilevel-networks, eval = has_tna && has_cograph, fig.width = 11, fig.height = 5.5----
cograph::splot(multilevel_nets, psych_styling = TRUE)

