smooth.construct.dm.smooth.spec: Distance matrix smoothing

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

Description

Provides smoothing methods for multidimensional scaling-based projections of a given distance matrix. The matrix can be supplied or a function to calculate the distances can be supplied.

Usage

1
2
## S3 method for class 'dm.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

Smoothing is performed using Duchon splines (see Duchon.spline for more information).

Value

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

mds.obj

result of running cmdscale on the data.

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.

When specifying the model extra arguments must be supplied by the xt argument.

D

a distance matrix

mds.dim

dimension of the MDS projection

grid

a grid over the covariates to use as a base for the MDS configuration. If NULL the sample points will be used. See below for details.

dist_fn

function to calculate distances, see below

**Write something here about grid**

dist_fn takes one argument, a data.frame of locations of the data, as provided as the covariates used in the smooth.

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
## Not run: 
# test this works with the wt2 example from msg
library(msg)
data(wt2)

## using a pre-built D matrix
# 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)
mds.dim<-5
custom_dist_fn <- function(x){
  msg:::create_distance_matrix(x$x,x$y,wt2$bnd,faster=0)
}

grid_obj <- msg:::create_refgrid(wt2$bnd,120)

grid_obj$nrefx <- grid_obj$nrefy <- NULL
grid_obj <- as.data.frame(grid_obj)


b.dm <- gam(z~s(x, y, bs="dm", k=200,
                xt=list(dist_fn=custom_dist_fn, mds.dim=5, grid=grid_obj)),
            data=wt2.samp)


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

## End(Not run)

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