Learn R Programming

LMest (version 3.1.2)

lmestCont: Estimate Latent Markov models for continuous responses

Description

Main function for estimating Latent Markov (LM) models for continuous responses.

Usage

lmestCont(responsesFormula = NULL, latentFormula = NULL,
          data, index, k = 1:4, start = 0,
          modSel = c("BIC", "AIC"), modBasic = 0,
          paramLatent = c("multilogit", "difflogit"),
          weights = NULL, tol = 10^-10,
          maxit = 5000, out_se = FALSE, output = FALSE,
          parInit = list(piv = NULL, Pi = NULL,
                         Mu = NULL, Si = NULL,
                         Be = NULL, Ga = NULL),
           fort = TRUE, seed = NULL, ntry = 0, miss.imp = FALSE)

Value

Returns an object of class 'LMbasiccont' for the model without covariates (see LMbasiccont-class), an object of class 'LMlatentcont' for the model with covariates on the latent model (see LMlatentcont-class), or an object of class 'LMmanifestcont' for the model with covariates on the measurement model (see LMmanifestcont-class)).

Arguments

responsesFormula

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

latentFormula

a symbolic description of the model to be fitted. 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

k

an integer vector specifying the number of latent states (default: 1:4)

start

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

modSel

a string indicating the model selection criteria: "BIC" for Bayesian Information Criterion and "AIC" for Akaike Information Criterion Criterion

modBasic

model on the transition probabilities (0 for time-heter., 1 for time-homog., from 2 to (TT-1) partial homog. of that order)

paramLatent

type of parametrization for the transition probabilities ("multilogit" = standard multinomial logit for every row of the transition matrix, "difflogit" = multinomial logit based on the difference between two sets of parameters)

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 (By default is set to FALSE)

output

to return additional output (V, Ul, Pmarg) (LMbasiccont-class,LMlatentcont-class,LMmanifestcont-class)

parInit

list of initial model parameters when "start = 2". For the list of parameters look at LMbasiccont-class, LMlatentcont-class, and LMmanifestcont-class

fort

to use fortran routines when possible (By default is set to TRUE)

seed

an integer value with the random number generator state

ntry

to set the number of random initializations

miss.imp

how to deal with missing values (TRUE for imputation through the imp.mix function, FALSE for missing at random assumption)

Author

Francesco Bartolucci, Silvia Pandolfi, Fulvia Pennoni

Details

The function lmestCont is a general function for estimating LM models for continuous responses. The function requires data in long format and two additional columns indicating the unit identifier and the time occasions.

Covariates are allowed on the initial and transition probabilities (latent model). Two different formulas are employed to specify the different LM models, responsesFormula and latentFormula:

  • responsesFormula is used to specify the measurament model:

    • responsesFormula = y1 + y2 ~ NULL
      the LM model without covariates and two 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 LM model without covariates;

    • responsesFormula = y1 + y2 ~ x1 + x2
      the LM model with two responses (y1 and y2) and two covariates in the measurement model is specified;

  • latentFormula is used to specify the LM model with covariates in the latent model:

    • responsesFormula = y1 + y2 ~ NULL
      latentFormula = ~ x1 + x2 | x3 + x4
      the LM model with two responses (y1 and y2) and two covariates affecting the initial probabilities (x1 and x2) and other two affecting the transition probabilities (x3 and x4) is specified;

    • responsesFormula = y1 + y2 ~ NULL
      latentFormula = ~ 1 | x1 + x2
      (or latentFormula = ~ NULL | x1 + x2)
      the covariates affect only the transition probabilities and an intercept is specified for the intial probabilities;

    • responsesFormula = y1 + y2 ~ NULL
      latentFormula = ~ x1 + x2
      the LM model with two covariates (x1 and x2) affecting both the initial and transition probabilities is specified;

    • responsesFormula = y1 + y2 ~ NULL
      latentFormula = ~ NULL | NULL
      (or latentFormula = ~ 1 | 1)
      the LM model with only an intercept on the initial and transition probabilities is specified.

The function also allows us to deal with missing responses using the mix package for imputing the missing values. Missing values for the covariates are not allowed.

For categorical outcomes see the function lmest.

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.

See Also

lmestFormula

Examples

Run this code
if (FALSE) {

data(data_long_cont)

# Basic LM model

out <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ NULL,
                 index = c("id", "time"),
                 data = data_long_cont,
                 k = 3,
                 modBasic = 1,
                 tol = 10^-5)

out
summary(out)

# Basic LM model with model selection using BIC

out1 <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ NULL,
                  index = c("id", "time"),
                  data = data_long_cont,
                  k = 1:5,
                  ntry = 2,
                  modBasic = 1,
                  tol = 10^-5)

out1
out1$Bic

# Basic LM model with model selection using AIC

out2 <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ NULL,
                  index = c("id", "time"),
                  data = data_long_cont,
                  k = 1:5,
                  modBasic = 1,
                  ntry = 2,
                  modSel = "AIC",
                  tol = 10^-5)
out2
out2$Aic


# LM model with covariates in the measurement model

out3 <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ X1 + X2,
                  index = c("id", "time"),
                  data = data_long_cont,
                  k = 3,
                  output = TRUE)

out3 
summary(out3)

# LM model with covariates in the latent model

out4 <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ NULL,
                  latentFormula = ~ X1 + X2,
                  index = c("id", "time"),
                  data = data_long_cont,
                  k = 3,
                  output = TRUE)

out4
summary(out4)

# LM model with two covariates affecting the initial probabilities and one 
# affecting the transition probabilities 

out5 <- lmestCont(responsesFormula = Y1 + Y2 + Y3 ~ NULL,
                  latentFormula = ~ X1 + X2 | X1,
                  index = c("id", "time"),
                  data = data_long_cont,
                  k = 3,
                  output = TRUE)

out5
summary(out5)

}

Run the code above in your browser using DataLab