fit_markov_mix {markovmix} | R Documentation |
Fit mixture of Markov chains
Description
fit_markov_mix
fits mixture of Markov chains. It supports high-order Markov chains,
multiple sequences and mixture components with cluster probabilities.
Usage
fit_markov_mix(
seq_list,
order. = 1L,
states = NULL,
clusters = NULL,
verbose = TRUE
)
Arguments
seq_list |
Sequence list containing vectors of the same class. |
order. |
Integer (1L) indicating the order of the Markov chain. |
states |
|
clusters |
|
verbose |
Logical (1L) indicating whether additional messages should be printed. |
Value
An object of class MarkovMix
.
Note
Change log:
0.1.0 Xiurui Zhu - Initiate the function.
Author(s)
Xiurui Zhu
Examples
# Generate a list of integer sequences of different lengths with 4 states
test_states <- seq_len(4L)
test_maxlen <- 10L
set.seed(1111L)
test_seq <- purrr::map(
seq_len(100L),
~ sample(test_states, sample.int(test_maxlen, 1L), replace = TRUE)
)
# Fit a 1-order Markov chain
markov_fit <- fit_markov_mix(
seq_list = test_seq,
order. = 1L,
states = test_states
)
print(markov_fit)
# Fit a mixture of 2-order Markov chain with 3 components
test_n_comp <- 3L
test_clusters <- matrix(
runif(length(test_seq) * test_n_comp),
nrow = length(test_seq),
ncol = test_n_comp
)
markov_mix_fit <- fit_markov_mix(
seq_list = test_seq,
order. = 2L,
states = test_states,
clusters = test_clusters
)
print(markov_mix_fit)