if (FALSE) { # interactive()
# Load the MVAD data
data(mvad)
mvad$Location <- factor(apply(mvad[,5:9], 1L, function(x)
which(x == "yes")), labels = colnames(mvad[,5:9]))
mvad <- list(covariates = mvad[c(3:4,10:14,87)],
sequences = mvad[,15:86],
weights = mvad[,2])
mvad.cov <- mvad$covariates
# Create a state sequence object with the first two (summer) time points removed
states <- c("EM", "FE", "HE", "JL", "SC", "TR")
labels <- c("Employment", "Further Education", "Higher Education",
"Joblessness", "School", "Training")
mvad.seq <- seqdef(mvad$sequences[-c(1,2)], states=states, labels=labels)
# \donttest{
# Fit a model with weights and a gating covariate
# Have the probability of noise-component membership depend on the covariate
mod <- MEDseq_fit(mvad.seq, G=5, modtype="UUN", weights=mvad$weights,
gating=~ gcse5eq, covars=mvad.cov, noise.gate=TRUE)
# Extract the names
names <- MEDseq_clustnames(mod, cluster=FALSE, size=TRUE)
# Get the renamed MAP cluster membership indicator vector
group <- MEDseq_nameclusts(names)
# Use the output in plots
plot(mod, type="d", soft=FALSE, weighted=FALSE, cluster=FALSE, size=TRUE, border=TRUE)
# same as:
# seqplot(mvad.seq, type="d", group=group)
# Indeed, this function is invoked by default for certain plot types
plot(mod, type="d", soft=TRUE, weighted=TRUE)
plot(mod, type="d", soft=TRUE, weighted=TRUE, SPS=FALSE)
# Invoke this function when printing the gating network coefficients
print(mod$gating, SPS=FALSE)
print(mod$gating, SPS=TRUE)
# Invoke this function in a call to MEDseq_meantime
MEDseq_meantime(mod, SPS=TRUE)
# Invoke this function in other plots
plot(mod, type="clusters", SPS=TRUE)
plot(mod, type="precision", SPS=TRUE)# }
}
Run the code above in your browser using DataLab