geostatData: Prepare observations and covariates for a geostatistical...

View source: R/0gm.R

geostatDataR Documentation

Prepare observations and covariates for a geostatistical model

Description

Extracts covariates at observation locations, aligns covariate rasters to a prediction grid, and returns the data structures used by glgm and lgm.

Usage

geostatData(formula, data, grid, covariates, buffer = 0)
## S3 method for class 'SpatVector'
geostatData(formula, data, grid, covariates, buffer = 0)
## S3 method for class 'SpatRaster'
geostatData(formula, data, grid = data, covariates = NULL, buffer = 0)
## Default S3 method:
geostatData(formula, data, ...)

Arguments

formula

Model formula. Names on the right-hand side are taken from data when present and otherwise extracted from covariates.

data

A SpatVector of point observations, or a SpatRaster of observations on a lattice.

grid

A SpatRaster giving the prediction grid (and the lattice for the spatial random effect). For the SpatRaster method this defaults to data.

covariates

A SpatRaster, a multi-layer SpatRaster, or a list of SpatRasters. Layer or list names must match names in formula.

buffer

Extra space padded around grid, passed to the same argument of squareRaster.

...

Ignored. The default method reports an error if data is not a SpatVector or SpatRaster.

Value

A list with

data

For SpatVector input, a SpatVector with extracted covariates and a space cell identifier. For SpatRaster input, a data.frame of cell values.

grid

The (possibly buffered) square SpatRaster used as the model lattice.

covariates

A data.frame of covariate values on grid.

formula

Returned only by the SpatRaster method. Equal to the supplied formula, or a rewritten formula when log-offsets are aggregated.

See Also

glgm, lgm, squareRaster

Examples

data("loaloa")
loaloa = unwrap(loaloa)
elevationLoa = unwrap(elevationLoa)
eviLoa = unwrap(eviLoa)

res = geostatData(
    y ~ elev + evi,
    data = loaloa,
    covariates = list(elev = elevationLoa, evi = eviLoa),
    grid = squareRaster(loaloa, cells = 20, buffer = 1e4)
)
names(res)
names(res$data)
res$grid

geostatsp documentation built on Sept. 10, 2026, 5:10 p.m.