Learn R Programming

valueprhr (version 0.1.0)

predict_pls: Predict from PLS Model

Description

Generate predictions from a fitted PLS model.

Usage

predict_pls(pls_result, newdata = NULL, ncomp = NULL)

Value

Matrix of predictions.

Arguments

pls_result

Result from fit_pls_multivariate.

newdata

Optional new data matrix for prediction.

ncomp

Number of components to use. Default uses optimal.

Examples

Run this code
# \donttest{
if (requireNamespace("pls", quietly = TRUE)) {
  set.seed(123)
  n <- 50
  p <- 10
  X <- matrix(rnorm(n * p), n, p)
  colnames(X) <- paste0("X", 1:p)
  Y <- X[, 1:3] %*% diag(c(1, 0.5, 0.3)) + matrix(rnorm(n * 3, 0, 0.5), n, 3)
  colnames(Y) <- paste0("Y", 1:3)

  result <- fit_pls_multivariate(X, Y, max_components = 5)
  preds <- predict_pls(result)
  dim(preds)
}
# }

Run the code above in your browser using DataLab