runSALSA2D | R Documentation |
This function fits a spatially adaptive two dimensional smooth of spatial coordinates with knot number and location selected by SALSA.
runSALSA2D(
model,
salsa2dlist,
d2k,
k2k,
splineParams = NULL,
chooserad = FALSE,
panels = NULL,
suppress.printout = FALSE,
tol = 0,
plot = FALSE,
basis = "gaussian",
initialise = TRUE,
initialKnots = NULL,
initialKnPos = NULL,
logfile = FALSE
)
model |
A model with no spatial smooth |
salsa2dlist |
Vector of objects required for |
d2k |
(n x k) Matrix of distances between all data points in |
k2k |
(k x k) Matrix of distances between all valid knot locations specified in |
splineParams |
(default |
chooserad |
logical flag. If FALSE (default) then the range parameter of the basis is chosen after the knot location and number. If TRUE, the range is assessed at every iteration of a knot move/add/drop. |
panels |
Vector denoting the panel identifier for each data point (if robust standard errors are to be calculated). Defaults to data order index if not given. |
suppress.printout |
(Default: |
tol |
Numeric stating the tolerance for the fitness Measure. e.g. tol=2 with AIC would only allow changes to be made if the AIC score improves by 2 units. |
plot |
logical stating whether to print out the chosen knot locations at each iteration. |
basis |
One of 'gaussian' (default) or 'exponential'. Specifys what kind of local radial function to use ( |
initialise |
(Defauls: |
initialKnots |
c x 2 dataframe or matrix specifying the coordinates of the starting locations of knots. c is the number of initial knots (should match what is specified in |
initialKnPos |
vector of length c denoting the rows of the |
logfile |
(Default: |
The object salsa2dlist
contains parameters for the runSALSA2D
function.
fitnessMeasure
. The criterion for selecting the ‘best’ model. Available options: AIC, AIC_c, BIC, QIC_b, cv.gamMRSea (use cv.opts in salsa2dlist to specify seed, folds, cost function (Defaults: cv.opts=list(cv.gamMRSea.seed=357, K=10, cost=function(y, yhat) mean((y - yhat)^2))
)
knotgrid
. A set of 'k' knot locations (k x 2 matrix or dataframe of coordinates). May be made using getKnotgrid
.
startknots
. Starting number of knots (initialised as spaced filled locations).
minKnots
. Minimum number of knots to be tried.
maxKnots
. Maximum number of knots to be tried.
gap
. The minimum gap between knots (in unit of measurement of coordinates).
interactionTerm
. Specifies which term in baseModel
the spatial smooth will interact with. If NULL
no interaction term is fitted.
cv.opts
Used if fitnessMeasure = cv.gamMRSea
. See above for specification.
This function returns the best model bestModel
and the fitness statistic for this model fitStat
The spline paramater object that is returned as part of the model object now contains a list in the first element (previously reserved for the spatial component). This list contains the objects required for the SALSA2D fitting process:
knotDist |
Matrix of knot to knot distances (k x k). May be Euclidean or geodesic distances. Must be square and the same dimensions as |
radii |
Sequence of range parameters for the CReSS basis from local (small) to global (large). Determines the range of the influence of each knot. |
dist |
Matrix of distances between data locations and knot locations (n x k). May be Euclidean or geodesic distances. Euclidean distances created using |
datacoords |
Coordinates of the data locations |
response |
Vector of response data for the modelling process |
knotgrid |
Grid of legal knot locations. |
minKnots |
Minimum number of knots to be tried. |
maxKnots |
Maximum number of knots to be tried. |
gap |
Minimum gap between knots (in unit of measurement of |
radiusIndices |
Vector of length startKnots identifying which radii ( |
knotPos |
Index of knot locations. The index identifies which knots (i.e. which rows) from |
Lindesay Scott-Hayward (University of St Andrews), Cameron Walker (University of Auckland)
Scott-Hayward, L.; M. Mackenzie, C.Donovan, C.Walker and E.Ashe. Complex Region Spatial Smoother (CReSS). Journal of computational and Graphical Statistics. 2013. doi: 10.1080/10618600.2012.762920
Scott-Hayward, L.. Novel Methods for species distribution mapping including spatial models in complex regions: Chapter 5 for SALSA2D methods. PhD Thesis, University of St Andrews. 2013
# load data
data(ns.data.re)
# load prediction data
data(ns.predict.data.re)
# load knot grid data
data(knotgrid.ns)
#set some input info for SALSA
ns.data.re$response<- ns.data.re$birds
# make distance matrices for datatoknots and knottoknots
distMats<-makeDists(cbind(ns.data.re$x.pos, ns.data.re$y.pos), na.omit(knotgrid.ns))
# set initial model without the spatial term
# (so all other non-spline terms)
initialModel<- glm(response ~ 1 + offset(log(area)),
family='quasipoisson', data=ns.data.re)
# make parameter set for running salsa2d
# I have chosen a gap parameter of 1000 (in metres) to speed up the process.
# Note that this means there cannot be two knots within 1000m of each other.
salsa2dlist<-list(fitnessMeasure = 'QICb',
knotgrid = na.omit(knotgrid.ns),
startKnots = 6,
minKnots = 2,
maxKnots = 20,
gap=1000)
salsa2dOutput<-runSALSA2D(initialModel,
salsa2dlist,
d2k=distMats$dataDist,
k2k=distMats$knotDist)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.