In general we understand under latent spatial effects the occurrence of spatial dependency in the observations, which might either be caused by spatial biases, similarities in the underlying sampling processes or unmeasured latent covariates, e.g. those that have not been quantified.

This package supports a range of different spatial effects, however they differ from another by their impact on the estimated prediction. Some effects simply add the spatial dependence as covariate, others make use of spatial random effects to account for spatial dependence in the predictions. By default these effects are added to each dataset as covariate or shared spatial field (e.g. SPDE). See details for an explanation of the available options.

## Usage

```
add_latent_spatial(
x,
method = "spde",
priors = NULL,
separate_spde = FALSE,
...
)
# S4 method for BiodiversityDistribution,character,ANY,logical
add_latent_spatial(x,method,priors,separate_spde,...)
```

## Arguments

- x
`distribution()`

(i.e.`BiodiversityDistribution`

) object.- method
A

`character`

describing what kind of spatial effect is to be added to the model. See details.- priors
A

`"Prior-List"`

object supplied to the latent effect. Relevant only for`engine_inla`

and`NULL`

equates the use of default priors.- separate_spde
A

`logical`

parameter indicating whether, in the case of SPDE effects, separate effects for each likelihood are being fitted. Default (`FALSE`

) uses a copy of the first added likelihood.- ...
Other parameters passed down

## Value

Adds latent spatial effect to a `distribution`

object.

## Details

There are several different options some of which depend on the engine used. In case a unsupported method for an engine is chosen this is modified to the next similar method

Available are:

* `"spde"`

- stochastic partial differential equation (SPDE) for
`engine_inla`

and `engine_inlabru`

. SPDE effects aim at capturing the
variation of the response variable in space, once all of the covariates are
accounted for. Examining the spatial distribution of the spatial error can
reveal which covariates might be missing. For example, if elevation is
positively correlated with the response variable, but is not included in
the model, we could see a higher posterior mean in areas with higher
elevation. Note that calculations of SPDE's can be computationally costly.

`"car"`

- conditional autocorrelative errors (CAR) for`engine_inla`

. Not yet implemented in full.`"kde"`

- additional covariate of the kernel density of input point observations.`"poly"`

- spatial trend correction by adding coordinates as polynominal transformation. Available for all Engines.`"nnd"`

- nearest neighbour distance. This function calculates the euclidean distance from each grid cell to the nearest other grid cell with values. Applied across all datasets in the`BiodiversityDistribution`

) object. Available for all Engines.

## References

Fletcher, R., & Fortin, M. (2018). Spatial ecology and conservation modeling. Springer International Publishing.

Mendes, P., Velazco, S. J. E., de Andrade, A. F. A., & Júnior, P. D. M. (2020). Dealing with overprediction in species distribution models: How adding distance constraints can improve model accuracy. Ecological Modelling, 431, 109180.

## Examples

```
if (FALSE) {
distribution(background) |> add_latent_spatial(method = "poly")
}
```