SVDsmooth {SpatioTemporal} | R Documentation |
Function that computes smooth functions for a data matrix with missing
values, as described in Fuentes et. al. (2006), or does cross validation to
determine a suitable number of basis functions. The function uses
SVDmiss
to complete the matrix and then computes smooth basis
functions by applying smooth.spline
to the
SVD of the completed data matrix.
SVDsmooth(X, n.basis = min(2, dim(X)[2]), date.ind = NULL, scale = TRUE, niter = 100, conv.reldiff = 0.001, df = NULL, spar = NULL, fnc = FALSE) SVDsmoothCV(X, n.basis, ...)
X |
Data matrix, with missing values marked by |
n.basis |
Number of smooth basis functions to compute, will be passed
as |
date.ind |
Vector giving the observation time of each row in
|
scale |
|
niter, conv.reldiff |
Controls convergence, passed to |
df, spar |
The desired degrees of freedom/smoothing parameter for the
spline, |
fnc |
If |
... |
Additional parameters passed to |
SVDsmoothCV
uses leave-one-column-out cross-validation; holding one column
out from X
, calling SVDsmooth
, and then regressing
the held out column on the resulting smooth functions. Cross-validation
statistics computed for each of these regressions include MSE, R-squared,
AIC and BIC. The weighted average (weighted by number of observations in the
colum) is then reported as CV-statistics.
Depends on the function:
SVDsmooth |
A matrix (if |
SVDsmoothCV |
A list of class
|
Paul D. Sampson and Johan Lindstrom
M. Fuentes, P. Guttorp, and P. D. Sampson. (2006) Using Transforms to Analyze Space-Time Processes in Statistical methods for spatio-temporal systems (B. Finkenstadt, L. Held, V. Isham eds.) 77-150
Other SVD for missing data: SVDmiss
,
calcSmoothTrends
, plot.SVDcv
,
print.SVDcv
,
updateTrend.STdata
Other data matrix: SVDmiss
,
createDataMatrix
,
estimateBetaFields
,
mesa.data.raw
Other SVDcv methods: plot.SVDcv
,
print.SVDcv
##create a data matrix t <- seq(0,4*pi,len=50) X.org <- cbind(cos(t),sin(2*t)) %*% matrix(rnorm(10),2,5) ##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 } ##compute two smooth basis functions res <- SVDsmooth(X, n.basis=2, niter=100) ##or compute the function that gives the basis functions res.fnc <- SVDsmooth(X, n.basis=2, niter=100, fnc=TRUE) ##and they are equal summary( res.fnc()-res ) ##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) } ##compute cross-validation for 1 to 4 basis functions res.cv <- SVDsmoothCV(X, n.basis=0:4, niter=100) ##study cross-validation results print(res.cv) summary(res.cv) ##plot cross-validation statistics plot(res.cv, sd=TRUE) ##boxplot of CV statistics for each column boxplot(res.cv) ##plot the BIC for each column plot(res.cv, "BIC", pairs=TRUE)