# NOT RUN {
# Simulate two overlapping groups
n <- 200
pars <- list(pro = c(0.5, 0.5),
mean = matrix(c(-1,1), nrow = 2, ncol = 2, byrow = TRUE),
variance = mclustVariance("EII", d = 2, G = 2))
pars$variance$sigmasq <- 1
data <- sim("EII", parameters = pars, n = n, seed = 12)
class <- data[,1]
X <- data[,-1]
clPairs(X, class, symbols = c(1,2), main = "Full classified data")
# Randomly remove labels
cl <- class; cl[sample(1:n, size = 195)] <- NA
table(cl, useNA = "ifany")
clPairs(X, ifelse(is.na(cl), 0, class),
symbols = c(0, 16, 17), colors = c("grey", 4, 2),
main = "Partially classified data")
# Fit semi-supervised classification model
mod_SSC <- MclustSSC(X, cl)
summary(mod_SSC, parameters = TRUE)
pred_SSC <- predict(mod_SSC)
table(Predicted = pred_SSC$classification, Actual = class)
ngrid <- 50
xgrid <- seq(-3, 3, length.out = ngrid)
ygrid <- seq(-4, 4.5, length.out = ngrid)
xygrid <- expand.grid(xgrid, ygrid)
pred_SSC <- predict(mod_SSC, newdata = xygrid)
col <- mclust.options("classPlotColors")[class]
pch <- class
pch[!is.na(cl)] = ifelse(cl[!is.na(cl)] == 1, 19, 17)
plot(X, pch = pch, col = col)
contour(xgrid, ygrid, matrix(pred_SSC$z[,1], ngrid, ngrid),
add = TRUE, levels = 0.5, drawlabels = FALSE, lty = 2, lwd = 2)
# }
Run the code above in your browser using DataLab