Title: Model Wrappers for Projection Methods
Version: 1.0.0
Description: Bindings for additional regression models for use with the 'parsnip' package, including ordinary and spare partial least squares models for regression and classification (Rohart et al (2017) <doi:10.1371/journal.pcbi.1005752>).
License: MIT + file LICENSE
URL: https://plsmod.tidymodels.org, https://github.com/tidymodels/plsmod
BugReports: https://github.com/tidymodels/plsmod/issues
Depends: parsnip (≥ 0.2.0), R (≥ 3.4)
Imports: dplyr, generics, magrittr, mixOmics, purrr, rlang, tibble, tidyr
Suggests: rmarkdown, covr, modeldata, spelling, testthat (≥ 3.0.0)
biocViews: mixOmics
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.2.1.9000
NeedsCompilation: no
Packaged: 2022-09-06 19:09:50 UTC; max
Author: Max Kuhn ORCID iD [aut, cre], RStudio [cph, fnd]
Maintainer: Max Kuhn <max@rstudio.com>
Repository: CRAN
Date/Publication: 2022-09-06 19:20:02 UTC

parsnip methods for partial least squares (PLS)

Description

plsmod offers a function to fit ordinary, sparse, and discriminant analysis PLS models.

Details

The model function works with the tidymodels infrastructure so that the model can be resampled, tuned, tided, etc.

Examples

For regression, let’s use the Tecator data in the modeldata package:

library(tidymodels)
library(plsmod)
tidymodels_prefer()
theme_set(theme_bw())

data(meats, package = "modeldata")

Note that using tidymodels_prefer() will resulting getting parsnip::pls() instead of mixOmics::pls() when simply running pls().

Although plsmod can fit multivariate models, we’ll concentration on a univariate model that predicts the percentage of protein in the samples.

meats <- meats %>% select(-water, -fat)

We define a sparse PLS model by setting the predictor_prop argument to a value less than one. This allows the model fitting process to set certain loadings to zero via regularization.

sparse_pls_spec <- 
  pls(num_comp = 10, predictor_prop = 1/3) %>% 
  set_engine("mixOmics") %>% 
  set_mode("regression")

The model is fit either with a formula or by passing the predictors and outcomes separately:

form_fit <- 
  sparse_pls_spec %>% 
  fit(protein ~ ., data = meats)
form_fit
## parsnip model object
## 
## 
## Call:
##  mixOmics::spls(X = x, Y = y, ncomp = ncomp, keepX = keepX) 
## 
##  sPLS with a 'regression' mode with 10 sPLS components. 
##  You entered data X of dimensions: 215 100 
##  You entered data Y of dimensions: 215 1 
## 
##  Selection of [34] [34] [34] [34] [34] [34] [34] [34] [34] [34] variables on each of the sPLS components on the X data set. 
##  Selection of [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] variables on each of the sPLS components on the Y data set. 
## 
##  Main numerical outputs: 
##  -------------------- 
##  loading vectors: see object$loadings 
##  variates: see object$variates 
##  variable names: see object$names 
## 
##  Functions to visualise samples: 
##  -------------------- 
##  plotIndiv, plotArrow 
## 
##  Functions to visualise variables: 
##  -------------------- 
##  plotVar, plotLoadings, network, cim
# or 

sparse_pls_spec %>% 
  fit_xy(x = meats %>% select(-protein), y = meats$protein)
## parsnip model object
## 
## 
## Call:
##  mixOmics::spls(X = x, Y = y, ncomp = ncomp, keepX = keepX) 
## 
##  sPLS with a 'regression' mode with 10 sPLS components. 
##  You entered data X of dimensions: 215 100 
##  You entered data Y of dimensions: 215 1 
## 
##  Selection of [34] [34] [34] [34] [34] [34] [34] [34] [34] [34] variables on each of the sPLS components on the X data set. 
##  Selection of [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] variables on each of the sPLS components on the Y data set. 
## 
##  Main numerical outputs: 
##  -------------------- 
##  loading vectors: see object$loadings 
##  variates: see object$variates 
##  variable names: see object$names 
## 
##  Functions to visualise samples: 
##  -------------------- 
##  plotIndiv, plotArrow 
## 
##  Functions to visualise variables: 
##  -------------------- 
##  plotVar, plotLoadings, network, cim

The pls() function can also be used with categorical outcomes.

Author(s)

Maintainer: Max Kuhn max@rstudio.com (ORCID)

Other contributors:

See Also

Useful links:


Model predictions across many sub-models

Description

Model predictions across many sub-models

Usage

## S3 method for class ''_mixo_pls''
multi_predict(object, new_data, num_comp = NULL, type = NULL, ...)

## S3 method for class ''_mixo_spls''
multi_predict(object, new_data, num_comp = NULL, type = NULL, ...)

## S3 method for class ''_mixo_plsda''
multi_predict(object, new_data, num_comp = NULL, type = NULL, ...)

## S3 method for class ''_mixo_splsda''
multi_predict(object, new_data, num_comp = NULL, type = NULL, ...)

Arguments

object

An object of class model_fit

new_data

A rectangular data object, such as a data frame.

num_comp

An integer vector for the number of PLS terms to retain.

type

A single character value or NULL. Possible values are "numeric", "class", or "prob". When NULL, predict() will choose an appropriate value based on the model's mode.

...

Not currently used.


Wrapper for mixOmics pls functions

Description

Based on arguments, this wrapper routes the data and arguments to the four pls functions that are sparse/dense or regression/classification.

Usage

pls_fit(x, y, ncomp = NULL, predictor_prop = 1, ...)

Arguments

x

A data frame or matrix of predictors.

y

For classification, a factor. For regression, a matrix, vector, or data frame.

ncomp

The number of PLS components. If left NULL, the maximum possible is used.

predictor_prop

The maximum proportion of original predictors that can have non-zero coefficients for each PLS component (via regularization). This value is used for all PLS components for X.

Value

A model object generated by mixOmics::pls(), mixOmics::plsda(), mixOmics::spls(), or mixOmics::splsda().


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

generics

tidy

magrittr

%>%

parsnip

multi_predict


Tidy methods for pls and spls objects

Description

Tidy methods for pls and spls objects

Usage

## S3 method for class 'mixo_pls'
tidy(x, ...)

## S3 method for class 'mixo_spls'
tidy(x, ...)

Arguments

x

An object with class mixo_pls or mixo_spls.

...

Not currently used.

Value

A tibble with columns terms (the predictor names), value (the loadings), type (either "predictors" or "outcomes"), and component (the component number).