spdiffpen: Spatial difference penalty

View source: R/spdiffpen.R

spdiffpenR Documentation

Spatial difference penalty

Description

spdiffpen computes the mth order spatial difference penalty for a set of coordinates.

Usage

spdiffpen(coords, m = 1, sparse = TRUE, longlat = FALSE, digits = 1)

Arguments

coords

A two-dimensional matrix-like object with non-NULL dimensions.

m

A positive integer indicating order of the difference penalty.

sparse

A logical value indicating if the result should be a sparse version of the Matrix-class.

longlat

A logical value indicating whether Great Circle distances should be used (TRUE) or Euclidean distances (FALSE). The default is FALSE.

digits

The number of digits to use when applying round to the distances.

Details

adjacent is used to determine the first-order neighbors of each point in coords. The difference penalties are then successively determined from that.

If sparse = TRUE, a sparseMatrix-class Matrix is returned when the penalty matrix is relatively sparse (typically, at least half the entries are zero). Otherwise, something of the more general Matrix-class is returned.

Value

A matrix or sparseMatrix-class object.

Examples

coords = expand.grid(1:4, 1:4)
# first order difference penalty
d1 = spdiffpen(coords, digits = 1)
# second order difference penalty
d2 = spdiffpen(coords, m = 2, digits = 1)
# third order difference penalty
d3 = spdiffpen(coords, m = 3, digits = 1)

hero documentation built on July 26, 2023, 5:11 p.m.