Learn R Programming

SpatioTemporal (version 0.9.2)

SVD.miss: Replace Missing Values in a Data Matrix Using Iterative svd.

Description

Function that completes a data matrix using iterative svd as described in Fuentes et. al. (2006). The function iterates between computing the svd for the matrix and replacing the missing values by linear regression of the columns onto the first ncomp svd components. As initial replacement for the missing values regression on the column averages are used. The function will fail if entire rows and/or columns are missing from the data matrix.

Usage

SVD.miss(X, niter = 25, ncomp = 4, conv.reldiff = 0.001)

Arguments

X
Data matrix, with missing values marked by NA.
niter
Maximum number of iterations to run before exiting, Inf will run until the conv.reldiff criteria is fulfilled.
ncomp
Number of svd components to use in the reconstruction.
conv.reldiff
Assume the iterative procedure has converged when the relative difference between two consecutive iterations is less than conv.reldiff.

Value

  • Returns a list with the following components
  • XfillThe completed data matrix with missing values replaced by fitting the data to the ncomp most important svd components
  • svdThe result of svd on the completed data matrix, i.e. svd(Xfill)
  • statusA vector of status variables: diff contains the absolute difference between the two last iterations, rel.diff contains the relative difference, and the number of iterations run are contained in n.iter

encoding

latin1

References

M. Fuentes, P. Guttorp, and P. D. Sampson. (2006) Using Transforms to Analyze Space-Time Processes in Statistical methods for spatio-temporal systems (B. Finkenst�dt{Finkenstadt}, L. Held, V. Isham eds.) 77-150

See Also

See also SVD.smooth, SVD.smooth.cv, and svd.

create.data.matrix can be used to create a data matrix from a mesa.data object.

Used by calc.smooth.trends to compute smooth trends for mesa.data.

Examples

Run this code
#create a data matrix
t <- seq(0,4*pi,len=50)
X.org <- matrix(cbind(cos(t),sin(2*t)),length(t),2) %*%
  matrix(rnorm(20),2,10)
#add some normal errors
X <- X.org + .25*rnorm(length(X.org))
#and mark some data as missing
X[runif(length(X))<.25] <- NA

#run the missing data svd
res <- SVD.miss(X, niter=100, ncomp=2)
#look at the status
res$status
#plot the first column of the data matrix
plot(t,X[,1])
lines(t,res$Xfill[,1])
lines(t,X.org[,1],col=2)
if( max(abs(res$Xfill-X),na.rm=TRUE) > 1e-10 ){
  stop("SVD.miss: Points not interpolated")
}

Run the code above in your browser using DataLab