| mc_multinom | R Documentation |
Function that estimates Markov chain model with suitable constraints on the transition matrix.
mc_multinom(formula, data, baseline = c("initial", "central"),
model_int = c("all", "const", "dist1", "dist2", "dist3", "two",
"symm", "rsymm", "diff"),
model_cov = c("all", "const", "dist1", "dist2", "dist3", "two",
"symm", "rsymm", "diff"),
formula_init = NULL, reltol = 10^-10, output = FALSE)
formula |
A model formula specifying the response variable and the covariates affecting the transition probabilities. The response variable must be numeric, coded consecutively from |
data |
A balanced data frame in long format. The first two required variables are |
baseline |
Character string specifying the reference category in the multinomial logit parameterization for the transition probabilities. With |
model_int |
Character string specifying the constraint structure for the intercepts of the transition logits. See |
model_cov |
Character string specifying the constraint structure for the regression coefficients associated with the transition covariates. See |
formula_init |
Optional formula specifying the covariates affecting the initial probabilities. If |
reltol |
Positive numeric value specifying the relative convergence tolerance used in the Newton–Raphson iterations for the initial and transition components of the log-likelihood |
output |
Logical value. If |
The covariates are included in the model through model.matrix, so that factors are automatically coded by means of dummy variables and transformations of the covariates may be specified directly in the formula, as in I(age - 50) or I((age - 50)^2/100). The model always includes an intercept and only one response variable is allowed. Covariates affecting the initial probabilities are specified through the separate argument formula_init; when this is NULL, the covariates in formula are used for both the initial and the transition probabilities, whereas formula_init = y ~ 1 gives initial probabilities that do not depend on covariates.
An object of class "mc_multinom" containing the following components:
la |
Estimated regression coefficients for the initial probabilities |
psi |
Estimated reduced vector of regression coefficients for the constrained transition logits |
eta |
Expanded vector of transition-logit parameters obtained by applying the design-matrix constraints to |
lk |
Total log-likelihood, equal to the sum of the initial-probability and transition-probability log-likelihoods |
lk1 |
Log-likelihood contribution of the initial probabilities |
lk2 |
Log-likelihood contribution of the transition probabilities |
np |
Number of free model parameters |
aic |
Akaike Information Criterion |
bic |
Bayesian Information Criterion |
sela |
Standard errors of the estimated coefficients |
sepsi |
Standard errors of the estimated coefficients |
call |
Matched call used to fit the model |
Piv |
Matrix of subject-specific initial probabilities, with dimensions |
PI |
Array of subject-specific transition probabilities, with dimensions |
Francesco Bartolucci and Silvia Pandolfi, University of Perugia (IT), Luca Brusa and Fulvia Pennoni, University of Milano-Bicocca (IT)
Bartolucci, F., Pandolfi, S., and Pennoni, F. (2026). Parsimonious parametrizations of transition matrices of Markov chain and hidden Markov models, Annals of Operations Research, 363, 233–266.
## Not run:
data("data_SRHS_long")
srhs <- data_SRHS_long
# Covariates
srhs$gender <- factor(
srhs$gender,
levels = c(1, 2),
labels = c("male", "female")
)
srhs$race <- factor(
srhs$race,
levels = c(1, 2, 3),
labels = c("white", "black", "others")
)
srhs$education <- factor(
srhs$education,
levels = 1:5,
labels = c(
"high school",
"general educational diploma",
"high school graduate",
"some college",
"college and above"
)
)
srhs$age_c <- srhs$age - mean(srhs$age)
# 1 = poor, ..., 5 = excellent
srhs$srhs1 <- 6L - as.integer(srhs$srhs)
# Consecutive numeric identifiers and ordering by subject and time
srhs$id <- as.integer(factor(srhs$id))
srhs <- srhs[order(srhs$id, srhs$t), ]
# Select a small reproducible balanced sample for a fast example
set.seed(2026)
n_example <- 2000L
example_ids <- sample(unique(srhs$id), n_example)
srhs_example <- srhs[srhs$id %in% example_ids, , drop = FALSE]
srhs_example$id <- match(srhs_example$id, example_ids)
srhs_example <- srhs_example[order(srhs_example$id, srhs_example$t), ]
# Example 1: gender and age affect both initial and transition probabilities
mod_cov <- mc_multinom(
srhs1 ~ gender + age_c,
data = srhs_example,
baseline = "central",
model_int = "dist1",
model_cov = "dist1",
output = TRUE)
print(mod_cov)
summary(mod_cov)
# Average initial and transition probabilities
colMeans(mod_cov$Piv)
round(apply(mod_cov$PI[, , , 2:max(srhs_example$t)], c(1, 2), mean),3)
# Example 2: covariates affect transitions only
mod_trans <- mc_multinom(
srhs1 ~ gender + age_c,
data = srhs_example,
baseline = "central",
model_int = "dist1",
model_cov = "dist1",
formula_init = srhs1 ~ 1)
print(mod_trans)
summary(mod_trans)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.