Learn R Programming

stopp (version 0.2.3)

stcov: Create stcov objects and interpolate spatio-temporal covariates on a regular grid

Description

This function interpolates the covariate values observed at some observed sites to a regular grid. The imput object should be either a matrix or a dataframe with four columns: x, y, t, and the covariate values, named as the covariate later called in the model formula (see stppm). The interpolation is performed through Inverse Distance Weighting (IDW). See the Details.

Usage

stcov(
  x,
  interp = TRUE,
  nx = NULL,
  mult = 1,
  p = 81,
  names = NULL,
  verbose = FALSE
)

Value

A stpm object, to be imputed as list object in stppm.

Arguments

x

A data.frame with four columns, containing the spatio-temporal coordinates and the covariate values.

interp

Logical value indicating whether to interpolate the covariate on a regular grid. Default to TRUE.

nx

Number of coordinates to generate for each dimention. The default is floor((mult * nrow(cov)) ^ (1/3)).

mult

The multiplicand of the number of points in the default for nx.

p

Power of IDW distances.

names

Factor string to name the covariate.

verbose

Default to FALSE. If TRUE, the elapsed minutes are printed.

Author

Nicoletta D'Angelo

Details

The function builds a regular grid with equispaced values along the three coordinates and interpolates the covariate values at the new locations. The interpolation at a point location \(x_k\) is performed through the inverse-distance weighting smoothing procedure of the covariate values \(Z(x_j)\) at their sampling locations \(j=1, \ldots, J\). In such a case, the smoothed value at location \(x_k\) is $$Z(x_k) = \frac{\sum_j w_j Z(x_j)}{\sum_j w_j},$$ where the weight \(w_j\) is the \(j\)-th element of the inverse \(p\)th powers of distance, $$\textbf{w}=\{w_j\}_{j=1}^J=\{\frac{1}{d(x_k-x_j)^p}\}_{j=1}^J,$$ with $$d(x_k-x_j) = ||x_k-x_j||$$ the Euclidean distance from \(x_k\) to \(x_j\).

See Also

stppm

Examples

Run this code


set.seed(2)
df <- data.frame(runif(100), runif(100), runif(100), rpois(100, 15))

cov <- stcov(df, interp = FALSE)


Run the code above in your browser using DataLab