# \donttest{
data(titanic)
head(titanic)
## Use the MixtComp format
dat <- titanic
# refactor categorical data: survived, sex, embarked and pclass
dat$sex <- refactorCategorical(dat$sex, c("male", "female", NA), c(1, 2, "?"))
dat$embarked <- refactorCategorical(dat$embarked, c("C", "Q", "S", NA), c(1, 2, 3, "?"))
dat$survived <- refactorCategorical(dat$survived, c(0, 1, NA), c(1, 2, "?"))
dat$pclass <- refactorCategorical(dat$pclass, c("1st", "2nd", "3rd"), c(1, 2, 3))
# replace all NA by ?
dat[is.na(dat)] <- "?"
# create model
model <- list(
pclass = "Multinomial",
survived = "Multinomial",
sex = "Multinomial",
age = "Gaussian",
sibsp = "Poisson",
parch = "Poisson",
fare = "Gaussian",
embarked = "Multinomial"
)
# create algo
algo <- createAlgo()
# run clustering
resLearn <- mixtCompLearn(dat, model, algo, nClass = 2:15, criterion = "ICL", nRun = 3, nCore = 1)
summary(resLearn)
plot(resLearn)
## Use standard data.frame and R format because titanic contains only standard variables.
# mixtCompLearn in "basic" mode without model parameters and data as a data.frame.
# A Multinomial model is used for factor variables, a Poisson for integer
# and a Gaussian for numeric.
resLearn <- mixtCompLearn(titanic, nClass = 2:15, nRun = 3, nCore = 1)
# imputed model
getType(resLearn)
# }
Run the code above in your browser using DataLab