smooth.construct.msg.smooth.spec: Multidimensional Scaling for Generalized additive models -...

Description Usage Arguments Details Value Details Author(s) References Examples

Description

Provides smoothing methods for multidimensional scaling-based projections of the data.

Usage

1
2
## S3 method for class 'msg.smooth.spec'
smooth.construct(object, data, knots)

Arguments

object

a smooth specification object, usually generated by a term s(...,bs="ds",...). Note that xt object is needed, see Details.

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

IGNORED!

Details

Usage is split into two cases: (1) For geographical smooths of two coordinates, within-area distances with respect to the boundary are used to create a distance matrix that is then projected into as many dimensions as required. (2) General distance smoothing where distances are calculated between observations based on all covariates supplied using Euclidean or Mahalanobis distances.

In both cases smoothing is performed using Duchon splines (see Duchon.spline for more information).

Value

An object of class msg.smooth. In addition to the usual elements of a smooth class documented under smooth.construct, this object will contain an element named msg:

metric which metric was used to calculate the distance matrix. For geographical smoothing only "WAD" (within-area distance) is permitted. Otherwise, "euclidean" or "mahalanobis" are allowed
mds.obj result of running cmdscale on the starting grid (for geographical smoothing) or the data (general distance smoothing)
dim dimension of the MDS projection.
term auto-generated names of the variables in the MDS space (of the form "mds-i" where i indexes the data)
data the data projected into MDS space
Plus those extra elements as documented in Duchon.spline

Details

The constructor is not normally called directly, but is rather used internally by gam. To use for basis setup it is recommended to use smooth.construct2.

The specification object will contain information on how to handle the boundary and the dimension of the MDS projection. In particular, the boundary is specified as a list or data.frame with named x and y components. The MDS dimension projection is specified as an integer. See the example below for how these are specified to the user.

Note that for geographical smoothing the coordinates must be named x and y.

MDS dimension selection may be performed by finding the projection with the lowest GCV score. BEWARE: the GCV score is not necessarily monotonic in the number of dimensions. Automated dimension selection will appear in a later version of the package.

Author(s)

David L. Miller

References

Duchon, J. (1977) Splines minimizing rotation-invariant semi-norms in Solobev spaces. in W. Shemp and K. Zeller (eds) Construction theory of functions of several variables, 85-100, Springer, Berlin. Miller, DL and Wood, SN. (2014) Finite area smoothing with generalized distance splines. Environmental and Ecological Statistics 4, 715-731

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
### Not run
# load some data
data(wt2)

# create the sample
samp.ind<-sample(1:length(wt2$data$x),250)
wt2.samp<- list(x=wt2$data$x[samp.ind],
                y=wt2$data$y[samp.ind],
                z=wt2$data$z[samp.ind]+rnorm(250)*0.9)

# fit the model
b<-gam(z~s(x,y,bs="msg",k=200,xt=list(bnd=wt2$bnd,mds.dim=5)),data=wt2.samp)

# predict
pred.grid<-data.frame(expand.grid(x=seq(min(wt2$data$x),max(wt2$data$x),len=50),
                                  y=seq(min(wt2$data$y),max(wt2$data$y),len=50)))
x <- pred.grid$x; y <- pred.grid$y
ind<-inSide(wt2$bnd,x,y)
pred.grid<-pred.grid[ind,]
pred.mat<-matrix(NA,50,50)
pred.mat[ind]<-predict(b,pred.grid)

# plot what happened
par(mfrow=c(2,2))
true.mat<-wt2$true.matrix

image(true.mat,main="Truth",xlab="x",ylab="y",col=heat.colors(1000))
contour(true.mat,add=TRUE,labcex=0.3,lwd=0.5)
image(pred.mat,main="Fitted model",xlab="x",ylab="y",col=heat.colors(1000))
contour(pred.mat,add=TRUE,labcex=0.3,lwd=0.5)

plot(b$smooth[[1]]$msg$grid,pch=19,cex=0.3,
     main="Starting grid",xlab="x",ylab="y")

plot(b$smooth[[1]]$msg$mds.obj$points,pch=19,cex=0.3,
     main="Starting grid\n(MDS space)",xlab="x",ylab="y")

dill/msg documentation built on May 15, 2019, 8:30 a.m.