check_spatialcorr_nested: Test spatial autocorrelation of the residuals within islands

Description Usage Arguments Value Note Author(s)

View source: R/check_spatialcorr_nested.R


This function tests for positive spatial autocorrelation of the (uni- or multivariate) residuals, using either Moran's I or Mantel's test. This function essentially performs the task of check_spatialcorr but within each island.


check_spatialcorr_nested(specdata, vars, plotit = T, test = "moran",
  method = "bonferroni", model = "gls")



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


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


Logical. Whether to plot residuals versus latitude and longitude.


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.


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


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).


A list of outputs, one per island. 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.


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.


Raphael Scherrer

rscherrer/sagreicolor documentation built on May 26, 2019, 12:32 p.m.