makeDists: Make Euclidean distance matrices for use in CReSS and SALSA...

View source: R/functions.R

makeDistsR Documentation

Make Euclidean distance matrices for use in CReSS and SALSA model frameworks

Description

[Experimental]

This function makes two Euclidean distance matrices. One for the distances between all spatial observations and all spatial knot locations. The other, if specified, is the distances between knot locations. It is experimental owing to the addition of the creation of infinity-block distance matrices. The original functionality is unchanged.

Usage

makeDists(
  datacoords,
  knotcoords,
  knotmat = TRUE,
  polys = NULL,
  type = "A",
  plot.transition = FALSE,
  grid.dim = c(100, 100)
)

Arguments

datacoords

Coordinates of the data locations. If a design matrix interaction is required, add a third column containing the factor level.

knotcoords

Coordinates of the legal knot locations. If a design matrix interaction is required, add a third column containing the factor level for each knot location.

knotmat

(default=TRUE). Should a matrix of knot-knot distances be created

polys

(default=NULL). If geodesic distances are to be calculated, provide a list of polygons defining exclusion areas.

type

(default='A'). One of 'A' or 'B'. 'A' is used when the knotcoords are a subset of datacoords AND the attributes of knotcoords give the index of points from datacoords (as happens if getKnotgrid() is used). 'B' is used for prediction (when datacoords is a prediction grid and so knotcoords is not a subset) or when the knotgrid was not generated using getKnotgrid().

plot.transition

(default=TRUE). Logical stating whether to plot the transition matrix. Useful to see if the boundaries are being obeyed.

grid.dim

This is a vector of length two which specifies the dimesions of the grid used to create the transition matrix (default c(100, 100). If the transition matrix shows that boundaries are being ignored, the grid dimensions will need to increase. However, increasing the grid, whilst improving accuracy, also increases computational time.

Details

The data-knot matrix is used in the CReSS basis and the knot-knot matrix is used in SALSA to determine where a nearest knot to ‘move’ should be.

If three columns are provided for datacoords and knotcoords the matrix returned has infinity for distances between knots and data associated with differing factor levels.

Examples

# load data
data(ns.data.re)
# load knot grid data
data(knotgrid.ns)
 
# make distance matrices for datatoknots and knottoknots
distMats<-makeDists(cbind(ns.data.re$x.pos, ns.data.re$y.pos), na.omit(knotgrid.ns))

# ~~~~~~~~~~~~~~~~~~
# Example with block-infinity distance matrix
data(nysted.analysisdata)
myknots <- selectFctrKnots(nysted.analysisdata[,c('x.pos', 'y.pos', 'impact')], nk=150)

dists <- makeDists(datacoords = nysted.analysisdata[,c('x.pos', 'y.pos', 'impact')], 
                   knotcoords = myknots, 
                   knotmat = TRUE)

lindesaysh/MRSea documentation built on April 5, 2024, 4:39 p.m.