## make a multiclass SIMCA model for Iris data
library(mdatools)
# split data
caldata = iris[seq(1, nrow(iris), 2), 1:4]
x.se = caldata[1:25, ]
x.ve = caldata[26:50, ]
x.vi = caldata[51:75, ]
x.test = iris[seq(2, nrow(iris), 2), 1:4]
c.test = iris[seq(2, nrow(iris), 2), 5]
# create individual models
m.se = simca(x.se, classname = "setosa")
m.se = selectCompNum(m.se, 1)
m.vi = simca(x.vi, classname = "virginica")
m.vi = selectCompNum(m.vi, 2)
m.ve = simca(x.ve, classname = "versicolor")
m.ve = selectCompNum(m.ve, 1)
# combine models into SIMCAM objects, show statistics and plots
m = simcam(list(m.se, m.vi, m.ve), info = "simcam model for Iris data")
summary(m)
# show predictions and residuals for calibration data
par(mfrow = c(2, 2))
plotPredictions(m)
plotCooman(m, nc = c(1, 2))
plotModelDistance(m, nc = 1)
plotDiscriminationPower(m, nc = c(1, 2))
par(mfrow = c(1, 1))
# apply the SIMCAM model to test set and show statistics and plots
res = predict(m, x.test, c.test)
summary(res)
plotPredictions(res)
Run the code above in your browser using DataLab