## ----options, include = FALSE-----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7,
                      fig.height = 4.5, fig.align = "center", dpi = 96)
old_options <- options(digits = 3, width = 90)

## ----setup------------------------------------------------------------------------------
library(transitiontrees)

## ----course-by-achievement--------------------------------------------------------------
xtabs(~ Course + Achiever, data = group_regulation_long)

## ----fit--------------------------------------------------------------------------------
grp <- context_tree(group_regulation_long,
                    actor = "Actor", time = "Time", action = "Action",
                    group = "Achiever", max_depth = 1, min_count = 10)
grp

## ----summary-group----------------------------------------------------------------------
summary(grp)

## ----frequencies------------------------------------------------------------------------
state_frequencies(grp)

## ----compare-trees----------------------------------------------------------------------
cmp <- compare_trees(grp, iter = 99)
summary(cmp)

## ----compare-trees-pathways-------------------------------------------------------------
as.data.frame(cmp, what = "pathways")

## ----compare-groups---------------------------------------------------------------------
cg <- compare_groups(grp, iter = 99)
summary(cg)

## ----omnibus----------------------------------------------------------------------------
as.data.frame(cg, what = "omnibus")
as.data.frame(cg, what = "distance")

## ----pathways---------------------------------------------------------------------------
as.data.frame(cg, what = "pathways")

## ----plot-difference, fig.width = 8, fig.height = 5-------------------------------------
plot_difference(grp, comparison = cg)

## ----fit-blocked------------------------------------------------------------------------
grp_course <- context_tree(group_regulation_long,
                           actor = "Actor", time = "Time", action = "Action",
                           group = "Achiever", block = "Course",
                           max_depth = 1, min_count = 10)
cg_course <- compare_groups(grp_course, iter = 99)
summary(cg_course)

## ----pathways-blocked-------------------------------------------------------------------
as.data.frame(cg_course, what = "pathways")

## ----restore-options, include = FALSE-----------------------------------------
options(old_options)

