smooth.construct.sos.smooth.spec {mgcv}R Documentation

Splines on the sphere

Description

gam can use isotropic smooths on the sphere, via terms like s(la,lo,bs="sos",m=2,k=100). There must be exactly 2 arguments to such a smooth. The first is taken to be latitude (in degrees) and the second longitude (in degrees). m (default 1) is an integer in the range 0 to 4 determining the order of the penalty used. For m>0, (m+2)/2 is the penalty order, so m=2 is the equivalent to the usual second derivative penalty. m=0 signals to use the 2nd order spline on the sphere, computed by Wendelberger's (1981) method. m = -1 results in a Duchon.spline being used (with m=2 and s=1/2).

k (default 50) is the basis dimension.

Usage

## S3 method for class 'sos.smooth.spec'
smooth.construct(object, data, knots)
## S3 method for class 'sos.smooth'
Predict.matrix(object, data)

Arguments

object a smooth specification object, usually generated by a term s(...,bs="sos",...).
data a list containing just the data (including any by variable) required by this term, with names corresponding to object$term (and object$by). The by variable is the last element.
knots a list containing any knots supplied for basis setup — in same order and with same names as data. Can be NULL

Details

For m>0, the smooths implemented here are based on the pseudosplines on the sphere of Wahba (1981) (there is a correction of table 1 in 1982, but the correction has a misprint in the definition of A — the A given in the 1981 paper is correct). For m=0 then a second order spline on the sphere is used which is the analogue of a second order thin plate spline in 2D: the computation is based on Chapter 4 of Wendelberger, 1981. Optimal low rank approximations are obtained using exactly the approach given in Wood (2003).

Note that the null space of the penalty is always the space of constant functions on the sphere, whatever the order of penalty.

Value

An object of class "sos.smooth". In addition to the usual elements of a smooth class documented under smooth.construct, this object will contain:
Xu A matrix of the unique covariate combinations for this smooth (the basis is constructed by first stripping out duplicate locations).
UZ The matrix mapping the t.p.r.s. parameters back to the parameters of a full thin plate spline.

Author(s)

Simon N. Wood simon.wood@r-project.org, with help from Grace Wahba (m=0 case) and Jean Duchon (m = -1, case).

References

Wahba, G. (1981) Spline interpolation and smoothing on the sphere. SIAM J. Sci. Stat. Comput. 2(1):5-16

Wahba, G. (1982) Erratum. SIAM J. Sci. Stat. Comput. 3(3):385-386.

Wendelberger, J. (1981) PhD Thesis, University of Winsconsin.

Wood, S.N. (2003) Thin plate regression splines. J.R.Statist.Soc.B 65(1):95-114

Examples

set.seed(0)
n <- 400

f <- function(la,lo) { ## a test function...
  sin(lo)*cos(la-.3)
}

## generate with uniform density on sphere...  
lo <- runif(n)*2*pi-pi ## longitude
la <- runif(3*n)*pi-pi/2
ind <- runif(3*n)<=cos(la)
la <- la[ind];
la <- la[1:n]

ff <- f(la,lo)
y <- ff + rnorm(n)*.2 ## test data

## generate data for plotting truth...
lam <- seq(-pi/2,pi/2,length=30)
lom <- seq(-pi,pi,length=60)
gr <- expand.grid(la=lam,lo=lom)
fz <- f(gr$la,gr$lo)
zm <- matrix(fz,30,60)

require(mgcv)
dat <- data.frame(la = la *180/pi,lo = lo *180/pi,y=y)

method <- "GCV.Cp";m <- 3

## fit spline on sphere model...
bp <- gam(y~s(la,lo,bs="sos",k=60),data=dat)

## pure knot based alternative...
ind <- sample(1:n,100)
bk <- gam(y~s(la,lo,bs="sos",k=60),knots=list(la=dat$la[ind],lo=dat$lo[ind]),data=dat)

b <- bp

cor(fitted(b),ff)

## plot results and truth...

pd <- data.frame(la=gr$la*180/pi,lo=gr$lo*180/pi)
fv <- matrix(predict(b,pd),30,60)

par(mfrow=c(2,1),mar=c(4,4,1,1))
contour(lom,lam,t(zm))
contour(lom,lam,t(fv))


[Package mgcv version 1.7-3 Index]