transition_matrix: Calculate the transition matrix of states

Description Usage Arguments Value See Also Examples

Description

Calculate the transition rates between states. If cluster_labels are provided then transition rates are calculated by cluster.

Usage

1
2
3
4
5
6
transition_matrix(
  seq_def_tidy,
  period_min = min(seq_def_tidy$sequenchr_seq_id),
  period_max = max(seq_def_tidy$sequenchr_seq_id),
  cluster_labels = NULL
)

Arguments

seq_def_tidy

a tidy tibble generated from sequenchr::tidy_sequence_data

period_min

the minimum period to include in the transition calculation

period_max

the maxmium period to include in the transition calculation

cluster_labels

optional. A vector of cluster assignments

Value

a tidy tibble containing the transition rates (per cluster)

See Also

plot_transition_matrix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library(TraMineR)
data(mvad)
seqstatl(mvad[, 17:86])
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
                   "training")
mvad.labels <- c("employment", "further education", "higher education",
                 "joblessness", "school", "training")
mvad.seq <- seqdef(mvad, 17:86, alphabet = mvad.alphabet,
                   labels = mvad.labels, xtstep = 6)
seq_def_tidy <- tidy_sequence_data(mvad.seq)

trans_tidy <- transition_matrix(seq_def_tidy)

dist_matrix <- TraMineR::seqdist(seqdata = mvad.seq, method = "DHD")
cluster_model <- hclust(d = as.dist(dist_matrix), method = 'ward.D2')
cluster_labels <- stats::cutree(cluster_model, k = 5)

trans_tidy <- transition_matrix(seq_def_tidy, cluster_labels = cluster_labels)

joemarlo/sequenchr documentation built on Sept. 29, 2021, 12:23 a.m.