View source: R/contributions.R
| contributions | R Documentation |
Computes how much each variable (wavelength) contributes to the Q
residual or to Hotelling's T^2 of each sample, keeping the sign of
the deviation, to find the variables that make a sample an outlier.
Relative contributions, computed against reference samples, show what
differs between a sample and the reference ones.
contributions(
model,
ncomp = NULL,
statistic = c("q", "t2"),
data = NULL,
samples = NULL,
reference = NULL,
k = deprecated()
)
model |
A |
ncomp |
The number of components. Required for a |
statistic |
|
data |
The samples whose contributions are computed: a numeric
matrix or data frame with the variables of the model (other columns
are ignored when the columns are named), preprocessed like the data the
model was fitted on (for example, with |
samples |
Optional indices or names of the rows of |
reference |
Optional indices or names of rows of |
k |
For a sample x (centered and scaled as in the model), with scores
t = xP on the first k components (ncomp; loadings P,
variances of the scores \lambda):
the Q contributions are the residuals e = x - tP^T, whose
sum of squares is Q (the squared orthogonal distance of robust fits);
the T^2 contributions are t \Lambda^{-1/2} P^T, the
scaled scores projected back onto the variables, whose sum of squares
is T^2 (the squared score distance of robust fits). For rospca()
fits, whose loadings are not exactly orthogonal, the sum of squares is
close to, but not exactly, T^2.
Q contributions show which variables the model does not describe for a
sample: large contributions grouped on a few emission lines point to a
systematic deviation (a contamination, a matrix effect, a saturated or
shifted line), small ones spread over all channels to random noise.
T^2 contributions show which variables place a sample far from the
center in the score space.
Relative contributions. Normally, contributions are relative to the
model (its center, for T^2). With reference, the mean
contribution of the reference samples is subtracted from the
contribution of each sample, which shows what differs between them: for
example, whether two samples have large Q residuals for the same reason,
or what moves a sample from the regular samples to where it lies in the
score space. reference = "regular" uses all the regular samples: of
the robust fit, or at the highest confidence level of q_residuals() for
a stats::prcomp() fit.
The contributions are in the units of the preprocessed data of the model: centered (and scaled, if the model scaled the variables).
A tibble of class specproc_contributions with one row per
sample: sample (the row name, or number) and one column per variable.
The attribute total holds the statistic of each sample (Q or
T^2, before any reference is subtracted). Draw it with
plot_contributions().
Christian L. Goueguel
Westerhuis, J.A., Gurden, S.P., Smilde, A.K. (2000). Generalized contribution plots in multivariate statistical process monitoring. Chemometrics and Intelligent Laboratory Systems, 51(1):95-114.
plot_contributions(), q_residuals(), plot_outlier_map()
spectra_id <- names(forageLIBS)[1:2]
minerals <- names(forageLIBS)[3:14]
spectra <- forageLIBS |> dplyr::select(-dplyr::all_of(c(spectra_id, minerals)))
set.seed(1)
fit <- robpca(spectra, ncomp = 3)
# Q contributions of two outlying samples, relative to the regular ones
q <- contributions(fit, data = spectra, samples = c(49, 127), reference = "regular")
q[, 1:5]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.