The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

mixOmics PLS models

Function Works
tidypredict_fit(), tidypredict_sql(), parse_model()
tidypredict_to_column() ✔*
tidypredict_test() ✔*
tidypredict_interval(), tidypredict_sql_interval()
parsnip

* Only for regression models with a single outcome.

mixOmics fits partial least squares models with pls() and spls(), and the discriminant analysis variants with plsda() and splsda(). All four collapse down to one set of regression coefficients per outcome, so the generated expression is a plain linear combination of the predictors.

For a single-outcome regression model, tidypredict_fit() returns one expression. For a model with multiple outcome columns it returns a named list of expressions, one per outcome. For the discriminant variants it returns a named list of class-probability expressions (the softmax of the predicted dummy outcomes, matching what plsmod predicts). Since those two cases return a list, tidypredict_to_column() and tidypredict_test() only work for single-outcome regression models.

The number of components (ncomp) is baked into the coefficients, and the sparse variants simply give the predictors that were not selected a coefficient of zero.

tidypredict_ functions

x <- as.matrix(mtcars[c("cyl", "disp", "hp", "drat")])
model <- mixOmics::pls(x, mtcars$mpg, ncomp = 2)

Discriminant analysis

plsda() and splsda() return one probability expression per class:

da_model <- mixOmics::splsda(as.matrix(iris[1:4]), iris$Species, ncomp = 2)

fit <- tidypredict_fit(da_model)
names(fit)
#> [1] "setosa"     "versicolor" "virginica"
fit[["setosa"]]
#> 1/(1 + exp(1.96606184899222 + (ifelse(is.na(Sepal.Length), 5.84333333333333, 
#>     Sepal.Length) * -0.0303959537594359) + (ifelse(is.na(Sepal.Width), 
#>     3.05733333333333, Sepal.Width) * -0.49202376740696) + (ifelse(is.na(Petal.Length), 
#>     3.758, Petal.Length) * 0.0179469395936271) + (ifelse(is.na(Petal.Width), 
#>     1.19933333333333, Petal.Width) * -0.0152407670638332) - (0.391460011724111 + 
#>     (ifelse(is.na(Sepal.Length), 5.84333333333333, Sepal.Length) * 
#>         -0.118750531861652) + (ifelse(is.na(Sepal.Width), 3.05733333333333, 
#>     Sepal.Width) * 0.378311039737146) + (ifelse(is.na(Petal.Length), 
#>     3.758, Petal.Length) * -0.0845568813586671) + (ifelse(is.na(Petal.Width), 
#>     1.19933333333333, Petal.Width) * -0.16933234787912))) + exp(-1.35752186071634 + 
#>     (ifelse(is.na(Sepal.Length), 5.84333333333333, Sepal.Length) * 
#>         0.149146485621088) + (ifelse(is.na(Sepal.Width), 3.05733333333333, 
#>     Sepal.Width) * 0.113712727669814) + (ifelse(is.na(Petal.Length), 
#>     3.758, Petal.Length) * 0.06660994176504) + (ifelse(is.na(Petal.Width), 
#>     1.19933333333333, Petal.Width) * 0.184573114942953) - (0.391460011724111 + 
#>     (ifelse(is.na(Sepal.Length), 5.84333333333333, Sepal.Length) * 
#>         -0.118750531861652) + (ifelse(is.na(Sepal.Width), 3.05733333333333, 
#>     Sepal.Width) * 0.378311039737146) + (ifelse(is.na(Petal.Length), 
#>     3.758, Petal.Length) * -0.0845568813586671) + (ifelse(is.na(Petal.Width), 
#>     1.19933333333333, Petal.Width) * -0.16933234787912))))

parsnip

parsnip fitted models are also supported by tidypredict. The mixOmics engine of pls() works for both regression and classification:

library(parsnip)
library(plsmod)

p_model <- pls(num_comp = 2) %>%
  set_engine("mixOmics") %>%
  set_mode("regression") %>%
  fit(mpg ~ disp + hp + drat, data = mtcars)

tidypredict_fit(p_model)
#> 18.9698741155116 + (ifelse(is.na(disp), 230.721875, disp) * -0.0183282632913477) + 
#>     (ifelse(is.na(hp), 146.6875, hp) * -0.0323705835435152) + 
#>     (ifelse(is.na(drat), 3.5965625, drat) * 2.80763705068415)

mixOmics models are fit from a numeric matrix, so a model fit directly can only refer to the matrix columns it was given. Categorical predictors therefore work through the parsnip interface, which keeps the formula around and lets the dummy columns be written in terms of the original factors:

cars <- transform(mtcars, gear = factor(gear))

c_model <- pls(num_comp = 2) %>%
  set_engine("mixOmics") %>%
  set_mode("regression") %>%
  fit(mpg ~ disp + hp + gear, data = cars)

tidypredict_fit(c_model)
#> 28.3990491890354 + (ifelse(is.na(disp), 230.721875, disp) * -0.0212765260717577) + 
#>     (ifelse(is.na(hp), 146.6875, hp) * -0.0321040699674561) + 
#>     (ifelse(is.na(gear), 0.375, ifelse(gear == "4", 1, 0)) * 
#>         1.89118556186025) + (ifelse(is.na(gear), 0.15625, ifelse(gear == 
#>     "5", 1, 0)) * 3.84388465523581)

Parse model spec

Here is an example of the model spec:

pm <- parse_model(model)
str(pm, 2)
#> List of 2
#>  $ general:List of 5
#>   ..$ model  : chr "mixo_pls"
#>   ..$ version: num 2
#>   ..$ type   : chr "regression"
#>   ..$ is_glm : num 0
#>   ..$ ncomp  : num 2
#>  $ terms  :List of 5
#>   ..$ :List of 4
#>   ..$ :List of 4
#>   ..$ :List of 4
#>   ..$ :List of 4
#>   ..$ :List of 4
#>  - attr(*, "class")= chr [1:3] "parsed_model" "pm_regression" "list"

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.