# Decoding for basic LM model
data("data_drug")
long <- data_drug[,-6]-1
long <- data.frame(id = 1:nrow(long),long)
long <- reshape(long,direction = "long",
idvar = "id",
varying = list(2:ncol(long)))
est <- lmest(index = c("id","time"),
k = 3,
data = long,
weights = data_drug[,6],
modBasic = 1)
# Decoding for a single sequence
out1 <- lmestDecoding(est, sequence = 1)
out2 <- lmestDecoding(est, sequence = 1:4)
# Decoding for all sequences
out3 <- lmestDecoding(est)
if (FALSE) {
# Decoding for LM model with covariates on the initial and transition probabilities
data("data_SRHS_long")
SRHS <- data_SRHS_long[1:2400,]
# Categories rescaled to vary from 0 (“poor”) to 4 (“excellent”)
SRHS$srhs <- 5 - SRHS$srhs
est2 <- lmest(responsesFormula = srhs ~ NULL,
latentFormula = ~
I(gender - 1) +
I( 0 + (race == 2) + (race == 3)) +
I(0 + (education == 4)) +
I(0 + (education == 5)) +
I(age - 50) + I((age-50)^2/100),
index = c("id","t"),
data = SRHS,
k = 2,
paramLatent = "difflogit",
output = TRUE)
# Decoding for a single sequence
out3 <- lmestDecoding(est2, sequence = 1)
# Decoding for the first three sequences
out4 <- lmestDecoding(est2, sequence = 1:3)
# Decoding for all sequences
out5 <- lmestDecoding(est2)
}
Run the code above in your browser using DataLab