Calculate amplitudes of spectroscopic components (a.k.a. scores) by matrix multiplication (see section "Detais") and properly label created hyperSpec object.

getScores(
  sp,
  loadings = NULL,
  xLabel = "Component",
  yLabel = "Amplitude",
  names.var = "cNames",
  scores = NULL
)

Arguments

sp

Spectroscopic data (either a hyperSpec object or a matrix).

loadings

Components' spectra (loadings) as either a matrix or a hyperSpec object.

xLabel

A label for x axis. Default is "Component".
labels(scores,".wavelength") <- xLabel

yLabel

A label for y axis. Default is "Amplitude".
labels(scores,"spc") <- yLabel

names.var

A name of variable in loadings, that contains names of components (loadings). These names will be transfered to scores.
NOTES:
1. if names.var does not exist (e.g., misspelled), component names No1, No2, ... will be used.
2. This parameter applicable only if class of sp is hyperSpec.

scores

A matrix of known/already calculated scores to convert to hyperSpec object.
If this argument is provided, matrix multiplication is not performed, but component names are copied from loadings to scores.

Value

Amplitudes of the components (i.e., scores), tha corespond to observations (spectra) in object sp.

Details

Equation of matrix multiplication to calculate scores:

$$scores = sp * loadings * inv(loadings' * loadings)$$

This formula is taken and adapted from [1].

References

[1] M. Brydegaard et al. IEEE Photonics J 2011:3(3);406-21.

See also

qplot_scores

Other component analysis / factorisation related functions in spHelper: infoDim(), plot_spDiff(), qplot_infoDim(), qplot_kAmp(), qplot_kSp(), qplot_spc(), reconstructSp(), sortLoadings(), unipeak(), whichOutlier()

Author

Vilmantas Gegzna

Examples


sc <- getScores(Spectra2, Loadings2)
sc
#> hyperSpec object
#>    150 spectra
#>    3 data columns
#>    5 data points / spectrum
qplot_scores(sc)
#> Warning: Function 'hyperSpec::chk.hy' is deprecated. 
#> Use function 'assert_hyperSpec' instead.
#> Error in dplyr::mutate(., row = row_number()):  In argument: `row = row_number()`.
#> Caused by error in `row_number()`:
#> ! could not find function "row_number"