check_spatialcorr: Test spatial autocorrelation of the residuals

Description Usage Arguments Value Note Author(s)

View source: R/check_spatialcorr.R

Description

This function tests for positive spatial autocorrelation of the (uni- or multivariate) residuals, using either Moran's I or Mantel's test.

Usage

1
2
check_spatialcorr(specdata, vars, plotit = T, test = "moran",
  method = "bonferroni", model = "gls")

Arguments

specdata

A data frame containing at least columns for the dependent variables, as well as a column "island" and a column "habitat".

vars

A character or integer vector. The names, or indices, of the dependent variables in specdata.

plotit

Logical. Whether to plot residuals versus latitude and longitude.

test

A character, what test to perform. "moran" (default) performs Moran's I test on each dependent variable. "mantel" performs Mantel's test to compare distance matrices in residual space and geographic space, meaning that it can perform a single test on multivariate residuals if several dependent variables are input.

method

A character, the method used for P-value correction. See ?p.adjust.

model

A character string, either lm or gls, defining what type of linear model to extract residuals from. If GLS is chosen, AIC comparison of variance structures is performed (one residual variance per island, per habitat or per island per habitat), and the Pearson residuals of the best model are extracted (note that Pearson residuals are identical to raw residuals for a regular linear model, whereas they differ for GLS models with particular variance structures – they are adjusted such that heteroscedasticity is reduced).

Value

Either the output of the mantel.test function from ape, or a table summarizing the (multiple) Moran's I test(s). If plotit = T, also returns a scatter plot of the residuals versus latitude and longitude.

Note

Beware that Mantel's test is a permutation test (999 permutations), and will take longer tha Moran's I test to run. Also, note that latitudes and longitudes are used to calculate geographical distances at the surface of the Earth using the Haversine distance function implemented in the package geosphere.

Author(s)

Raphael Scherrer


rscherrer/sagreicolor documentation built on Dec. 26, 2018, 1:15 p.m.