Learn R Programming

SpatioTemporal (version 1.1.7)

SVDmiss: Missing Data 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

SVDmiss(X, niter = 25, ncomp = min(4, dim(X)[2]),
    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 met.

ncomp

Number of SVD components to use in the reconstruction (>0).

conv.reldiff

Assume the iterative procedure has converged when the relative difference between two consecutive iterations is less than conv.reldiff.

Value

A list with the following components:

Xfill

The completed data matrix with missing values replaced by fitting the data to the ncomp most important svd components

svd

The result of svd on the completed data matrix, i.e. svd(Xfill)

status

A vector of status variables: diff, the absolute difference between the two last iterations; rel.diff, the relative difference; n.iter, the number of iterations; and max.iter, the requested maximum number of iterations.

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<e4>dt, L. Held, V. Isham eds.) 77-150

See Also

Other data matrix: createDataMatrix, estimateBetaFields, mesa.data.raw, SVDsmooth, SVDsmoothCV

Other SVD for missing data: boxplot.SVDcv, calcSmoothTrends, plot.SVDcv, print.SVDcv, summary.SVDcv, SVDsmooth, SVDsmoothCV, updateSTdataTrend, updateTrend, updateTrend.STdata, updateTrend.STmodel

Examples

Run this code
# NOT RUN {
##create a data matrix
t <- seq(0,4*pi,len=50)
X.org <- cbind(cos(t),sin(2*t)) %*% 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

##Ensure that we have complet columns/rows
while( any(rowSums(is.na(X))==dim(X)[2]) || any(colSums(is.na(X))==dim(X)[1]) ){
  X <- X.org + .25*rnorm(length(X.org))
  X[runif(length(X))<.25] <- NA
}

#run the missing data svd
res <- SVDmiss(X, niter=100, ncomp=2)
#look at the status
res$status
#plot the first four columns of the data matrix
par(mfrow=c(2,2))
for(i in 1:4){
  plot(t, X[,i])
  lines(t, res$Xfill[,i])
  lines(t, X.org[,i], col=2)
}
# }

Run the code above in your browser using DataLab