# NOT RUN {
## generate sample data and separate them
X = aux.gensamples(n=500)
set.seed(46556)
idxtest = sample(1:500,20) # 20% of data for testing
idxtrain = setdiff(1:500,idxtest) # 80% of data for training
Xtrain = X[idxtrain,]
Xtest = X[idxtest,]
## run PCA for train data
res_train = do.pca(Xtrain,ndim=2,preprocess="whiten")
## perform OOS.LINEAR on new dataset
## note that inputs should be from a given model you trained
model.projection = res_train$projection
model.trfinfo = res_train$trfinfo
res_test = oos.linear(Xtest, model.projection, model.trfinfo)
## let's compare via visualization
xx = c(-2,2) # range of axis 1 for compact visualization
yy = c(-2,2) # range of axis 2 for compact visualization
mm = "black=train / red=test data" # figure title
YY = res_test$Ynew # out-of-sample projection for test data
opar <- par(no.readonly=TRUE)
plot(res_train$Y, type="p", xlim=xx, ylim=yy,
main=mm, xlab="axis 1", ylab="axis 2")
points(YY[,1], YY[,2], lwd=3, col="red")
par(opar)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab