3
$\begingroup$

I fitted different response variables (one after each other) to the same categorial predictor. Since it's a categorical predictor I get a boxplot for the residual vs. fitted with the DHARMa diagnostics. In Florian Hartig’s vignette he explains very neatly different examples for continuous predictors, but I struggle interpreting the boxplots.

First, my plots are missing the quantile lines. Setting quantreg = T seems to have no effect. Is there a way to fix this?

Second, I would like an opinion on the following examples of my diagnostics. What would you consider fine and where do you see problems and why? What general things would you watch out for in this boxplot style output and are there rules of thumb e.g. "if one box is double the size of another..."? (Comments on the shape of the QQ plot are welcome but not the main focus of this question.)

My models have this structure and use DHARMa diagnostics:

    mod <- glmmTMB(response ~ cat_predictor + (1|sampleID), ziformula = ~ cat_predictor, family = "poisson", data = seeds)

sim <- simulateResiduals(mod)
plot(sim, quantreg = T, n = 250)

cat_predictor: has 4 level, with differing amounts of zeros per level

response: n = 320 , so per level 80 observations

response1 = count variable using family = poisson:

enter image description here

response2 = count variable using family = nbinom1:

enter image description here

response3 = binomial variable using family = binomial:

enter image description here

response4 = continuous variable using family = tweedie(without ziformula):

enter image description here

response5 = proportion variable using family = beta (values are 0 <= y <= 1):

enter image description here

response6 = proportion variable using family = tweedie(including ziformula, values are 0 <= y <= ~4)

enter image description here

I am looking forward to hearing your opinions!

$\endgroup$
1
  • $\begingroup$ The quantile lines are not necessary here because they correspond to the elements of a boxplot. $\endgroup$ Feb 23, 2021 at 13:31

1 Answer 1

3
$\begingroup$

in principle, the interpretation of the plots is explained in the help of ?plotResiduals:

If form is a factor, a boxplot will be plotted instead of a scatter plot. The distribution for each factor level should be uniformly distributed, so the box should go from 0.25 to 0.75, with the median line at 0.5. Again, chance deviations from this will increases when the sample size is smaller. You can run null simulations to test if the deviations you see exceed what you would expect from random variation. If you want to create box plots for categorical predictors (e.g. because you only have a small number of unique numeric predictor values), you can convert your predictor with as.factor(pred)

Regarding the specific questions:

  1. quantreg: there is currently no option to plot quantile regressions for categorical predictors. The reason is that it both doesn't make sense for unordered factors, and that quantile regressions will crash with too few unique values on x. 4 is definitely too many. Only if you have an ordered factor, and if you have a large number of levels, you could overrule this by using as.numeric(orderedCategorialPredictor) as predictor in plotResiduals, in which case the standard scatter plot would be drawn.
  2. Regarding your plots: I can see light variations of the dispersion between the groups in your plot. I don't think it's a large concern. The interpretation depends also on your data size, as stochasticity of these plots will increase for smaller datasets. If your data is reasonably large (say n>100), you could try adding dispformula ~ cat_predictor to your model, which would model variable dispersion in the groups specified by your cat_predictor

Addition 5.3.21: the development version of DHARMa now includes some formal tests (within-group distribution and homogeneity of variances, example see below) for this plot, which will aid interpretation. This can be installed from already now from https://github.com/florianhartig/DHARMa and will go into DHARMa 0.3.4 (scheduled for April 2021).

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.