Learn R Programming

SpatioTemporal (version 0.9.2)

SVD.smooth: Smooth Basis Functions for Data Matrix with Missing Values

Description

Function that computes smooth functions for a data matrix with missing values, as described in Fuentes et. al. (2006). The function uses SVD.miss to complete the matrix and then computes smooth basis functions by applying smooth.spline to the svd of the completed data matrix.

Usage

SVD.smooth(data, n.basis, date.ind=NA, scale.data=TRUE,
           niter=100, conv.reldiff=0.001, df=NULL, spar=NULL)

Arguments

data
Data matrix, with missing values marked by NA.
n.basis
Number of smooth basis functions to compute, will be passed as ncomp to SVD.miss.
date.ind
Vector giving the observation time of each row in data, used as x in smooth.spline when computing the smooth basis functions. If set to NA it will try t
scale.data
If TRUE, will use scale to scale the data matrix before calling SVD.miss.
niter, conv.reldiff
Controls convergence for SVD.miss.
df, spar
The desired degrees of freedom/smoothing parameter for the spline, see smooth.spline

Value

  • The function returns a matrix where each column is a smooth basis function based on the svd of the completed data matrix. The left most column contains the smooth of the most important svd.

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.miss, svd, and smooth.spline.

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

#compute two smooth basis functions
res <- SVD.smooth(X, n.basis=2, niter=100)

#plot the two smooth basis functions
par(mfcol=c(3,2),mar=c(4,4,.5,.5))
plot(t,res[,1],ylim=range(res),type="l")
lines(t,res[,2],col=2)
#and some of the data fitted to the smooths
for(i in 1:5){
  plot(t,X[,i])
  lines(t,predict.lm(lm(X[,i]~res),data.frame(res)))
  lines(t,X.org[,i],col=2)
}

Run the code above in your browser using DataLab