Skip to content

Commit

Permalink
Fixed extract.glmmTMB and added unit test; closes #206
Browse files Browse the repository at this point in the history
  • Loading branch information
leifeld committed Nov 9, 2023
1 parent 95228b0 commit 1346dff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,7 @@ extract.glmmTMB <- function(model, beside = FALSE, include.count = TRUE,
gof.names <- c(gof.names, grp.names)
gof.decimal <- c(gof.decimal, rep(FALSE, length(grps)))
}
if (include.variance == TRUE && !is.na(s$ngrps[1])) {
if (include.variance == TRUE && !is.na(s$ngrps[1]) && (length(s$ngrps$cond) > 0 || length(s$ngrps$zi) > 0)) {
vc <- glmmTMB::VarCorr(model)
vc <- as.data.frame(rapply(vc, function(x) attr(x, "stddev")))^2
rownames(vc) <- gsub("\\.", " ", rownames(vc))
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ test_that("extract glmmTMB objects from the glmmTMB package", {
expect_length(tr[[2]]@pvalues, 8)
expect_length(tr, 2)
expect_equivalent(which(tr[[2]]@gof.decimal), c(1, 2, 5))

data("mtcars")
cars <- glmmTMB(gear ~ mpg, data = mtcars)
tr_cars <- extract(cars)
expect_length(tr_cars@gof, 3)
expect_equal(tr_cars@gof.decimal, c(TRUE, TRUE, FALSE))
expect_equal(tr_cars@gof.names, c("AIC", "Log Likelihood", "Num. obs."))
expect_length(tr_cars@coef, 2)
expect_length(tr_cars@se, 2)
expect_length(tr_cars@pvalues, 2)
})

# ivreg (AER) ----
Expand Down

0 comments on commit 1346dff

Please sign in to comment.