ppmdat: Prepare data for model fitting

View source: R/ppmlasso/R/ppmlasso_functions.R View source: R/ppmlasso_functions.R

ppmdatR Documentation

Prepare data for model fitting

Description

This function prepares the data for model fitting. In particular, it determines observation weights and sets up the design matrix required for fitting a regularisation path.

Usage

ppmdat(sp.xy, sp.scale, back.xy, coord = c("X","Y"), sp.dat = getEnvVar(sp.xy = sp.xy, 
env.scale = sp.scale, env.grid = back.xy, coord = coord, writefile = writefile), 
sp.file = NA, quad.file = NA, datfilename = "PPMDat", writefile = TRUE)

Arguments

sp.xy

A matrix of species locations containing at least one column representing longitude and one column representing latitude.

sp.scale

The spatial resolution at which to sample quadrature points.

back.xy

The geo-referenced matrix of environmental grids.

coord

A vector containing the names of the longitude and latitude coordinates, as in sampleQuad.

sp.dat

A matrix of species presence locations and the corresponding environmental data, as generated by getEnvVar.

sp.file

The name of a saved file containing a matrix of species presence locations and the corresponding environmental data, as generated by getEnvVar.

quad.file

The name of a fie containing the quadrature points created from the sampleQuad function.

datfilename

An optional argument containing the name of the saved file. Setting datfilename = "PPMDat" will save a matrix dat.ppm containing the species presence locations and quadrature points, the environmental data, as well as an indicator for whether the locations correspond to presence locations or quadrature points and the corresponding quadrature weights to the file "PPMDat.RData".

writefile

A logical argument to determine whether the output should be written to a file or not. If TRUE (the default), the output will be saved with the file name as described in the datfilename argument.

Details

This function will call the sampleQuad and getEnvVar functions to generate a quadrature scheme and interpolate environmental data to presence locations. Alternatively, the quadrature scheme may be directly supplied to the quad.file argument, and the matrix of presence locations and associated environmental data may be directly supplied to either the sp.dat argument (as an object in the workspace) or to the sp.file argument (as the name of a saved file containing this matrix).

Value

A matrix dat.ppm with columns representing the latitude and longitude of presence locations and quadrature points along with the associated environmental data, as well as a column Pres indicating whether either point corresponds to a presence location or a quadrature point, and a column wt of observation weights.

Author(s)

Ian W. Renner

See Also

sampleQuad for generating a regular grid of quadrature points.

getEnvVar for interpolating environmental data to species presence locations.

Examples

## Do not run because of NOTE Examples with CPU time > 2.5 times elapsed time
#data(BlueMountains)
#species.ppm = ppmdat(sp.xy = BlueMountains$eucalypt, back.xy = BlueMountains$env, 
#sp.scale = 1, datfilename = NA, writefile = FALSE)

ppmlasso documentation built on May 29, 2024, 7:12 a.m.