Learn R Programming

LMest (version 3.1.2)

lmestMixed: Estimate mixed Latent Markov models

Description

Main function for estimating the mixed latent Markov (LM) models for categorical responses with discrete random effects in the latent model.

Usage

lmestMixed(responsesFormula = NULL,
           data, index, k1, k2, start = 0,
           weights = NULL, tol = 10^-8, maxit = 1000,
           out_se = FALSE, seed = NULL)

Value

Returns an object of class 'LMmixed' (see LMmixed-class).

Arguments

responsesFormula

a symbolic description of the model to fit. A detailed description is given in the ‘Details’ section

data

a data.frame in long format

index

a character vector with two elements, the first indicating the name of the unit identifier, and the second the time occasions

k1

number of latent classes

k2

number of latent states

start

type of starting values (0 = deterministic, 1 = random, 2 = initial values in input)

weights

an optional vector of weights for the available responses

tol

tolerance level for convergence

maxit

maximum number of iterations of the algorithm

out_se

to compute the information matrix and standard errors (FALSE is the default option)

seed

an integer value with the random number generator state

Author

Francesco Bartolucci, Silvia Pandolfi, Fulvia Pennoni, Alessio Farcomeni, Alessio Serafini

Details

The function lmestMixed estimates the mixed LM for categorical data. The function requires data in long format and two additional columns indicating the unit identifier and the time occasions.

responsesFormula is used to specify the responses of the mixed LM model:

  • responsesFormula = y1 + y2 ~ NULL
    the mixed LM model with two categorical responses (y1 and y2) is specified;

  • responsesFormula = NULL
    all the columns in the data except the "id" and "time" columns are used as responses to estimate the mixed LM.

Missing responses are not allowed.

References

Bartolucci F., Pandolfi S., Pennoni F. (2017) LMest: An R Package for Latent Markov Models for Longitudinal Categorical Data, Journal of Statistical Software, 81(4), 1-38.

Bartolucci, F., Farcomeni, A. and Pennoni, F. (2013) Latent Markov Models for Longitudinal Data, Chapman and Hall/CRC press.

Examples

Run this code
if (FALSE) {

# Example based on criminal data

data(data_criminal_sim)
data_criminal_sim <- data.frame(data_criminal_sim)

# Estimate mixed LM model for females

responsesFormula <- lmestFormula(data = data_criminal_sim,
                                 response = "y")$responsesFormula

# fit mixed LM model only for females
out <- lmestMixed(responsesFormula = responsesFormula,
                  index = c("id","time"),
                  k1 = 2,
                  k2 = 2,
                  data = data_criminal_sim[data_criminal_sim$sex == 2,])
out
summary(out)
}

Run the code above in your browser using DataLab