Predict responses and latent scores from PLS fits
Source:R/predict.gPLS.R, R/predict.pls.cox.R, R/predict.sPLS.R, and 1 more
predict_pls_latent.RdThese prediction helpers reconstruct the response matrix and latent
component scores for partial least squares (PLS) models fitted inside the
Cox-PLS toolbox. They support group PLS, sparse PLS, sparse-group PLS, and
classical PLS models created by sgPLS::gPLS(), sgPLS::sPLS(),
sgPLS::sgPLS(), or plsRcox::pls.cox().
Usage
# S3 method for class 'gPLS'
predict(object, newdata, scale.X = TRUE, scale.Y = TRUE, ...)
# S3 method for class 'pls.cox'
predict(object, newdata, scale.X = TRUE, scale.Y = TRUE, ...)
# S3 method for class 'sPLS'
predict(object, newdata, scale.X = TRUE, scale.Y = TRUE, ...)
# S3 method for class 'sgPLS'
predict(object, newdata, scale.X = TRUE, scale.Y = TRUE, ...)Arguments
- object
A fitted PLS model returned by
sgPLS::gPLS(),sgPLS::sPLS(),sgPLS::sgPLS(), orplsRcox::pls.cox().- newdata
Numeric matrix or data frame with the same number of columns as the training design matrix used when fitting
object.- scale.X, scale.Y
Logical flags indicating whether the predictors and responses supplied in
newdatashould be centred and scaled according to the training statistics stored inobject.- ...
Unused arguments included for compatibility with the generic
stats::predict()signature.
Value
A list containing reconstructed responses, latent component scores,
and regression coefficients. The exact elements depend on the specific PLS
algorithm but always include components named predict, variates, and
B.hat.
References
Bastien, P., Bertrand, F., Meyer, N., & Maumy-Bertrand, M. (2015). Deviance residuals-based sparse PLS and sparse kernel PLS for censored data. Bioinformatics, 31(3), 397–404. doi:10.1093/bioinformatics/btu660
See also
coxgpls(), coxsgpls(), coxspls_sgpls(), and
coxDKgplsDR() for Cox model wrappers that return PLS fits using these
prediction methods.
Examples
n <- 100
sigma.gamma <- 1
sigma.e <- 1.5
p <- 400
q <- 500
theta.x1 <- c(rep(1, 15), rep(0, 5), rep(-1, 15), rep(0, 5), rep(1.5,15),
rep(0, 5), rep(-1.5, 15), rep(0, 325))
theta.x2 <- c(rep(0, 320), rep(1, 15), rep(0, 5), rep(-1, 15), rep(0, 5),
rep(1.5, 15), rep(0, 5), rep(-1.5, 15), rep(0, 5))
theta.y1 <- 1
theta.y2 <- 1
Sigmax <- matrix(0, nrow = p, ncol = p)
diag(Sigmax) <- sigma.e ^ 2
Sigmay <- matrix(0,nrow = 1, ncol = 1)
diag(Sigmay) <- sigma.e ^ 2
set.seed(125)
gam1 <- rnorm(n)
gam2 <- rnorm(n)
X <- matrix(c(gam1, gam2), ncol = 2, byrow = FALSE) %*% matrix(c(theta.x1, theta.x2),
nrow = 2, byrow = TRUE) + mvtnorm::rmvnorm(n, mean = rep(0, p), sigma =
Sigmax, method = "svd")
Y <- matrix(c(gam1, gam2), ncol = 2, byrow = FALSE) %*% matrix(c(theta.y1, theta.y2),
nrow = 2, byrow = TRUE) + rnorm(n,0,sd=sigma.e)
ind.block.x <- seq(20, 380, 20)
model.gPLS <- sgPLS::gPLS(X, Y, ncomp = 2, mode = "regression", keepX = c(4, 4),
keepY = c(4, 4), ind.block.x = ind.block.x)
head(predict(model.gPLS, newdata = X)$variates)
#> dim 1 dim 2
#> [1,] 1.7433859 -1.0107806
#> [2,] 0.3536207 5.7590437
#> [3,] 4.6851991 -1.7566289
#> [4,] 0.2587842 -0.6634727
#> [5,] 1.5699343 0.4017589
#> [6,] -10.5958505 -2.3180566