By splitting data into training and test data repeatedly the number of principal components can be determined by inspecting the distribution of the explained variances.

1 2 3 |

`X` |
numeric data frame or matrix |

`amax` |
maximum number of components for evaluation |

`center` |
should the data be centered? TRUE or FALSE |

`scale` |
should the data be scaled? TRUE or FALSE |

`repl` |
number of replications of the CV procedure |

`segments` |
number of segments for CV |

`segment.type` |
"random", "consecutive", "interleaved" splitting into training and test data |

`length.seg` |
number of parts for training and test data, overwrites segments |

`trace` |
if TRUE intermediate results are reported |

`plot.opt` |
if TRUE the results are shown by boxplots |

`...` |
additional graphics parameters, see |

For cross validation the data are split into a number of segments, PCA is computed (using 1 to amax components) for all but one segment, and the scores of the segment left out are calculated. This is done in turn, by omitting each segment one time. Thus, a complete score matrix results for each desired number of components, and the error martrices of fit can be computed. A measure of fit is the explained variance, which is computed for each number of components. Then the whole procedure is repeated (repl times), which results in repl numbers of explained variance for 1 to amax components, i.e. a matrix. The matrix is presented by boxplots, where each boxplot summarized the explained variance for a certain number of principal components.

`ExplVar ` |
matrix with explained variances, repl rows, and amax columns |

`MSEP ` |
matrix with MSEP values, repl rows, and amax columns |

Peter Filzmoser <P.Filzmoser@tuwien.ac.at>

K. Varmuza and P. Filzmoser: Introduction to Multivariate Statistical Analysis in Chemometrics. CRC Press, Boca Raton, FL, 2009.

1 2 3 |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.