eofRecon: EOF reconstruction (Empirical Orthogonal Functions analysis)

View source: R/eofRecon.R

eofReconR Documentation

EOF reconstruction (Empirical Orthogonal Functions analysis)

Description

This function reconstructs the original field from an EOF object of the function eof.

Usage

eofRecon(EOF, pcs = NULL, newpcs = NULL, uncenter = TRUE, unscale = TRUE)

Arguments

EOF

An object resulting from the function eof.

pcs

The principal components (PCs) to use in the reconstruction (defaults to the full set of PCs: pcs=seq(ncol(EOF$u)))

newpcs

An (optional) matrix of new principal coordinates to use in the reconstruction. This would typically come from a gappy dataset whose missing values are to be predicted based on the EOF loadings of a the EOF object (see eofPred).

uncenter

Logical. Should reconstructed matrix be un-centered (e.g. if centered = TRUE was used in linkeof). Default is TRUE.

unscale

Logical. Should reconstructed matrix be un-centered (e.g. if scaled = TRUE was used in linkeof). Default is TRUE.

Examples

set.seed(1)
iris.gappy <- as.matrix(iris[,1:4])
iris.gappy[sample(length(iris.gappy), 0.25*length(iris.gappy))] <- NaN
Er <- eof(iris.gappy, method="svd", recursive=TRUE) # recursive (RSEOF)
Enr <- eof(iris.gappy, method="svd", recursive=FALSE) # non-recursive (LSEOF)
iris.gappy.recon.r <- eofRecon(Er)
iris.gappy.recon.nr <- eofRecon(Enr)

# Reconstructed values vs. observed values
op <- par(mfrow=c(1,2))
lim <- range(iris.gappy, na.rm=TRUE)
plot(iris.gappy, iris.gappy.recon.r, 
col=c(2:4)[iris$Species], main="recursive=TRUE", xlim=lim, ylim=lim)
abline(0, 1, col=1, lwd=2)
plot(iris.gappy, iris.gappy.recon.nr, 
col=c(2:4)[iris$Species], main="recursive=FALSE", xlim=lim, ylim=lim)
abline(0, 1, col=1, lwd=2)
par(op)

# Reconstructed values from gappy data vs. all original values
op <- par(mfrow=c(1,2))
plot(as.matrix(iris[,1:4]), iris.gappy.recon.r, 
col=c(2:4)[iris$Species], main="recursive=TRUE")
abline(0, 1, col=1, lwd=2) 
plot(as.matrix(iris[,1:4]), iris.gappy.recon.nr, 
col=c(2:4)[iris$Species], main="recursive=FALSE")
abline(0, 1, col=1, lwd=2) 


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