Learn R Programming

adespatial (version 0.0-7)

test.W: Function to compute and test eigenvectors of spatial weighting matrices

Description

This function is a user-friendly way to compute and test eigenvectors for various definitions of spatial weighting matrices. It combines calls to the functions scores.listw and ortho.AIC. It allows to test various definitions of the spatial weighting matrix and return results of scores.listw for the best one.

Usage

test.W(Y, nb, xy, MEM.autocor = c("all", "positive", "negative"), f = NULL, ...)

Arguments

Y
A matrix with response variables (univariate or multivariate response)
nb
An object of the class nb created by functions of the spdep package
xy
Coordinates of the samples, this argument is optional and is required only if the argument f is not null.
MEM.autocor
A string indicating if all MEM must be returned or only those corresponding to positive or negative autocorrelation
f
A function of the distance that can be used as a weighting spatial function. This argument is optional
...
Others arguments for the function f. It defines the range of parameters which will be tested

Value

A list with the following elements: A list with the following elements:

Details

This functions allows to test one binary spatial weighting matrix (if only Y and nb are provided). It allows also to test a weighting function based on distances (if f is provided) and a weighting function with different values of parameters if other arguments of f are provided.

References

Dray S., Legendre P. and Peres-Neto P. R. (2006) Spatial modeling: a comprehensive framework for principal coordinate analysis of neighbor matrices (PCNM). Ecological Modelling, 196, 483--493

See Also

ortho.AIC, scores.listw

Examples

Run this code

if(require(ade4) & require(spdep)){

data(oribatid)
# Hellinger transformation
fau <- sqrt(oribatid$fau / outer(apply(oribatid$fau, 1, sum), rep(1, ncol(oribatid$fau)), "*"))
# remove gradient effect
faudt <- resid(lm(as.matrix(fau) ~ as.matrix(oribatid$xy)))

# test a binary spatial weighting matrix
nbtri <- tri2nb(as.matrix(oribatid$xy))
tri.res <- test.W(faudt, nbtri)

maxi <- max(unlist(nbdists(nbtri, as.matrix(oribatid$xy))))

# test a simple spatial weighting function of the distance
f1 <- function(x) {1-(x)/(maxi)}
tri.f1 <- test.W(faudt, nbtri, f = f1, xy = as.matrix(oribatid$xy))

# test a spatial weighting function with various values of parameters
f2 <- function(x,dmax,y) {1-(x^y)/(dmax)^y}
tri.f2 <- test.W(faudt,nbtri, f = f2, y = 2:10, dmax = maxi, xy = as.matrix(oribatid$xy))
}

Run the code above in your browser using DataLab