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 # or sparse_pls_spec %>% fit_xy(x = meats %>% select(-protein), y = meats$protein)
The pls()
function can also be used with categorical outcomes.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.