testPhylogeneticAutocorrelation | R Documentation |
This function performs a Moran's I test for phylogenetic autocorrelation on the calculated quantile residuals.
testPhylogeneticAutocorrelation(simulationOutput, tree,
alternative = c("two.sided", "greater", "less"))
simulationOutput |
an object of class DHARMa, either created via simulateResiduals for supported models or via createDHARMa for simulations created outside DHARMa, or a supported model. Providing a supported model directly is discouraged, because simulation settings cannot be changed in this case. |
tree |
A phylogenetic tree object. |
alternative |
A character string specifying whether the test should test if observations are "greater", "less" or "two.sided" compared to the simulated null hypothesis of no phylogenetic correlation. |
The function performs Moran.I test from the package ape on the DHARMa residuals, based on the phylogenetic distance matrix internally created from the provided tree. For custom distance matrices, you can use testSpatialAutocorrelation.
Standard DHARMa simulations from models with (temporal / spatial / phylogenetic) conditional autoregressive terms will still have the respective temporal / spatial / phylogenetic correlation in the DHARMa residuals, unless the package you are using is modelling the autoregressive terms as explicit REs and is able to simulate conditional on the fitted REs. This has two consequences:
If you check the residuals for such a model, they will still show significant autocorrelation, even if the model fully accounts for this structure.
Because the DHARMa residuals for such a model are not statistically independent any more, other tests (e.g. dispersion, uniformity) may have inflated type I error, i.e. you will have a higher likelihood of spurious residual problems.
There are three (non-exclusive) routes to address these issues when working with spatial / temporal / phylogenetic autoregressive models:
Simulate conditional on the fitted CAR structures (see conditional simulations in the help of simulateResiduals).
Rotate simulations prior to residual calculations (see parameter rotation in simulateResiduals).
Use custom tests / plots that explicitly compare the correlation structure in the simulated data to the correlation structure in the observed data.
Florian Hartig
testResiduals, testUniformity, testOutliers, testDispersion, testZeroInflation, testGeneric, testTemporalAutocorrelation, testSpatialAutocorrelation, testQuantiles, testCategorical
## Not run:
library(DHARMa)
library(phylolm)
set.seed(123)
tre = rcoal(60)
b0 = 0; b1 = 1;
x <- runif(length(tre$tip.label), 0, 1)
y <- b0 + b1*x +
rTrait(n = 1, phy = tre,model="BM",
parameters = list(ancestral.state = 0, sigma2 = 10))
dat = data.frame(trait = y, pred = x)
fit = lm(trait ~ pred, data = dat)
res = simulateResiduals(fit, plot = T)
testPhylogeneticAutocorrelation(res, tree = tre)
fit = phylolm(trait ~ pred, data = dat, phy = tre, model = "BM")
summary(fit)
# phylogenetic autocorrelation still present in residuals
res = simulateResiduals(fit, plot = T)
# with "rotation" the residual autcorrelation is gone, see ?simulateResiduals.
res = simulateResiduals(fit, plot = T, rotation = "estimated")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.