Open florianhartig opened 7 months ago
It's a good point that the KS test has lower power, although I would note that generally, my view is that the tests are just a help for interpreting the plots (see comments in the vignette https://cran.r-project.org/web/packages/DHARMa/vignettes/DHARMa.html#general-remarks-on-interperting-residual-patterns-and-tests), and should not be interpreted as the main decision criterion on whether there is a problem, so one could argue about how important the loss of power through the KS test is.
In any case, it's reasonable to choose the test with the highest power available, so let's say we are concerned about this and would like to switch to shapiro or some other parametric test to improve power:
1) First of all, note that DHARMa already offers the option to transform the residuals to any other distribution, including normal, in the function DHARMa::residuals. So you could choose normal here and then test use the shapiro test. There is an ongoing discussion about whether uniform or normal residuals are better in DHARMa, and what should be the default, and it's on our list to look at this in more detail https://github.com/florianhartig/DHARMa/issues/39
2) One of the reason I'm not doing the normal transformation by default is that with the normal distribution, there's the problem where to back-transform points that are outside the simulation envelope (at thus at a ecdf value close to 0 or 1). However, note that in the case of lmer, there would actually not be any need to do simulations, you could get the ecdf position analytically (and then back-transform to normal, which, however, would be the same to just use the residuals from lmer). The reason I'm always simulating in DHARMa is a pure practical one, I just don't want to program a large set of rules when to use simulation-based and when to use analytical ecdf values. So long story short: if you want analytical values with higher power, just use the default residuals. I have also considered whether it would be useful to provide an option to read in such default residuals in DHARMa and give the user an option to just use the plots / tests. In such a case, you could provide the residuals and the lmer object, and DHARMa wouldn't simulate but rather use the default residuals() function but people could still use the plots https://github.com/florianhartig/DHARMa/issues/408
3) In case we stay with uniform: a question one could look into is if there is a parametric test for uniformity with a similar power as the shapiro test. I have to say that I never researched this and just chose the KS as the first convenient thing that came to mind
Cheers
Florian
via Email: