data(linnerud)
X <- linnerud$exercise
Y <- linnerud$physiological
linn.pls <- pls(X, Y, ncomp = 2, mode = "classic")
indiv1 <- c(200, 40, 60)
indiv2 <- c(190, 45, 45)
newdata <- rbind(indiv1, indiv2)
colnames(newdata) <- colnames(X)
newdata
pred <- predict(linn.pls, newdata)
plotIndiv(linn.pls, comp = 1:2, rep.space = "X-variate")
points(pred$variates[, 1], pred$variates[, 2], pch = 19, cex = 1.2)
text(pred$variates[, 1], pred$variates[, 2],
c("new ind.1", "new ind.2"), pos = 3)
## First example with plsda
data(liver.toxicity)
X = as.matrix(liver.toxicity$gene)
Y = as.factor(liver.toxicity$treatment[,4] )
# if training is perfomed on 4/5th of the original data
samp = sample(1:5, nrow(X), replace = TRUE)
test = which(samp == 1) # testing on the first fold
train = setdiff(1:nrow(X), test)
plsda.train = plsda(X[train,], Y[train], ncomp = 1, mode = 'regression')
test.predict = predict(plsda.train, X[test,], method = "class.dist")
test.predict$class
## Second example with splsda
data(liver.toxicity)
X = as.matrix(liver.toxicity$gene)
Y = as.factor(liver.toxicity$treatment[, 4]) # time points
# if training is perfomed on 4/5th of the original data
samp = sample(1:5, nrow(X), replace = TRUE)
test = which(samp == 1) # testing on the first fold
train = setdiff(1:nrow(X), test)
splsda.train = splsda(X[train,], Y[train], ncomp = 1, keepX = 20, mode = 'regression')
test.predict = predict(splsda.train, X[test,], method = "class.dist")
test.predict$class
Run the code above in your browser using DataLab