extract_transition_matrix() returns the weight matrix of a network: for
a transition network, the transition probabilities or counts between
states, with rows as the states moved from and columns as the states
moved to. It reads a netobject (or any list with a weights element), a
tna, ftna, ctna or atna model, an mcml (one matrix per layer) or
a bare matrix, and can rescale the rows to sum to 1.
Arguments
- model
The network: a
netobject, atna-family model, anmcml, a list holding the matrix asweights(or, failing that,transition_matrixortransition), or a weight matrix. Anything else raises an error.- type
Which matrix to return.
"raw"(default) returns the weights as stored."scaled"divides each row by its sum, so the rows of a count matrix become transition probabilities; a row that sums to zero is left as it is.- x
For the
print()method: anest_transition_matrix.- ...
For the
summary()method: ignored. For theprint()method: passed on to the matrix print.- object
For the
summary()method: anest_transition_matrix.
Value
For a single network: a square numeric matrix with the model's
state names (if any) as row and column names, of class
c("nest_transition_matrix", "matrix", "array"). It behaves as an
ordinary matrix in arithmetic and indexing; summary()
returns a data frame with one row per non-zero entry (self-transitions
included) and the columns from, to and weight, sorted by
decreasing absolute weight.
For an mcml: a named list of such matrices, macro first and then
one per cluster.
Details
Models store their weights in different places; the function looks in
each in turn. "scaled" is useful when the stored weights are counts or
otherwise do not sum to 1 per row.
See also
extract_initial_probs for extracting initial probabilities,
extract_edges for extracting an edge list.
Examples
seqs <- data.frame(V1 = c("A","B","A"), V2 = c("B","A","C"), V3 = c("A","C","B"))
net <- build_network(seqs, method = "relative")
trans_mat <- extract_transition_matrix(net)
print(trans_mat)
#> A B C
#> A 0 0.3333333 0.6666667
#> B 1 0.0000000 0.0000000
#> C 0 1.0000000 0.0000000