Type: | Package |
Title: | Interpretation Tools for Partial Least Squares Regression |
Version: | 0.2.1 |
Imports: | pls, ggplot2, ggrepel, rlang, descriptio |
Suggests: | plsVarSel, ggforce |
Description: | Various kinds of plots (observations, variables, correlations, weights, regression coefficients and Variable Importance in the Projection) and aids to interpretation (coefficients, Q2, correlations, redundancies) for partial least squares regressions computed with the 'pls' package, following Tenenhaus (1998, ISBN:2-7108-0735-1). |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
URL: | https://framagit.org/nicolas-robette/morepls, https://nicolas-robette.frama.io/morepls/ |
NeedsCompilation: | no |
Packaged: | 2025-05-29 09:42:16 UTC; nicolas |
Author: | Nicolas Robette [aut, cre] |
Maintainer: | Nicolas Robette <nicolas.robette@uvsq.fr> |
Repository: | CRAN |
Date/Publication: | 2025-05-29 10:10:02 UTC |
Q2 and cumulative Q2 indexes
Description
Computes Q2 and cumulative Q2 indexes from a PLS regression.
Usage
get_Q2(object)
Arguments
object |
an object of class |
Value
A list with the following elements :
Q2kh |
Q2 index by X variable and number of components |
Q2h |
Q2 index by number of components |
Q2cumkh |
cumulative Q2 index by X variable and number of components |
Q2cumh |
cumulative Q2 index by number of components |
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
res <- get_Q2(pls)
str(res)
Standardized and raw coefficients
Description
Computes the standardized and raw coefficients of a PLS regression, with p-values and confidence intervals from a jackknife procedure.
Usage
get_coef(object, y = NULL, ncomp = NULL,
ci = 0.95, raw = FALSE)
Arguments
object |
an object of class |
y |
the name of the response variable whose coefficients are plotted. If |
ncomp |
the number of components to use for computing coefficients |
ci |
the confidence level of the confidence interval. Default is 0.95. |
raw |
logical. If |
Value
A data frame with coefficients, standard deviation, t-values, p-values and confidence intervals.
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls",
jackknife = TRUE)
res <- get_coef(pls)
head(res)
Correlations between variables and scores
Description
Computes correlations between variables and scores from a PLS regression.
Usage
get_cor(object)
Arguments
object |
an object of class |
Value
A list with the following elements :
Xt |
correlations between X variables and X scores |
Yt |
correlations between Y variables and X scores |
Xu |
correlations between X variables and Y scores |
Yu |
correlations between Y variables and Y scores |
XY |
correlations between X variables and Y variables |
tu |
correlations between X scores and Y scores |
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
res <- get_cor(pls)
str(res)
R2 and redundancies
Description
Computes R2 and redundancies between variables and scores from a PLS regression.
Usage
get_red(object)
Arguments
object |
an object of class |
Value
A list with the following elements :
Xt |
R2 and redundancies between X variables and X scores |
Yt |
R2 and redundancies between Y variables and X scores |
Xu |
R2 and redundancies between X variables and Y scores |
Yu |
R2 and redundancies between Y variables and Y scores |
Xtcum |
cumulative R2 and redundancies between X variables and X scores |
Ytcum |
cumulative R2 and redundancies between Y variables and X scores |
Xucum |
cumulative R2 and redundancies between X variables and Y scores |
Yucum |
cumulative R2 and redundancies between Y variables and Y scores |
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
res <- get_red(pls)
str(res)
Plot of coefficients
Description
Plots the coefficients from a PLS regression.
Usage
plo_coef(object, y = NULL, ncomp = NULL, sort = FALSE,
col = "darkgreen", repel = FALSE,
max.pval = NULL, whiskers = FALSE, ci = 0.95)
Arguments
object |
an object of class |
y |
the name of the response variable whose coefficients are plotted. If |
ncomp |
the number of components to use for computing coefficients |
sort |
logical. If |
col |
color of the bars |
repel |
logical. If |
max.pval |
coefficients with jack-knife p-values higher than |
whiskers |
logical. If |
ci |
the confidence level of the confidence interval. Only used if |
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls",
jackknife = TRUE)
plo_coef(pls)
plo_coef(pls, max.pval = 0.05)
plo_coef(pls, whiskers = TRUE)
Plot of correlations
Description
Plots the correlations between (X and Y) variables and the components (X scores) of a PLS regression.
Usage
plo_cor(object, comps = 1:2, which = "both", min.cor = NULL,
lim = NULL, circles = NULL, col = NULL, size = 3.88)
Arguments
object |
an object of class |
comps |
the components to use. Default is |
which |
character string. If |
min.cor |
numerical value. The minimal correlation with one or the other component for a variable to be plotted. If |
lim |
numerical value. The limit of the scale (in absolute value). If |
circles |
vector of numeric values. Circles are added to the plot at radiuses specified in |
col |
colors for the names of the variables. Only one value should be provided if |
size |
numerical value. The size of the names of the variables. |
Value
a ggplot2
object
Note
This is what Tenenhaus calls the univariate interpretation of the PLS components, as opposed to the multivariate interpretation (see plo_var
).
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
plo_cor(pls)
# plot with circles corresponding to
# correlations of 0.5 and 1
plo_cor(pls, lim = 1, circles = c(0.5, 1), col = c("pink", "purple"))
Plot of weights
Description
Plots the weights of X variables from a PLS regression.
Usage
plo_ctr(object, comp = 1, sort = FALSE, col = "tomato4", repel = FALSE)
Arguments
object |
an object of class |
comp |
the component to use. Default is 1. |
sort |
logical. If |
col |
color of the bars |
repel |
logical. If |
Details
According to Tenenhaus, the contribution of a variable to the construction of a component is measured by the squared loading weight. For a given component, the sum af the squared loading weights is equal to 1. This plot represents the loading weights, which keeps the information about their sign. Dashed lines are added at +/- sqrt(1/p), with p the number of X variables, which corresponds to the average contribution to the construction of the component.
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
plo_ctr(pls)
Plot of Interactions
Description
Plots the interaction between two categorical supplementary variables for a PLS regression.
Usage
plo_inter(object, var1, var2, excl1 = NULL, excl2 = NULL,
comps = c(1,2), shapesize = 1, textsize = 3,
force = 1, max.overlaps = Inf,
lines = TRUE, dashes = TRUE)
Arguments
object |
an object of class |
var1 |
factor. The first categorical supplementary variable. |
var2 |
factor. The second categorical supplementary variable. |
excl1 |
character vector of categories from the var1 to exclude from the plot. If NULL (default), all the supplementary categories are plotted. |
excl2 |
character vector of categories from the var2 to exclude from the plot. If NULL (default), all the supplementary categories are plotted. |
comps |
the components to use. Default is |
shapesize |
Size of the shapes. Default is 1. |
textsize |
Size of the labels of categories. Default is 3. |
force |
Force of repulsion between overlapping text labels. Defaults to 1. If 0, labels are not repelled at all. |
max.overlaps |
Exclude text labels that overlap too many things. Defaults to Inf, which means no labels are excluded. |
lines |
logical. Whether to add colored lines between the points of the categories of v1. Default is TRUE. |
dashes |
logical. Whether to add gray dashed lines between the points of the categories of v2. Default is TRUE. |
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(mpg, package = "ggplot2")
pls <- mvr(displ ~ cty + hwy + cyl,
ncomp = 3,
data = mpg,
validation = "CV",
method = "oscorespls")
supvars <- data.frame(class = factor(mpg$class), trans = factor(mpg$trans))
plo_inter(pls, factor(mpg$class), factor(mpg$trans), lines = FALSE, dashes = FALSE)
Plot of scores
Description
Plots the scores of the observations of a PLS regression.
Usage
plo_obs(object, comps = 1:2, col = "black", size = 1.5)
Arguments
object |
an object of class |
comps |
the components to use. Default is |
col |
the color of the points. |
size |
numerical value. The size of the points. |
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
plo_obs(pls)
Plot of Main and Partial Effect
Description
Plots the the main and partial effects of a supplementary variable for a PLS regression, with one or more supplementary partialled out.
Usage
plo_part(object, var, controls, excl = NULL,
comps = c(1,2), shapesize = 1.5, col = "black",
textsize = 4, force = 1, max.overlaps = Inf,
lines = TRUE, dashes = TRUE, alpha = 0.3, legend = "right")
Arguments
object |
an object of class |
var |
factor. The categorical supplementary variable. |
controls |
data frame of supplementary variables to be partialled out (i.e. control variables) |
excl |
character vector of categories from the var to exclude from the plot. If NULL (default), all the supplementary categories are plotted. |
comps |
the components to use. Default is |
shapesize |
Size of the shapes. Default is 1.5. |
col |
the color for the labels and lines. Default is "black". |
textsize |
Size of the labels of categories. Default is 4. |
force |
Force of repulsion between overlapping text labels. Defaults to 1. If 0, labels are not repelled at all. |
max.overlaps |
Exclude text labels that overlap too many things. Defaults to Inf, which means no labels are excluded. |
lines |
logical. Whether to add colored lines between the points of the categories of v1. Default is TRUE. |
dashes |
logical. Whether to add gray dashed lines between the points of the categories of v2. Default is TRUE. |
alpha |
Numerical value. Transparency of the partial effects. Default is 0.3. |
legend |
the position of legends ("none", "left", "right", "bottom", "top", or two-element numeric vector). Default is right. |
Value
a ggplot2
object
Note
The partial effects of the supplementary variable are computed with the Average Marginal Effects of a linear regression, with individual coordinates as dependent variable, and the supplementary and control variables as independent variables.
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(mpg, package = "ggplot2")
pls <- mvr(displ ~ cty + hwy + cyl,
ncomp = 3,
data = mpg,
validation = "CV",
method = "oscorespls")
plo_part(pls, factor(mpg$class), factor(mpg$trans), lines = FALSE, dashes = FALSE)
Plot of Supplementary Variables
Description
Plots the categories of supplementary variables for a PLS regression.
Usage
plo_sup(object, vars, excl = NULL, comps = c(1,2),
shapesize = 2, textsize = 3, vlab = TRUE, force = 1,
max.overlaps = Inf, dashes = TRUE)
Arguments
object |
an object of class |
vars |
A data frame of categorical supplementary variables. All these variables should be factors. |
excl |
character vector of supplementary categories to exclude from the plot, specified in the form "namevariable.namecategory" (for instance "Gender.Men"). If NULL (default), all the supplementary categories are plotted. |
comps |
the components to use. Default is |
shapesize |
Size of the shapes. Default is 2. |
textsize |
Size of the labels of categories. Default is 3. |
vlab |
Logical. If TRUE (default), the variable name is added as a prefix for the labels of the categories. |
force |
Force of repulsion between overlapping text labels. Defaults to 1. If 0, labels are not repelled at all. |
max.overlaps |
Exclude text labels that overlap too many things. Defaults to Inf, which means no labels are excluded. |
dashes |
Logical. Should one add lines between categories ? Default is TRUE. |
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(mpg, package = "ggplot2")
pls <- mvr(displ ~ cty + hwy + cyl,
ncomp = 3,
data = mpg,
validation = "CV",
method = "oscorespls")
supvars <- data.frame(class = factor(mpg$class), trans = factor(mpg$trans))
plo_sup(pls, supvars, dashes = FALSE)
Plot of loadings
Description
Plots the loadings of the variables of a PLS regression.
Usage
plo_var(object, comps = 1:2, which = "both", col = NULL,
size = 3.88, Yline = TRUE, col.Yline = "firebrick3")
Arguments
object |
an object of class |
comps |
the components to use. Default is |
which |
character string. If |
col |
colors for the names of the variables. Only one value should be provided if |
size |
numerical value. The size of the names of the variables. |
Yline |
logical. If |
col.Yline |
the color of the lines drawn if |
Value
a ggplot2
object
Note
This is what Tenenhaus calls the multivariate interpretation of the PLS components, as opposed to the univariate interpretation provided by the correlations (see plo_cor
). This superposes Y loadings (vectors from the C matrix) and projections, i.e. modified weights (vectors of the W* matrix).
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
plo_var(pls)
Plot of VIPs
Description
Plots the Variable Importance in Projections (VIP) indexes of a PLS regression.
Usage
plo_vip(object, ncomp = NULL, sort = FALSE,
col = "steelblue4", repel = FALSE)
Arguments
object |
an object of class |
ncomp |
the number of components to use for computing VIPs |
sort |
logical. If |
col |
color of the bars |
repel |
logical. If |
Value
a ggplot2
object
Author(s)
Nicolas Robette
References
Martens, H., Næs, T. (1989) Multivariate calibration. Chichester: Wiley.
Tenenhaus, M. (1998) La Regression PLS. Theorie et Pratique. Editions TECHNIP, Paris.
See Also
Examples
library(pls)
data(yarn)
pls <- mvr(density ~ NIR,
ncomp = 5,
data = yarn,
validation = "CV",
method = "oscorespls")
plo_vip(pls)