Next: Universal kriging and generalized Up: Spatial and spatio-temporal data Previous: Working with shape files

#### Space-time smoothing in R

New versions of the mgcv library allow you to do space-time smoothing in gam() via tensor products of spatial and temporal bases, using the te() function. Thanks, Simon! (Simon Wood is creator and maintainer of the mgcv package and has done great work in devising, implementing, and making available computationally efficient smoothing techniques.) Here's an example from the help function of te(), where (v,w) would be the spatial coordinates, and u the time:

test2<-function(u,v,w,sv=0.3,sw=0.4)
{((pi**sv*sw)*(1.2*exp(-(v-0.2)^2/sv^2-(w-0.3)^2/sw^2)+
0.8*exp(-(v-0.7)^2/sv^2-(w-0.8)^2/sw^2)))*(u-0.5)^2*20
}
n <- 500
v <- runif(n);w<-runif(n);u<-runif(n)
f <- test2(u,v,w)
y <- f + rnorm(n)*0.2
# tensor product of a 2-d thin plate regression spline and 1-d cr spline
b <- gam(y~te(v,w,u,k=c(30,5),d=c(2,1),bs=c(tp,cr)))
op <- par(mfrow=c(2,2))
vis.gam(b,cond=list(u=0),color=heat,zlim=c(-0.2,3.5))
vis.gam(b,cond=list(u=.33),color=heat,zlim=c(-0.2,3.5))
vis.gam(b,cond=list(u=.67),color=heat,zlim=c(-0.2,3.5))
vis.gam(b,cond=list(u=1),color=heat,zlim=c(-0.2,3.5))
par(op)

Keywords: spatio-temporal, kriging, R, spatial

Chris Paciorek 2012-01-21