SEMap-class {pMEM} | R Documentation |
Class and Methods for Predictive Moran's Eigenvector Maps (pMEM)
Description
Generator function, class, and methods to handle predictive Moran's eigenvector maps (pMEM).
Usage
genSEF(x, m, f, tol = .Machine$double.eps^0.5)
## S3 method for class 'SEMap'
print(x, ...)
## S3 method for class 'SEMap'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
## S3 method for class 'SEMap'
as.matrix(x, ...)
## S3 method for class 'SEMap'
predict(object, newdata, ...)
Arguments
x |
a set of coordinates to be given to the distance metric function
(argument |
m |
a distance metric function, such as one of those returned by
|
f |
a distance weighting function, such as one of those returned by
|
tol |
a tolerance threshold for absolute eigenvalues, below which to discard spatial eigenfunctions. |
... |
further arguments to be passed to other functions or methods. |
row.names |
|
optional |
logical. If |
object |
an |
newdata |
a set of new coordinates from which to calculate pMEM predictor scores. |
Format
A SEMap-class
object contains:
- show
A printing function.
- getIMoran
A function (with no argument) returning the Moran's I coefficients associated with the spatial eigenfunctions.
- getSEF
A function that return the spatial eigenvectors. It has an argument
wh
which allows one to specify a selection of the eigenvectors that are to be returned.- getLambda
A function that returns the eigenvalues.
- getPredictor
A function that calculate the spatial eigenfunction values for arbitrary locations about the sampling points. The coordinates of these locations are given as a vector or matrix through argument
xx
. It also has an argumentwh
which allows one to specify a selection of the eigenfunctions that are to be returned.
Details
Predictive Moran's Eigenvector Maps (pMEM) allows one to model the
spatial variability of an environmental variable and use the resulting model
for making prediction at any location on and around the sampling points. They
originate from coordinates in one or more dimensions, which are used to
calculate distances. The distances are obtained from the coordinates using a
function given through argument m
(see genDistMetric
for
further details). The distances are then transformed to weights using a
spatial weighting function given as argument f
(see
genDWF
for implementations of spatial weighting function). The
resulting weights are row- and column-centred to the value 0 before being
submitted to an eigenvalue decomposition. Eigenvectors associated to
eigenvalues whose absolute value are above the threshold value set through
argument tol
are retained as part of the resulting eigenvector map.
In a standard workflow, a model is built for the locations where values of
the response variable are known using the eigenvectors (or a subset thereof).
This model may be build using any model building approach using descriptors.
The scores obtained for new coordinates from method predict
are used
given to the model for making predictions.
The function can handle real-valued as well as complex-valued distance metrics. The latter is useful to represent asymmetric (i.e., directed) spatial processes.
Value
- genSEF
a
SEMap-class
object.- print.SEMap
-
NULL
(invisibly). - as.data.frame.SEMap
A
data.frame
with the spatial eigenvectors.- as.matrix.SEMap
A matrix with the spatial eigenvectors.
- predict.SEMap
A matrix with the spatial eigenfunction values
Functions
-
genSEF()
: Predictive Moran's Eigenvector Map (pMEM) GenerationGenerates a predictive spatial eigenvector map (a SEMap-class object).
-
print(SEMap)
: Print SEMap-classA print method for
SEMap-class
objects. -
as.data.frame(SEMap)
: Anas.data.frame
Method forSEMap-class
ObjectsA method to extract the spatial eigenvectors from an
SEMap-class
object as a data frame. -
as.matrix(SEMap)
: Anas.matrix
Method forSEMap-class
ObjectsA method to extract the spatial eigenvectors from an
SEMap-class
object as a matrix. -
predict(SEMap)
: Apredict
Method forSEMap-class
ObjectsA method to obtain predictions from an
SEMap-class
object.
Author(s)
Guillaume Guénard [aut, cre] (ORCID: <https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (ORCID: <https://orcid.org/0000-0002-3838-3305>)
Maintainer: Guillaume Guénard <guillaume.guenard@umontreal.ca>
Examples
## Store graphical parameters:
tmp <- par(no.readonly = TRUE)
par(las=1)
## Case 1: one-dimensional symmetrical
n <- 11
x <- (n - 1)*seq(0, 1, length.out=n)
xx <- (n - 1)*seq(0, 1, 0.01)
sefSym <- genSEF(x, genDistMetric(), genDWF("Gaussian",3))
plot(y = predict(sefSym, xx, wh=1), x = xx, type = "l", ylab = "PMEM_1",
xlab = "x")
points(y = as.matrix(sefSym, wh=1), x = x)
plot(y = predict(sefSym, xx, wh=2), x = xx, type = "l", ylab = "PMEM_2",
xlab = "x")
points(y = as.matrix(sefSym, wh=2), x = x)
plot(y = predict(sefSym, xx, wh=5), x = xx, type = "l", ylab = "PMEM_5",
xlab = "x")
points(y = as.matrix(sefSym, wh=5), x = x)
## Case 2: one-dimensional asymmetrical (each has a real and imaginary parts)
sefAsy <- genSEF(x, genDistMetric(delta = pi/8), genDWF("Gaussian",3))
plot(y = Re(predict(sefAsy, xx, wh=1)), x = xx, type = "l", ylab = "PMEM_1",
xlab = "x", ylim=c(-0.35,0.35))
lines(y = Im(predict(sefAsy, xx, wh=1)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=1)), x = x)
points(y = Im(as.matrix(sefAsy, wh=1)), x = x, col="red")
plot(y = Re(predict(sefAsy, xx, wh=2)), x = xx, type = "l", ylab = "PMEM_2",
xlab = "x", ylim=c(-0.45,0.35))
lines(y = Im(predict(sefAsy, xx, wh=2)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=2)), x = x)
points(y = Im(as.matrix(sefAsy, wh=2)), x = x, col="red")
plot(y = Re(predict(sefAsy, xx, wh=5)), x = xx, type = "l", ylab = "PMEM_5",
xlab = "x", ylim=c(-0.45,0.35))
lines(y = Im(predict(sefAsy, xx, wh=5)), x = xx, col="red")
points(y = Re(as.matrix(sefAsy, wh=5)), x = x)
points(y = Im(as.matrix(sefAsy, wh=5)), x = x, col="red")
## A function to display combinations of the real and imaginary parts:
plotAsy <- function(object, xx, wh, a, ylim) {
pp <- predict(object, xx, wh=wh)
plot(y = cos(a)*Re(pp) + sin(a)*Im(pp), x = xx, type = "l",
ylab = "PMEM_5", xlab = "x", ylim=ylim, col="green")
invisible(NULL)
}
## Display combinations at an angle of 45° (pMEM_5):
plotAsy(sefAsy, xx, 5, pi/4, ylim=c(-0.45,0.45))
## Display combinations for other angles:
for(i in 0:15) {
plotAsy(sefAsy, xx, 5, i*pi/8, ylim=c(-0.45,0.45))
if(is.null(locator(1))) break
}
## Case 3: two-dimensional symmetrical
cbind(
x = c(-0.5,0.5,-1,0,1,-0.5,0.5),
y = c(rep(sqrt(3)/2,2L),rep(0,3L),rep(-sqrt(3)/2,2L))
) -> x2
seq(min(x2[,1L]) - 0.3, max(x2[,1L]) + 0.3, 0.05) -> xx
seq(min(x2[,2L]) - 0.3, max(x2[,2L]) + 0.3, 0.05) -> yy
list(
x = xx,
y = yy,
coords = cbind(
x = rep(xx, length(yy)),
y = rep(yy, each = length(xx))
)
) -> ss
cc <- seq(0,1,0.01)
cc <- c(rgb(cc,cc,1),rgb(1,1-cc,1-cc))
sefSym2D <- genSEF(x2, genDistMetric(), genDWF("Gaussian",3))
scr <- predict(sefSym2D, ss$coords)
par(mfrow = c(2,3), mar=0.5*c(1,1,1,1))
for(i in 1L:6) {
image(z=matrix(scr[,i],length(ss$x),length(ss$y)), x=ss$x, y=ss$y, asp=1,
zlim=max(abs(scr[,i]))*c(-1,1), col=cc, axes=FALSE)
points(x = x2[,1L], y = x2[,2L])
}
## Case 4: two-dimensional asymmetrical
sefAsy2D0 <- genSEF(x2, genDistMetric(delta=pi/8), genDWF("Gaussian",1))
## Note: default influence angle is 0 (with respect to the abscissa)
## A function to display combinations of the real and imaginary parts (2D):
plotAsy2 <- function(object, ss, a) {
pp <- predict(object, ss$coords)
for(i in 1:6) {
z <- cos(a)*Re(pp[,i]) + sin(a)*Im(pp[,i])
image(z=matrix(z,length(ss$x),length(ss$y)), x=ss$x, y=ss$y, asp=1,
zlim=max(abs(z))*c(-1,1), col=cc, axes=FALSE)
}
invisible(NULL)
}
## Display combinations at an angle of 22°:
plotAsy2(sefAsy2D0, ss, pi/8)
## Display combinations at other angles:
for(i in 0:23) {
plotAsy2(sefAsy2D0, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of +45° (with respect to the abscissa)
sefAsy2D1 <- genSEF(x2, genDistMetric(delta=pi/8, theta = pi/4),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D1, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of +90° (with respect to the abscissa)
sefAsy2D2 <- genSEF(x2, genDistMetric(delta=pi/8, theta = pi/2),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D2, ss, i*pi/12)
if(is.null(locator(1))) break
}
## With an influence of -45° (with respect to the abscissa)
sefAsy2D3 <- genSEF(x2, genDistMetric(delta=pi/8, theta = -pi/4),
genDWF("Gaussian",1))
for(i in 0:23) {
plotAsy2(sefAsy2D3, ss, i*pi/12)
if(is.null(locator(1))) break
}
## Reverting to initial graphical parameters:
par(tmp)