| specifyISDM {PointedSDMs} | R Documentation |
R6 class for creating a startISDM object.
Description
A data object containing the data and the relevant information about the integrated model. The function startISDM acts as a wrapper in creating one of these objects. The output of this object has additional functions within the object which allow for further specification and customization of the integrated model.
Methods
Public methods
Method help()
Function to provide documentation for a specifyISDM object.
Usage
specifyISDM$help(...)
Arguments
...Not used
Returns
Documentation.
Method print()
Prints the datasets, their data type and the number of observations, as well as the marks and their respective families.
Usage
specifyISDM$print(...)
Arguments
...Not used.
Method plot()
Makes a plot of the points surrounded by the boundary of the region where they were collected. The points may either be plotted based on which dataset they come from, or which species group they are part of (if speciesName is non-NULL in intModel).
Usage
specifyISDM$plot(datasetNames, Boundary = TRUE, ...)
Arguments
datasetNamesName of the datasets to plot. If this argument is missing, the function will plot all the data available to the model.
BoundaryLogical: should a boundary (created using the
Meshobject) be used in the plot. Defaults toTRUE....Not used.
Returns
A ggplot object.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
library(ggplot2)
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
Projection = proj,
responsePA = 'Present')
#Create plot of data
organizedData$plot()
}
}
Method addBias()
Function used to add additional spatial fields (called bias fields) to a selected dataset present in the integrated model. Bias fields are typically used to account for sampling biases in opportunistic citizen science data in the absence of any covariate to do such.
Usage
specifyISDM$addBias( datasetNames = NULL, allPO = FALSE, biasField = NULL, copyModel = TRUE, shareModel = FALSE, temporalModel = list(model = "ar1") )
Arguments
datasetNamesA vector of dataset names (class
character) for which a bias field needs to be added to. IfNULL(default), thenallPOhas to beTRUE.allPOLogical: should a bias field be added to all datasets classified as presence only in the integrated model. Defaults to
FALSE.biasFieldAn
inla.spdeobject used to describe the bias field. Defaults toNULLwhich usesinla.spde2.maternto create a Matern model for the field.copyModelCreate copy models for all the of the datasets specified with either
datasetNamesorallPO. The first dataset in the vector will have its own spatial effect, and the other datasets will "copy" the effect with shared hyperparameters. Defaults toTRUE.shareModelShare a bias field across the datasets specified with
datasetNames. Defaults toFALSE.temporalModelList of model specifications given to the control.group argument in the time effect component. Defaults to
list(model = 'ar1'); seecontrol.groupfrom the INLA package for more details.temporalNameneeds to be specified inintModelprior.
Returns
A bias field to the model.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
Projection = proj,
responsePA = 'Present')
#Add bias field to eBird records
organizedData$addBias(datasetNames = 'eBird')
}
}
Method updateFormula()
Function used to update the formula for a selected observation model. The function is designed to work similarly to the generic update formula, and should be used to thin terms out of a process from the full model specified in intModel. The function also allows the user to add their own formula to the model, such that they can include non-linear components in the model. The function can also be used to print out the formula for a process by not specifying the Formula or newFormula arguments.
Usage
specifyISDM$updateFormula( datasetName = NULL, Formula, newFormula, processLevel = FALSE )
Arguments
datasetNameName of the dataset (class
character) for which the formula needs to be changed.FormulaAn updated formula to give to the process. The syntax provided for the formula in this argument should be identical to the formula specification as in base R. Should be used to thin terms out of a formula but could be used to add terms as well. If adding new terms not specified in
intModel, remember to add the associated component using.$changeComponentsas well.newFormulaCompletely change the formula for a process – primarily used to add non-linear components into the formula. Note: all terms need to be correctly specified here.
processLevelLogical argument: if
TRUEchanges the formulas for all of the processes in a dataset. Defaults toFALSE.
Returns
An updated formula.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj,
responsePA = 'Present',
pointsSpatial = 'individual')
#Remove Forest from eBird
organizedData$updateFormula(datasetName = 'eBird', Formula = ~ . - Forest)
#Add some scaling to Forest for Parks
organizedData$updateFormula('Parks', newFormula = ~ I(. +(Forest+1e-6)*scaling))
#Now dd scaling to components
organizedData$changeComponents(addComponent = 'scaling')
}
}
Method changeComponents()
Function to add and specify custom components to model, which are required by inlabru. The main purpose of the function is to re-specify or completely change components already in the model, however the user can also add completely new components to the model as well. In this case, the components need to be added to the correct formulas in the model using the .$updateFormula function. If addComponent and removeComponent are both missing, the function will print out the components to be supplied to inlabru's bru function.
Usage
specifyISDM$changeComponents(addComponent, removeComponent, print = TRUE)
Arguments
addComponentComponent to add to the integrated model. Note that if the user is re-specifying a component already present in the model, they do not need to remove the old component using
removeComponent.removeComponentComponent (or just the name of a component) present in the model which should be removed.
printLogical: should the updated components be printed. Defaults to
TRUE.
Returns
An updated components list.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Remove Forest from components
organizedData$changeComponents(removeComponent = 'Forest')
}
}
Method priorsFixed()
Function to change priors for the fixed (and possibly random) effects of the model.
Usage
specifyISDM$priorsFixed( Effect, datasetName = NULL, mean.linear = 0, prec.linear = 0.001 )
Arguments
EffectName of the fixed effect covariate to change the prior for. Can take on
'intercept', which will change the specification for an intercept (specified by one ofspeciesordatasetName).datasetNameName of the dataset for which the prior of the intercept should change (if fixedEffect = 'intercept'). Defaults to
NULLwhich will change the prior effect of the intercepts for all the datasets in the model.mean.linearMean value for the prior of the fixed effect. Defaults to
0.prec.linearPrecision value for the prior of the fixed effect. Defaults to
0.001.
Returns
New priors for the fixed effects.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present',
pointsSpatial = 'individual')
#Add prior to Forest
organizedData$priorsFixed(Effect = 'Forest', mean.linear = 2, prec.linear = 0.1)
}
}
Method specifySpatial()
Function to specify random fields in the model using penalizing complexity (PC) priors for the parameters.
Usage
specifyISDM$specifySpatial( sharedSpatial = FALSE, datasetName, Bias, PC = TRUE, Remove = FALSE, ... )
Arguments
sharedSpatialLogical: specify the shared spatial field in the model. Requires
pointsSpatial == 'shared'inintModel. Defaults toFALSE.datasetNameName of which of the datasets' spatial fields to be specified. Requires
pointsSpatial = 'individual'inintModel.BiasName of the dataset for which the bias field to be specified.
PCLogical: should the Matern model be specified with pc priors. Defaults to
TRUE, which usesinla.spde2.pcmaternto specify the model; otherwise usesinla.spde2.matern.RemoveLogical: should the chosen spatial field be removed. Requires one of
sharedSpatial,species,markorbiasto be non-missing, which chooses which field to remove....Additional arguments used by INLA's
inla.spde2.pcmaternorinla.spde2.maternfunction, dependent on the value ofPC.
Returns
A new model for the spatial effects.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Specify the shared spatial field
organizedData$specifySpatial(sharedSpatial = TRUE,
prior.range = c(1,0.001),
prior.sigma = c(1,0.001))
}
}
Method changeLink()
Function used to change the link function for a given process.
Usage
specifyISDM$changeLink(datasetName, Link)
Arguments
datasetNameName of the dataset for which the link function needs to be changed.
LinkName of the link function to add to the process. If missing, will print the link function of the specified dataset.
Returns
A new link function for a process.
Examples
\dontrun{
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Specify the shared spatial field
organizedData$changeLink('Parks', 'logit')
}
}
Method spatialBlock()
Function to spatially block the datasets, which will then be used for model cross-validation with blockedCV. See the spatialBlock function from blockCV for how the spatial blocking works and for further details on the function's arguments.
Usage
specifyISDM$spatialBlock(k, rows_cols, plot = FALSE, seed = 1234, ...)
Arguments
kInteger value reflecting the number of folds to use.
rows_colsInteger value by which the area is divided into longitudinal and latitudinal bins.
plotPlot the cross-validation folds as well as the points across the boundary. Defaults to
FALSE.seedSeed used by blockCV's
spatialBlockto make the spatial blocking reproducible across different models. Defaults to1234....Additional arguments used by blockCV's
spatialBlock.
Returns
If plot = TRUE, a plot of the grid.
Examples
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present',
pointsSpatial = 'individual')
#Specify the spatial block
organizedData$spatialBlock(k = 2, rows = 2, cols = 1, plot = FALSE)
}
Method addSamplers()
Function to add an integration domain for the PO datasets.
Usage
specifyISDM$addSamplers(datasetName, Samplers)
Arguments
datasetNameName of the dataset for the samplers.
SamplersA
Spatial*object representing the integration domain.
Returns
New samplers for a process.
Method specifyRandom()
Function to specify the models and priors for the random effects included in the model.
Usage
specifyISDM$specifyRandom( temporalModel = list(model = "ar1"), copyModel = list(beta = list(fixed = FALSE)), copyBias = list(beta = list(fixed = FALSE)) )
Arguments
temporalModelList of model specifications given to the control.group argument in the time effect component. Defaults to
list(model = 'ar1'); seecontrol.groupfrom the INLA package for more details.copyModelList of model specifications given to the hyper parameters for the
"copy"model. Defaults tolist(beta = list(fixed = FALSE)).copyBiasList of model specifications given to the hyper parameters for the
"copy"bias model. Defaults tolist(beta = list(fixed = FALSE)).
Returns
An updated component list.
Method new()
Usage
specifyISDM$new( data, projection, Inlamesh, initialnames, responsecounts, responsepa, pointcovariates, trialspa, spatial, intercepts, spatialcovariates, boundary, ips, temporal, temporalmodel, offset, copymodel, formulas )
Method samplingBias()
Usage
specifyISDM$samplingBias(datasetName, Samplers)
Examples
## ------------------------------------------------
## Method `specifyISDM$plot`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
library(ggplot2)
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
Projection = proj,
responsePA = 'Present')
#Create plot of data
organizedData$plot()
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$addBias`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
Projection = proj,
responsePA = 'Present')
#Add bias field to eBird records
organizedData$addBias(datasetNames = 'eBird')
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$updateFormula`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj,
responsePA = 'Present',
pointsSpatial = 'individual')
#Remove Forest from eBird
organizedData$updateFormula(datasetName = 'eBird', Formula = ~ . - Forest)
#Add some scaling to Forest for Parks
organizedData$updateFormula('Parks', newFormula = ~ I(. +(Forest+1e-6)*scaling))
#Now dd scaling to components
organizedData$changeComponents(addComponent = 'scaling')
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$changeComponents`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Remove Forest from components
organizedData$changeComponents(removeComponent = 'Forest')
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$priorsFixed`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present',
pointsSpatial = 'individual')
#Add prior to Forest
organizedData$priorsFixed(Effect = 'Forest', mean.linear = 2, prec.linear = 0.1)
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$specifySpatial`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Specify the shared spatial field
organizedData$specifySpatial(sharedSpatial = TRUE,
prior.range = c(1,0.001),
prior.sigma = c(1,0.001))
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$changeLink`
## ------------------------------------------------
## Not run:
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present')
#Specify the shared spatial field
organizedData$changeLink('Parks', 'logit')
}
## End(Not run)
## ------------------------------------------------
## Method `specifyISDM$spatialBlock`
## ------------------------------------------------
if (requireNamespace('INLA')) {
#Get Data
data("SolitaryTinamou")
proj <- "+proj=longlat +ellps=WGS84"
data <- SolitaryTinamou$datasets
mesh <- SolitaryTinamou$mesh
mesh$crs <- proj
Forest <- terra::rast(
system.file(
'extdata/SolitaryTinamouCovariates.tif',
package = "PointedSDMs"))$Forest
#Set model up
organizedData <- startISDM(data, Mesh = mesh,
spatialCovariates = Forest,
Projection = proj, responsePA = 'Present',
pointsSpatial = 'individual')
#Specify the spatial block
organizedData$spatialBlock(k = 2, rows = 2, cols = 1, plot = FALSE)
}