# Overview

This vignette is a short tutorial on the use of the core functions of
the `bootPLS`

package.

These functions can also be used to reproduce the simulations and the figures of the book chapter Magnanensi et al. (2016) and of the two articles https://doi.org/10.1007/978-3-319-40643-5_18, Magnanensi et al. (2017) https://doi.org/10.1007/s11222-016-9651-4 and Magnanensi et al. (2021) https://doi.org/10.3389/fams.2021.693126.

# Pine real dataset: pls and spls regressions

## Loading and displaying dataset

Load and display the pinewood worm dataset.

```
library(bootPLS)
library(plsRglm)
data(pine, package = "plsRglm")
Xpine<-pine[,1:10]
ypine<-log(pine[,11])
```

Michel Tenenhaus’ reported in his book, *La régression PLS*
(1998) Technip, Paris, that most of the expert biologists claimed that
this dataset features two latent variables, which is tantamount to the
PLS model having two components.

## PLS LOO and CV

Leave one out CV (`K=nrow(pine)`

) one time
(`NK=1`

).

```
bbb <- plsRglm::cv.plsR(log(x11)~.,data=pine,nt=6,K=nrow(pine),NK=1,verbose=FALSE)
plsRglm::cvtable(summary(bbb))
```

Set up 6-fold CV (`K=6`

), 100 times (`NK=100`

),
and use `random=TRUE`

to randomly create folds for repeated
CV.

Display the results of the cross-validation.

The \(Q^2\) criterion is recommended in that PLSR setting without missing data. A model with 1 component is selected by the cross-validation as displayed by the following figure. Hence the \(Q^2\) criterion (1 component) does not agree with the experts (2 components).

As for the CV Press criterion it is unable to point out a unique number of components.

## PLS (Y,T) Bootstrap

The package features our bootstrap based algorithm to select the
number of components in plsR regression. It is implemented with the
`nbcomp.bootplsR`

function.

The `verbose=FALSE`

option suppresses messages output
during the algorithm, which is useful to replicate the bootstrap
technique. To set up parallel computing, you can use the
`parallel`

and the `ncpus`

options.

```
set.seed(4619)
res_boot_rep <- replicate(20,nbcomp.bootplsR(Y=ypine,X=Xpine,R =500,verbose =FALSE,parallel = "multicore",ncpus = 2))
```

It is easy to display the results with the `barplot`

function.

A model with two components should be selected using our bootstrap based algorithm to select the number of components. Hence the number of component selected with our algorithm agrees with what was stated by the experts.

## sPLS (Y,T) Bootstrap

The package also features our bootstrap based algorithm to select,
for a given \(\eta\) value, the number
of components in spls regression. It is implemented with the
`nbcomp.bootspls`

function.

A `doParallel`

and `foreach`

based parallel
computing version of the algorithm is implemented as the
`nbcomp.bootspls.para`

function.

## Bootstrap (Y,X) for the coefficients with number of components updated for each resampling

Pinewood worm data reloaded.

```
library(bootPLS)
library(plsRglm)
data(pine, package = "plsRglm")
Xpine<-pine[,1:10]
ypine<-log(pine[,11])
datasetpine <- cbind(ypine,Xpine)
```

Replicate the results to get the bootstrap distributions of the selected number of components and the coefficients.

Parallel computing support with the `ncpus`

and
`parallel="multicore"`

options.

# Aze real dataset: binary logistic plsRglm and sgpls regressions

## PLSGLR (Y,T) Bootstrap

Loading the data and creating the data frames.

```
data(aze_compl)
Xaze_compl<-aze_compl[,2:34]
yaze_compl<-aze_compl$y
dataset <- cbind(y=yaze_compl,Xaze_compl)
```

Fitting a logistic PLS regression model with 10 components. You have to use the family option when fitting the plsRglm.

Perform the bootstrap based algorithm with the
`nbcomp.bootplsRglm`

function. By default 250 resamplings are
carried out.

Plotting the bootstrap distributions of the coefficients of the components.

Computing the bootstrap based confidence intervals of the coefficients of the components.

Computing the bootstrap based confidence intervals of the coefficients of the components.

## sparse PLSGLR (Y,T) Bootstrap

The package also features our bootstrap based algorithm to select,
for a given \(\eta\) value, the number
of components in sgpls regression. It is implemented in the
`nbcomp.bootsgpls`

.

```
set.seed(4619)
data(prostate, package="spls")
nbcomp.bootsgpls((prostate$x)[,1:30], prostate$y, R=250, eta=0.2, typeBCa = FALSE)
```

A `doParallel`

and `foreach`

based parallel
computing version of the algorithm is implemented as the
`nbcomp.bootspls.para`

function.