# \donttest{
## generate sample data and separate them
data(iris, package="Rdimtools")
X = as.matrix(iris[,1:4])
lab = as.factor(as.vector(iris[,5]))
ids = sample(1:150, 30)
Xold = X[setdiff(1:150,ids),] # 80% of data for training
Xnew = X[ids,] # 20% of data for testing
## run PCA for train data & use the info for prediction
training = do.pca(Xold,ndim=2)
Yold = training$Y
Ynew = Xnew%*%training$projection
Yplab = lab[ids]
## perform out-of-sample prediction
Yoos = oos.linproj(Xold, Yold, Xnew)
## visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
plot(Ynew, pch=19, col=Yplab, main="true prediction")
plot(Yoos, pch=19, col=Yplab, main="OOS prediction")
par(opar)
# }
Run the code above in your browser using DataLab