Learn R Programming

letsR (version 1.0)

lets.correl: Compute correlogram based on Moran's I

Description

Compute Moran's correlogram of a variable using a distance matrix.

Usage

lets.correl(x, y, z, equidistant=FALSE, plot=TRUE)

Arguments

x
A single variable in vector format or multiple variables in matrix format (as columns).
y
A distance matrix of class matrix.
z
The number of distance classes to use in the correlogram.
equidistant
Logical, if TRUE the classes will be equidistant. If FALSE the classes will have equal number of observations.
plot
Logical, if TRUE the correlogram will be ploted.

Value

  • Returns a matrix with the Moran's I Observed value, Standard Deviation and Expected value. Also the p value of the null model, the mean distance between classes and the number of observations.

Examples

Run this code
var <- runif(100)  # random variable

# Correlated distance matrix
distan <- matrix(runif(1000), ncol=100, nrow=100)
diag(distan) <- 0
distan[lower.tri(distan)] <- distan[upper.tri(distan)]
distan2 <- as.matrix(dist(var))
distan <- (distan)*(distan2)

moran <- lets.correl(var, distan, 5, equidistant=FALSE, plot=TRUE)

Run the code above in your browser using DataLab