griddify {ppmlasso} | R 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 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 and
be the supplied coordinates contained in
envframe
. The function first determines the spatial resolution based on the median of the differences in the unique values of
and
as well as the coordinates of a rectangular grid with this spatial resolution
and
. Given the tolerance
supplied to
tol
, any coordinate for which
will be adjusted to
. Likewise, any coordinate
for which
will be adjusted to
.
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)