plsr | R Documentation |
Regression on PCA or PLS latent variables (scores).
Functions pcr
and plsr
assume PCA and PLS algorithms providing orthogonal scores.
Matrix X
is centered before the analyses, but X
is not column-wise scaled (there is no argument scale
available). If a scaling is needed, the user has to scale X
before using the functions.
Row observations can eventually be weighted (using argument weights
).
pcr(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, ...)
plsr(Xr, Yr, Xu, Yu = NULL, ncomp, algo = NULL, ...)
Xr |
A |
Yr |
A |
Xu |
A |
Yu |
A |
ncomp |
The maximal number of PLS scores (= components = latent variables) to consider. |
algo |
For |
... |
Optionnal arguments to pass in the function defined in |
A list of outputs (see examples), such as:
y |
Responses for the test data. |
fit |
Predictions for the test data. |
r |
Residuals for the test data. |
n <- 10
p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p)
y1 <- 100 * rnorm(n)
y2 <- 100 * rnorm(n)
Y <- cbind(y1, y2)
set.seed(NULL)
Xr <- X[1:8, ] ; Yr <- Y[1:8, ]
Xu <- X[9:10, ] ; Yu <- Y[9:10, ]
ncomp <- 3
fm <- plsr(Xr, Yr, Xu, Yu, ncomp = ncomp)
#fm <- pcr(Xr, Yr, Xu, Yu, ncomp = ncomp)
names(fm)
fm$y
fm$fit
fm$r
names(fm)
plsr(Xr, Yr, Xu, ncomp = ncomp)[c("y", "fit", "r")]
plsr(Xr, Yr[, 1], Xu, Yu[, 1], ncomp = ncomp)[c("y", "fit", "r")]
####### MSE
ncomp <- 3
fm <- plsr(Xr, Yr, Xu, Yu, ncomp = ncomp)
mse(fm, ~ ncomp, nam = "y1")
mse(fm, ~ ncomp, nam = "y2")
mse(fm, ~ ncomp)
z <- mse(fm, ~ ncomp)
z
z[z$msep == min(z$msep), ]
plotmse(z)
####### B-COEFFICIENTS FOR THE MODEL WITH ncomp COMPONENTS
bcoef(fm, ncomp = 2)
####### Weighted PLSR
# fictive weights
plsr(Xr, Yr, Xu, Yu, ncomp = ncomp, weights = 1:nrow(Xr))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.