get_loadings: Get loadings

View source: R/utility_functions.R

get_loadingsR Documentation

Get loadings

Description

Returns the loadings of a mixOmics spls train object. Either from the final model fitted on the full training data, or the median and sd across CV folds from the best performing tuning parameters. If there are multiple CV repeats, these are separated or can be chosen.

Usage

get_loadings(trainobj, what = c("finalModel", "CV"), xykeep = c("x", "y",
  "both"), rep = NA, remove_empty = TRUE, ncomp = NA, keepX = NA,
  keepY = NA)

Arguments

trainobj

The train object from caret, fit using mixOmics spls.

what

Which model to return loadings from. Either "finalModel" or "CV".

xykeep

Return loadings from x or y? Either "x", "y", or "both".

rep

If what = "CV", and trainobj was fit using repeated cross-validation, choose a repeat (e.g. "Rep1") or leave as NA for all repeats (default).

remove_empty

Remove loadings with a value of zero from output.

ncomp

Manually select CV predictions with this parameter.

keepX

Manually select CV predictions with this parameter.

keepY

Manually select CV predictions with this parameter.

Value

A data.frame with the variables

  • var - the variable

  • comp - the component

  • loading - the loading value (median if across CV folds / reps)

  • sd - the standard deviation of the loading (if across CV folds / reps, NA otherwise)

  • xy - is it a loading on x or y?

Examples

library(caret)
x <- data.frame(matrix(rnorm(1000),nrow = 100))
y <- rnorm(100)
PLS <- train(x = x, y = y, method = get_mixOmics_spls())
get_loadings(PLS)

get_loadings(PLS, "CV") %>%
  ggplot(aes(var, loading, ymin = loading - sd, ymax = loading + sd)) +
    facet_wrap(~ comp, scales = "free_x") +
    geom_errorbar() +
    geom_bar(stat = "identity")

jonathanth/mixOmicsCaret documentation built on Feb. 25, 2023, 5:41 a.m.