📄 crossval.html
字号:
<html><head><title>R: Cross-validation of PLSR and PCR models</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>
<table width="100%" summary="page for crossval {pls}"><tr><td>crossval {pls}</td><td align="right">R Documentation</td></tr></table>
<h2>Cross-validation of PLSR and PCR models</h2>
<h3>Description</h3>
<p>
A “stand alone” cross-validation function for <code>mvr</code> objects.
</p>
<h3>Usage</h3>
<pre>
crossval(object, segments = 10,
segment.type = c("random", "consecutive", "interleaved"),
length.seg, trace = 15, ...)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>object</code></td>
<td>
an <code>mvr</code> object; the regression to cross-validate.</td></tr>
<tr valign="top"><td><code>segments</code></td>
<td>
the number of segments to use, or a list with segments
(see below). Ignored if <code>loo = TRUE</code>.</td></tr>
<tr valign="top"><td><code>segment.type</code></td>
<td>
the type of segments to use. Ignored if
<code>segments</code> is a list.</td></tr>
<tr valign="top"><td><code>length.seg</code></td>
<td>
Positive integer. The length of the segments to
use. If specified, it overrides <code>segments</code>.</td></tr>
<tr valign="top"><td><code>trace</code></td>
<td>
if <code>TRUE</code>, tracing is turned on. If numeric, it
denotes a time limit (in seconds). If the estimated total time of
the cross-validation exceeds this limit, tracing is turned on.</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
additional arguments, sent to the underlying fit function.</td></tr>
</table>
<h3>Details</h3>
<p>
This function performs cross-validation on a model fit by <code>mvr</code>.
It can handle models such as <code>plsr(y ~ msc(X), ...)</code> or other
models where the predictor variables need to be recalculated for each
segment. When recalculation is not needed, the result of
<code>crossval(mvr(...))</code> is identical to <code>mvr(...,
validation = "CV")</code>, but slower.
</p>
<p>
If <code>length.seg</code> is specified, segments of the requested length
are used. Otherwise:
If <code>segments</code> is a number, it specifies the number of segments to
use, and <code>segment.type</code> is used to select the type of segments.
If <code>segments</code> is a list, the elements of the list should be
integer vectors specifying the indices of the segments. See
<code><a href="cvsegments.html">cvsegments</a></code> for details.
</p>
<p>
The R2 component returned is calculated as the squared correlation
between the cross-validated predictions and the responses.
</p>
<p>
When tracing is turned on, the segment number is printed for each segment.
</p>
<h3>Value</h3>
<p>
The supplied <code>object</code> is returned, with an additional component
<code>validation</code>, which is a list with components
</p>
<table summary="R argblock">
<tr valign="top"><td><code>method</code></td>
<td>
euqals <code>"CV"</code> for cross-validation.</td></tr>
<tr valign="top"><td><code>pred</code></td>
<td>
an array with the cross-validated predictions.</td></tr>
<tr valign="top"><td><code>MSEP0</code></td>
<td>
a vector of MSEP values (one for each response variable)
for a model with zero components, i.e., only the intercept.</td></tr>
<tr valign="top"><td><code>MSEP</code></td>
<td>
a matrix of MSEP values for models with 1, ...,
<code>ncomp</code> components. Each row corresponds to one response variable.</td></tr>
<tr valign="top"><td><code>adj</code></td>
<td>
a matrix of adjustment values for calculating bias
corrected MSEP. <code>MSEP</code> uses this.</td></tr>
<tr valign="top"><td><code>R2</code></td>
<td>
a matrix of R2 values for models with 1, ...,
<code>ncomp</code> components. Each row corresponds to one response variable.</td></tr>
<tr valign="top"><td><code>segments</code></td>
<td>
the list of segments used in the cross-validation.</td></tr>
</table>
<h3>Note</h3>
<p>
The <code>MSEP0</code> is always cross-validated using leave-one-out
cross-validation. This usually makes little difference in practice,
but should be fixed for correctness.
</p>
<h3>Author(s)</h3>
<p>
Ron Wehrens and Bj鴕n-Helge Mevik
</p>
<h3>References</h3>
<p>
Mevik, B.-H., Cederkvist, H. R. (2004) Mean Squared Error of
Prediction (MSEP) Estimates for Principal Component Regression (PCR)
and Partial Least Squares Regression (PLSR).
<EM>Journal of Chemometrics</EM>, <B>18</B>(9), 422–429.
</p>
<h3>See Also</h3>
<p>
<code><a href="mvr.html">mvr</a></code>
<code><a href="mvrCv.html">mvrCv</a></code>
<code><a href="cvsegments.html">cvsegments</a></code>
<code><a href="MSEP.html">MSEP</a></code>
</p>
<h3>Examples</h3>
<pre>
data(NIR)
NIR.pcr <- pcr(y ~ msc(X), 6, data = NIR)
NIR.cv <- crossval(NIR.pcr, segments = 10)
plot(MSEP(NIR.cv))
</pre>
<hr><div align="center">[Package <em>pls</em> version 1.1-0 <a href="00Index.html">Index]</a></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -