woldcv: Wold's PCA cross-validation procedure

View source: R/woldcv.R

woldcvR Documentation

Wold's PCA cross-validation procedure

Description

Performs a cross-validation procedure for EOF/PCA according to an interpolation routine for substituted missing values

Usage

woldcv(
  dat,
  fracValid = 0.2,
  centered = TRUE,
  scaled = FALSE,
  uncenter.recon = TRUE,
  unscale.recon = TRUE,
  ...
)

Arguments

dat

Dataset (matrix)

fracValid

Fraction of data to use for each validation. Will determine the number of cross-validation groups (Default=0.2)

centered

Center data (logical). Passed to eof. Default = TRUE.

scaled

Scale data (logical). Passed to eof Default = FALSE.

uncenter.recon

Logical. Compare eof reconstruction to uncentered dat. If centered = FALSE, then this has no effect. Default = TRUE.

unscale.recon

Logical. Compare eof reconstruction to unscaleded dat. If scaled = FALSE, then this has no effect. Default = TRUE.

...

Additional parameters to pass to eof

Value

List of sum of square error (SS), root mean square error (RMSECV) of cross-validation, number of values used in validation (npred), number of groups used in cross-validation (ngroups)

References

Wold S (1978) Technometrics 20:397-405

Examples


### wine dataset example
data(wine)
dat <- as.matrix(wine[,-1])

# uncenter and unscale reconstruction
res <- woldcv(dat, fracValid=0.1, centered=TRUE, scaled=TRUE, 
  uncenter.recon = TRUE, unscale.recon = TRUE)
op <- par(mfrow=c(1,2))
plot(res$SS, t="b"); which.min(res$SS)
plot(res$RMSECV, t="b"); which.min(res$RMSECV)
par(op)
res$ngroups
res$npred

# Comparison to centered and scaled data
res <- woldcv(dat, fracValid=0.1, centered=TRUE, scaled=TRUE,
  uncenter.recon = FALSE, unscale.recon = FALSE)
op <- par(mfrow=c(1,2))
plot(res$SS, t="b"); which.min(res$SS)
plot(res$RMSECV, t="b"); which.min(res$RMSECV)
par(op)
res$ngroups
res$npred



### iris dataset example
data(iris)
dat <- as.matrix(iris[,-5])

# uncenter and unscale reconstruction
res <- woldcv(dat, fracValid=0.1, centered=TRUE, scaled=TRUE, 
  uncenter.recon = TRUE, unscale.recon = TRUE)
op <- par(mfrow=c(1,2))
plot(res$SS, t="b"); which.min(res$SS)
plot(res$RMSECV, t="b"); which.min(res$RMSECV)
par(op)
res$ngroups
res$npred

# comparison to centered and scaled data
res <- woldcv(dat, fracValid=0.2, centered=TRUE, scaled=TRUE,
  uncenter.recon = FALSE, unscale.recon = FALSE)
op <- par(mfrow=c(1,2))
plot(res$SS, t="b"); which.min(res$SS)
plot(res$RMSECV, t="b"); which.min(res$RMSECV)
par(op)
res$ngroups
res$npred


marchtaylor/sinkr documentation built on July 4, 2022, 5:48 p.m.