predict.sparsePCA: Prediction of new scores

View source: R/predict.sparsePCA.R

predict.sparsePCAR Documentation

Prediction of new scores

Description

Performs scores of new observations on the principal components of sparsePCA (or groupsparsePCA). The new observations must be described with the same variables than those used in sparsePCA (or groupsparsePCA).

Usage

## S3 method for class 'sparsePCA'
predict(object, newdat, ...)

Arguments

object

an object of class sparsePCA obtained with the function sparsePCA or groupsparsePCA.

newdat

a numerical data matrix.

...

urther arguments passed to or from other methods. They are ignored in this function.

Value

Returns the matrix of the scores of the new observations on the principal components.

See Also

sparsePCA, groupsparsePCA

Examples

#Simulated data
v1 <- c(1,1,1,1,0,0,0,0,0.9,0.9)
v2 <- c(0,0,0,0,1,1,1,1,-0.3,0.3)
valp <- c(200,100,50,50,6,5,4,3,2,1)
A <- simuPCA(50,cbind(v1,v2),valp,seed=1)
#Group-sparse PCA
index <- rep(c(1,2,3),c(4,4,2)) 
train <- 1:30
test <- 31:50
res <- groupsparsePCA(A[train,],2,c(0.5,0.5),index)
pred <- predict(res,A[test,])

chavent/sparsePCA documentation built on Feb. 2, 2023, 1:12 p.m.