Computes the spatial correlation coefficient (Moran's I) of a vector given a distance matrix, and a distance threshold used to define "neighborhood".

moran(
  x = NULL,
  distance.matrix = NULL,
  distance.threshold = NULL,
  verbose = TRUE
)

Arguments

x

Numeric vector, generally model residuals, Default: NULL

distance.matrix

Distance matrix among cases in x. The number of rows of this matrix must be equal to the length of x. Default: NULL

distance.threshold

numeric value in the range of values available in distance.matrix. Distances below such threshold are set to 0. Default: NULL (which defaults to 0).

verbose

Logical, if TRUE, prints a Moran's I plot. Default: TRUE

Value

A list with three named slots:

  • test: Data frame with observed and expected Moran's I values, p-value, and interpretation.

  • plot: Moran's plot of the vector x against the spatial lags of x.

  • plot.df: Data used in the Moran's plot.

Details

Inspired in the Moran.I() function of the ape package.

Examples

if(interactive()){

 #loading example data
 data(distance_matrix)
 data(plant_richness)

 #Moran's I of the response variable
 out <- moran(
   x = plant_richness$richness_species_vascular,
   distance.matrix = distance_matrix
   )
 out

}