testCategorical {DHARMa} | R Documentation |

This function tests if there are probles in a res ~ group structure. It performs two tests: test for within-group uniformity, and test for between-group homongeity of variances

testCategorical(simulationOutput, catPred, quantiles = c(0.25, 0.5, 0.75), plot = T)

`simulationOutput` |
an object of class DHARMa, either created via |

`catPred` |
a categorical predictor with the same dimensions as the residuals in simulationOutput |

`quantiles` |
whether to draw the quantile lines. |

`plot` |
if T, the function will create an additional plot |

The function tests for two common problems: are residuals within each group distributed according to model assumptions, and is the variance between group heterogeneous.

The test for within-group uniformity is performed via multipe KS-tests, with adjustment of p-values for multiple testing. If the plot is drawn, problematic groups are highlighted in red, and a corresponding message is displayed in the plot.

The test for homogeneity of variances is done with a Levene test. A significant p-value means that group variances are not constant. In this case, you should consider modelling variances, e.g. via ~dispformula in glmmTMB.

Florian Hartig

`testResiduals`

, `testUniformity`

, `testOutliers`

, `testDispersion`

, `testZeroInflation`

, `testGeneric`

, `testTemporalAutocorrelation`

, `testSpatialAutocorrelation`

, `testQuantiles`

, `testCategorical`

testData = createData(sampleSize = 100, overdispersion = 0.5, randomEffectVariance = 0) fittedModel <- glm(observedResponse ~ Environment1 , family = "poisson", data = testData) simulationOutput <- simulateResiduals(fittedModel = fittedModel) # the plot function runs 4 tests # i) KS test i) Dispersion test iii) Outlier test iv) quantile test plot(simulationOutput, quantreg = TRUE) # testResiduals tests distribution, dispersion and outliers # testResiduals(simulationOutput) ####### Individual tests ####### # KS test for correct distribution of residuals testUniformity(simulationOutput) # KS test for correct distribution within and between groups testCategorical(simulationOutput, testData$group) # Dispersion test - for details see ?testDispersion testDispersion(simulationOutput) # tests under and overdispersion # Outlier test (number of observations outside simulation envelope) # Use type = "boostrap" for exact values, see ?testOutliers testOutliers(simulationOutput, type = "binomial") # testing zero inflation testZeroInflation(simulationOutput) # testing generic summaries countOnes <- function(x) sum(x == 1) # testing for number of 1s testGeneric(simulationOutput, summary = countOnes) # 1-inflation testGeneric(simulationOutput, summary = countOnes, alternative = "less") # 1-deficit means <- function(x) mean(x) # testing if mean prediction fits testGeneric(simulationOutput, summary = means) spread <- function(x) sd(x) # testing if mean sd fits testGeneric(simulationOutput, summary = spread)

[Package *DHARMa* version 0.4.3 Index]