# Plsrsgcv

### Purpose

Generates a PLS model for MSPC with cross-validation.

### Synopsis

- coeff = plsrsgcv(data,lv,cvit,cvnum,out)

### Description

This function constructs a matrix of PLS models that can be used like a PCA model for multivariate statistical process control (MSPC) purposes. Given a data matrix `data`, a PLS model is formed using a maximum of `lv` latent variables that relates each variable to all of the other variables. The PLS model regression vectors are collected in an output matrix `coeff`, which can be used like the `I=PP'` matrix in PCA.

Multiplying a new data matrix by the matrix `coeff` yields a matrix whose values are the difference between the new data and it's prediction based on the PLS regressions created by `plsrsgncv`.

**Warning**: This function can take a long time to execute if you choose to do many cross-validations! Execution can be sped up by setting optional variable out=0.

#### Inputs

**data**= input data matrix**lv**= maximum number of latent variables to consider**cvit**= the number of cross-validation test sets**cvnum**= the number of samples in each cross validation test set

#### Optional Inputs

**out**= allows the user to suppress intermediate output [out=0 suppresses output]

#### Outputs

**coeff**= matrix of PLS regression coefficients