# NOT RUN {
# 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)
# Fit a range of exponential-distance models without clustering
mod0 <- MEDseq_fit(mvad.seq, G=1)
# Show the central sequence and precision parameters of the optimal model
plot(mod0, type="mean")
plot(mod0, type="precision")
# }
# NOT RUN {
# Fit a range of unweighted mixture models without covariates
# Only consider models with a noise component
# mod1 <- MEDseq_fit(mvad.seq, G=9:11, modtype=c("CCN", "CUN", "UCN", "UUN"))
# Plot the DBS values for all fitted models
# plot(mod1, "dbs")
# Plot the clusters of the optimal model (according to the dbs criterion)
# plot(mod1, "clusters", criterion="dbs")
# Plot the observation-specific ASW values of the best UUN model (according to the asw criterion)
# plot(mod1, "aswvals", modtype="UUN", criterion="asw")
# Fit a model with weights and gating covariates
# mod2 <- MEDseq_fit(mvad.seq, G=10, modtype="UCN", weights=mvad$weights,
# gating=~ fmpr + gcse5eq + livboth, covars=mvad.cov)
# Plot the central sequences & precision parameters of this model
# plot(mod2, "mean")
# plot(mod2, "precision")
# Plot the clustering uncertainties in the form of a barplot
# plot(mod2, "uncert.bar")
# Plot the observation-specific DBS values and the transversal entropies by cluster
# plot(mod2, "dbsvals")
# plot(mod2, "Ht")
# Plot the state-distributions by cluster
# Note that this plot may not display properly in the preview panel
# plot(mod2, "d")
# }
Run the code above in your browser using DataLab