## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 8, fig.height = 5, out.width = "100%") ## ----setup-------------------------------------------------------------------- library(transitiontrees) data(trajectories) set.seed(1) tree <- context_tree(trajectories, max_depth = 3L, min_count = 5L) pruned <- prune_tree(tree, criterion = "G2", alpha = 0.05) pruned ## ----horizontal, fig.width = 14, fig.height = 8------------------------------- plot(pruned, style = "horizontal") ## ----horizontal-sized, fig.width = 14, fig.height = 8------------------------- plot(pruned, style = "horizontal", point_size_range = c(3, 12), edge_size_range = c(0.4, 3.5)) ## ----dendrogram, fig.height = 6----------------------------------------------- plot(pruned, style = "dendrogram") ## ----icicle, fig.height = 6--------------------------------------------------- plot(pruned, style = "icicle") ## ----heatmap-count, fig.height = 5.5------------------------------------------ plot_pathways(pruned, top = 12, sort_by = "count") # the highways ## ----heatmap-div, fig.height = 5.5-------------------------------------------- plot_pathways(pruned, top = 12, sort_by = "divergence") # the informative ones ## ----divergence, fig.height = 5----------------------------------------------- plot_divergence(pruned, top = 12, min_count = 5) ## ----distributions, fig.height = 5.5------------------------------------------ plot_distributions(pruned, top = 6) ## ----pruning, fig.width = 9, fig.height = 4.5--------------------------------- plot_pruning(tree, "Active -> Active -> Average") ## ----predictive-logloss, fig.height = 4.5------------------------------------- plot_predictive(pruned, trajectories, type = "logloss") ## ----predictive-ecdf, fig.height = 4.5---------------------------------------- plot_predictive(pruned, trajectories, type = "ecdf") ## ----traj-fit----------------------------------------------------------------- data(ai_long) tree_ai <- context_tree(ai_long, actor = "project", session = "session_id", action = "code", max_depth = 3L, min_count = 10L) pruned_ai <- prune_tree(tree_ai) ## ----traj-freq, fig.width = 11, fig.height = 7-------------------------------- plot_trajectories(tree_ai, measure = "frequency", min_count = 20L) ## ----traj-pred, fig.width = 11, fig.height = 7-------------------------------- plot_trajectories(pruned_ai, measure = "predictability", min_count = 20L) ## ----boot-plot, fig.height = 5.5---------------------------------------------- boot <- bootstrap_pathways(pruned, iter = 100L, seed = 1L) plot(boot) ## ----boot-resamples, fig.height = 4.5----------------------------------------- plot_pathway_resamples(boot, stat = "divergence", top = 6) ## ----compare-plot, fig.height = 4.5------------------------------------------- data(group_regulation_long) grp_reg <- context_tree(group_regulation_long, actor = "Actor", time = "Time", action = "Action", group = "Achiever", max_depth = 2L, min_count = 10L) cmp <- compare_trees(prune_tree(grp_reg), iter = 199L, seed = 1L) plot(cmp) ## ----tune-plot, fig.height = 5------------------------------------------------ tg <- tune_tree(trajectories, max_depth = 1L:4L, folds = 5L, seed = 1L) plot(tg) ## ----difference, fig.height = 5----------------------------------------------- plot_difference(grp_reg, depth = 1L)