griddify: Ensure that a geo-referenced matrix of environmental grids is...

View source: R/ppmlasso_functions.R

griddifyR Documentation

Ensure that a geo-referenced matrix of environmental grids is rectangular

Description

This function ensures that the coordinates of the supplied geo-referenced matrix of environmental grids constitutes a rectangular grid.

Usage

griddify(envframe, tol = 0.01, coord = c("X", "Y"))

Arguments

envframe

The geo-referenced matrix of environmental grids.

tol

The tolerance level within which to correct coordinate errors.

coord

A vector containing the names of the longitude and latitude coordinates.

Details

The functions in the ppmlasso package require a set of quadrature points along a rectangular grid. At times a set of quadrature points with a desired spatial resolution of x_δ \times y_δ will have some minor machine error in some coordinates such that the coordinates as supplied do not consistute a rectangular grid. The griddify function corrects this error as follows:

Let \{x_1, x_2, …, x_n\} and \{y_1, y_2, …, y_n\} be the supplied coordinates contained in envframe. The function first determines the spatial resolution x_δ \times y_δ based on the median of the differences in the unique values of x_i and y_i as well as the coordinates of a rectangular grid with this spatial resolution \{x^{grid}_1, x^{grid}_2, …, x^{grid}_n\} and \{y^{grid}_1, y^{grid}_2, …, y^{grid}_n\}. Given the tolerance ε supplied to tol, any coordinate x_i for which 0 < ≤ft|x_i - x^{grid}_i\right| ≤q ε \times x_δ will be adjusted to x^{grid}_i. Likewise, any coordinate y_i for which 0 < ≤ft|y_i - y^{grid}_i\right| ≤q ε \times y_δ will be adjusted to y^{grid}_i.

Any environmental variables contained in envframe are left unchanged.

Value

A data frame containing the coordinates on a rectangular grid as well as any environmental variables left unchanged.

Author(s)

Ian W. Renner

Examples

X = seq(0, 5, 1)
Y = seq(1, 11, 2)
XY = expand.grid(X, Y) # generate 1 x 2 rectangular grid
names(XY) = c("X", "Y")
#move some coordinates off of rectangular grid
XY$X[1] = XY$X[1] - 0.01
XY$Y[1] = XY$Y[1] - 0.01
XY$X[7] = XY$X[7] + 0.01
XY$Y[7] = XY$Y[7] + 0.01

#generate environmental variables
XY$V1 = 0.1*XY$X + 0.2*XY$Y + rnorm(36, 0, 1)
XY$V2 = -0.2*XY$X + 0.1*XY$Y + 0.05*XY$X*XY$Y + rnorm(36, 0, 5)

XY_grid = griddify(XY)

ppmlasso documentation built on Dec. 1, 2022, 5:09 p.m.