Skip to content

Commit 1dda914

Browse files
Merge pull request #292 from florianhartig/0.4.3-glmmTMB-issue
0.4.3 glmm tmb issue
2 parents 6dc26a5 + 939d1cd commit 1dda914

File tree

9 files changed

+53
-31
lines changed

9 files changed

+53
-31
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ sudo: false
1717
# cache: packages
1818

1919
r:
20-
- oldrel
2120
- release
22-
- devel
23-
21+
2422
# Install nlopt package to help nloptr install
2523
# glpk-utils and libglpk-dev are needed because of DHARMa #166
2624
addons:

DHARMa/tests/testthat/testModelTypes.R Code/testModelTypes.R

+8-8
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ test_that("glm poisson works",
310310
# fittedModel2 <- glm.nb(observedResponse ~ Environment1, data = testData2)
311311
# expectDispersion(fittedModel2,FALSE)
312312

313-
fittedModel <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData)
314-
runEverything(fittedModel, testData)
315-
fittedModel2 <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData2)
316-
expectDispersion(fittedModel2)
313+
#fittedModel <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData)
314+
#runEverything(fittedModel, testData)
315+
#fittedModel2 <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData2)
316+
#expectDispersion(fittedModel2)
317317

318-
fittedModel <- glmmTMB(observedResponse ~ Environment1 + (1|group), zi=~1 , family = nbinom2, data = testData)
319-
fittedModel2 <- glmmTMB(observedResponse ~ Environment1 + (1|group), zi=~1 , family = nbinom2, data = testData2)
318+
#fittedModel <- glmmTMB(observedResponse ~ Environment1 + (1|group), zi=~1 , family = nbinom2, data = testData)
319+
#fittedModel2 <- glmmTMB(observedResponse ~ Environment1 + (1|group), zi=~1 , family = nbinom2, data = testData2)
320320
# does not fully work
321321
# runEverything(fittedModel, testData)
322322
# expectDispersion(fittedModel2, F)
@@ -389,8 +389,8 @@ test_that("glm poisson weights throws warning",
389389
expect_warning(simulateResiduals(fittedModel))
390390

391391
# glmmTMB does not warn, implemented warning in DHARMa
392-
fittedModel <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData, weights = weights)
393-
expect_warning(simulateResiduals(fittedModel))
392+
# fittedModel <- glmmTMB(observedResponse ~ Environment1 , family = "poisson", data = testData, weights = weights)
393+
# expect_warning(simulateResiduals(fittedModel))
394394

395395
# spaMM does not warn, but seems to be simulating with correct (heteroskedastic) variance.
396396
# weights cannot be fit with poisson, because spaMM directly interpretes weights as variance

DHARMa/DESCRIPTION

+3-4
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.4.2
4-
Date: 2021-04-8
3+
Version: 0.4.3
4+
Date: 2021-07-06
55
Authors@R: c(person("Florian", "Hartig", email = "florian.hartig@biologie.uni-regensburg.de", role = c("aut", "cre"), comment=c(ORCID="0000-0002-6255-9059")), person("Lukas", "Lohse", role = "ctb"))
66
Description: The 'DHARMa' package uses a simulation-based approach to create
77
readily interpretable scaled (quantile) residuals for fitted (generalized) linear mixed
@@ -28,8 +28,7 @@ Imports:
2828
lmtest,
2929
ape,
3030
qgam (>= 1.3.2),
31-
lme4,
32-
glmmTMB (>= 1.0.1)
31+
lme4
3332
Suggests:
3433
knitr,
3534
testthat,

DHARMa/NEWS

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
NOTE: for more news about the package, see https://github.com/florianhartig/DHARMa/releases
22

3+
DHARMa 0.4.3
4+
============
5+
6+
Bugfixes
7+
8+
- Removed glmmTMB completely, see #289
9+
10+
311
DHARMa 0.4.2
412
============
513

DHARMa/R/compatibility.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ getFixedEffects <- function(fittedModel){
168168
} else if(class(fittedModel)[1] %in% c("glmerMod", "lmerMod", "HLfit")){
169169
out = fixef(fittedModel)
170170
} else if(class(fittedModel)[1] %in% c("glmmTMB")){
171-
out = glmmTMB::fixef(fittedModel)
171+
out = fixef(fittedModel)
172172
out = out$cond
173173
} else {
174174
out = coef(fittedModel)
@@ -232,7 +232,7 @@ getFitted <- function (object, ...) {
232232
#' @export
233233
getFitted.default <- function (object,...){
234234
out = predict(object, type = "response", re.form = ~0)
235-
out = as.vector(out)
235+
out = as.vector(out) # introduced because of phyr error
236236
}
237237

238238

DHARMa/cran-comments.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
# Version 0.4.1
1+
# Version 0.4.3
2+
3+
## Submission 1, 6.7.2021
4+
5+
This is a bugfix release, attempting to fix the issue with the dependency on glmmTMB
6+
7+
See NEWS for details.
8+
9+
This release was tested without apparent problems under
10+
11+
* local MAC OS 11.4 (Big Sur), R 4.1.0
12+
* http://win-builder.r-project.org/ - oldrelease / devel / release
13+
* Linux (Travis CI) - release
14+
* GitHub Actions - Windows / Mac / Ubuntu (release), Ubuntu (devel)
15+
16+
# Version 0.4.2
217

318
## Submission 1, 5.7.2021
419

DHARMa/inst/examples/hurricanes.R

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
\dontrun{
12
# Loading hurricanes dataset
23

34
library(DHARMa)
4-
data(hurricanes)
55

6+
data(hurricanes)
67
str(hurricanes)
78

89
# this is the model fit by Jung et al.
@@ -24,4 +25,5 @@ res2 = recalculateResiduals(res, group = hurricanes$Year)
2425
testTemporalAutocorrelation(res2, time = unique(hurricanes$Year))
2526

2627
# task: try to address these issues - in many instances, this will
27-
# make the MasFem predictor n.s.
28+
# make the MasFem predictor n.s.
29+
}

DHARMa/man/hurricanes.Rd

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

DHARMa/vignettes/DHARMa.Rmd

+8-10
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ testZeroInflation(simulationOutput)
367367

368368
This test is likely better suited for detecting zero-inflation than the standard plot, but note that also overdispersion will lead to excess zeros, so only seeing too many zeros is not a reliable diagnostics for moving towards a zero-inflated model. A reliable differentiation between overdispersion and zero-inflation will usually only be possible when directly comparing alternative models, e.g. through residual comparison / model selection of a model with / without zero-inflation, or by simply fitting a model with zero-inflation and looking at the parameter estimate for the zero-inflation. A good option is the R package glmmTMB, which is also supported by DHARMa. We can use this to fit
369369

370-
```{r}
371-
library(glmmTMB)
370+
```{r, eval= F}
371+
# requires glmmTMB
372372
fittedModel <- glmmTMB(observedResponse ~ Environment1 + I(Environment1^2) + (1|group), ziformula = ~1 , family = "poisson", data = testData)
373373
summary(fittedModel)
374374
@@ -565,28 +565,26 @@ I guess you could use either Model 2 or 3 - the broader point is: increasing mod
565565

566566
## Owl example (count data)
567567

568-
The next examples uses the fairly well known Owl dataset which is provided in glmmTMB (see ?Owls for more info about the data).
568+
The next examples uses the fairly well known Owl dataset which is provided in glmmTMB (see ?Owls for more info about the data). The following shows a sequence of models, all checked with DHARMa. The example is discussed in a talk at ISEC 2018, see slides [here](https://www.slideshare.net/florianhartig/mon-c5hartig2493).
569569

570-
The following shows a sequence of models, all checked with DHARMa. The example is discussed in a talk at ISEC 2018, see slides [here](https://www.slideshare.net/florianhartig/mon-c5hartig2493).
571570

572-
573-
```{r}
571+
```{r, eval = F}
574572
m1 <- glm(SiblingNegotiation ~ FoodTreatment*SexParent + offset(log(BroodSize)), data=Owls , family = poisson)
575573
res <- simulateResiduals(m1)
576574
plot(res)
577575
```
578576

579577
OK, this is highly overdispersed. Let's add a RE on nest
580578

581-
```{r}
579+
```{r, eval = F}
582580
m2 <- glmer(SiblingNegotiation ~ FoodTreatment*SexParent + offset(log(BroodSize)) + (1|Nest), data=Owls , family = poisson)
583581
res <- simulateResiduals(m2)
584582
plot(res)
585583
```
586584

587585
Somewhat better, but not good. Move to neg binom, to adjust dispersion
588586

589-
```{r}
587+
```{r, eval= F}
590588
m3 <- glmmTMB(SiblingNegotiation ~ FoodTreatment*SexParent + offset(log(BroodSize)) + (1|Nest), data=Owls , family = nbinom1)
591589
592590
res <- simulateResiduals(m3, plot = T)
@@ -598,7 +596,7 @@ testZeroInflation(res)
598596

599597
We see underdispersion now. In a model with variable dispersion, this is often the signal that some other distributional assumptions are violated, that is why I checked for zero-inflation, and it looks as if there is some. Therefore fitting a zero-inflated model
600598

601-
```{r}
599+
```{r, eval= F}
602600
m4 <- glmmTMB(SiblingNegotiation ~ FoodTreatment*SexParent + offset(log(BroodSize)) + (1|Nest), ziformula = ~ FoodTreatment + SexParent, data=Owls , family = nbinom1)
603601
604602
res <- simulateResiduals(m4, plot = T)
@@ -610,7 +608,7 @@ testZeroInflation(res)
610608

611609
This looks a lot better. Trying a slightly different model specification
612610

613-
```{r}
611+
```{r, eval= F}
614612
m5 <- glmmTMB(SiblingNegotiation ~ FoodTreatment*SexParent + offset(log(BroodSize)) + (1|Nest), dispformula = ~ FoodTreatment , ziformula = ~ FoodTreatment + SexParent, data=Owls , family = nbinom1)
615613
616614
res <- simulateResiduals(m4, plot = T)

0 commit comments

Comments
 (0)