Skip to content

Commit 45c0503

Browse files
committed
bubfixes test / moved to 0.0.2.1
1 parent b999a6e commit 45c0503

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

DHARMa/DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: DHARMa
22
Title: Residual Diagnostics for HierArchical (Multi-level / Mixed) Regression Models
3-
Version: 0.0.2.0
4-
Date: 11.8.2016
3+
Version: 0.0.2.1
4+
Date: 12.8.2016
55
Authors@R: c(person("Florian", "Hartig", email = "florian.hartig@biologie.uni-regensburg.de", role = c("aut", "cre")))
66
Author: Florian Hartig [aut, cre],
77
Maintainer: Florian Hartig <florian.hartig@biologie.uni-regensburg.de>

DHARMa/R/testsResiduals.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @seealso \code{\link{testUniformDistribution}}, \code{\link{testZeroInflation}}, \code{\link{testTemporalAutocorrelation}}, \code{\link{testSpatialAutocorrelation}}
77
testSimulatedResiduals <- function(simulationOutput){
88

9-
out <- testUniformDistribution(simulationOutput$scaledResiduals)
9+
out$pValueUnivariate <- testUniformDistribution(simulationOutput)
1010

1111
return(out)
1212
}
@@ -20,7 +20,7 @@ testSimulatedResiduals <- function(simulationOutput){
2020
#' @export
2121
testUniformDistribution <- function(simulationOutput, print = T){
2222

23-
out <- suppressWarnings(ks.test(simulationOutput, 'punif'))
23+
out <- suppressWarnings(ks.test(simulationOutput$scaledResiduals, 'punif'))
2424
if(print == T) out
2525
return(out)
2626
}

DHARMa/R/zz-testTypeI.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Simulated p-values for internal testing
22
#' @return list of various named objects. Within each, order is dispersion_glmer, overdisp_fun, DHARMa
3-
simulatePvaluesDispersion <- function(overdispersion, n = 20, alpha = 0.05){
3+
simulatePvaluesDispersion <- function(overdispersion = 0, n = 20, alpha = 0.05){
44

55
out = matrix(nrow = n, ncol = 3)
66

@@ -16,8 +16,8 @@ simulatePvaluesDispersion <- function(overdispersion, n = 20, alpha = 0.05){
1616

1717

1818
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
19-
x = testSimulatedResiduals(simulationOutput)
20-
out[i,3] = x$pValueUnivariate$p.value
19+
x = testUniformDistribution(simulationOutput)
20+
out[i,3] = x$p.value
2121
}
2222

2323

DHARMa/man/simulatePvaluesDispersion.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DHARMa/vignettes/DHARMa.Rmd

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set.seed(123)
1717

1818

1919
```{r global_options, include=FALSE}
20-
knitr::opts_chunk$set(fig.width=7, fig.height=4.5, warning=FALSE, message=FALSE, cache = T)
20+
knitr::opts_chunk$set(fig.width=7, fig.height=4.5, warning=FALSE, message=FALSE, cache = F)
2121
```
2222

2323
***Summary: The DHARMa package creates readily interpretable residuals for generalized linear (mixed) models that are standardized to values between 0 and 1. This is achieved by a simulation-based approach, similar to the Bayesian p-value or the parametric bootstrap: 1) simulate new data from the fitted model 2) from this simulated data, calculate the cummulative density function 3) residual is the value of the empirical density function at the value of the observed data.* **
@@ -121,13 +121,13 @@ The DHARMa package provides a number of additional tests, which, however, should
121121
You can run a hypothesis test on the residuals, which runs a KS test on the uniformity of the simulated residuals
122122

123123
```{r}
124-
testSimulatedResiduals(simulationOutput = simulationOutput)
124+
testUniformDistribution(simulationOutput = simulationOutput)
125125
```
126126

127127
Note, however, that simulations show that this test is less powerfull than parametric tests on the likelihood that are currently run by many people. On the other hand, the parametric tests
128128

129129
```{r}
130-
dispersionTest(fittedModel, type = 1)
130+
parametricDispersionTest(fittedModel, type = 1)
131131
```
132132

133133
### Test for zero-inflation
@@ -204,7 +204,7 @@ summary(fittedModel)
204204
205205
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
206206
plotSimulatedResiduals(simulationOutput = simulationOutput)
207-
testSimulatedResiduals(simulationOutput = simulationOutput)
207+
testUniformDistribution(simulationOutput = simulationOutput)
208208
```
209209

210210
Here, we get too many residuals around 0.5, which means that we are not getting as many residuals as we would expect in the tail of the distribution that is epected with the fitted model.
@@ -251,7 +251,7 @@ fittedModel <- glmer(observedResponse ~ Environment1 + (1|group), family = "pois
251251
252252
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
253253
plotSimulatedResiduals(simulationOutput = simulationOutput)
254-
testSimulatedResiduals(simulationOutput = simulationOutput)
254+
testUniformDistribution(simulationOutput = simulationOutput)
255255
```
256256

257257
Adding a simple overdispersion correction will try to find a compromise between the different levels of dispersion in the model. The qq plot looks better now, but there is still a pattern in the residuals
@@ -264,7 +264,7 @@ fittedModel <- glmer(observedResponse ~ Environment1 + (1|group) + (1|ID), famil
264264
265265
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
266266
plotSimulatedResiduals(simulationOutput = simulationOutput)
267-
testSimulatedResiduals(simulationOutput = simulationOutput)
267+
testUniformDistribution(simulationOutput = simulationOutput)
268268
```
269269

270270
To remove this patter, you would need to make the dispersion parameter dependent on a predictor (e.g. in JAGS), or apply a transformation.
@@ -287,7 +287,7 @@ fittedModel <- glmer(observedResponse ~ Environment1 + Environment2 + (1|group)
287287
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
288288
# plotConventionalResiduals(fittedModel)
289289
plotSimulatedResiduals(simulationOutput = simulationOutput, quantreg = T)
290-
testSimulatedResiduals(simulationOutput = simulationOutput)
290+
testUniformDistribution(simulationOutput = simulationOutput)
291291
```
292292

293293
Difficult to see with the overall pattern, but it becomes clear if we plot against the environment
@@ -354,7 +354,7 @@ plotSimulatedResiduals(simulationOutput = simulationOutput)
354354
The residuals look clearly overdispersed. We can confirm that with a
355355

356356
```{r}
357-
testSimulatedResiduals(simulationOutput = simulationOutput)
357+
testUniformDistribution(simulationOutput = simulationOutput)
358358
```
359359

360360

0 commit comments

Comments
 (0)