Skip to content

Commit

Permalink
bug fix for survey::svyglm() models with replicate weights
Browse files Browse the repository at this point in the history
fix #240
  • Loading branch information
larmarange committed Nov 29, 2023
1 parent 6b94c89 commit 99294ff
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ S3method(model_get_terms,glmmTMB)
S3method(model_get_terms,model_fit)
S3method(model_get_weights,default)
S3method(model_get_weights,model_fit)
S3method(model_get_weights,svrepglm)
S3method(model_get_weights,svyglm)
S3method(model_get_xlevels,brmsfit)
S3method(model_get_xlevels,default)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- fix in `supported_models`
- bug fix when using `tidy_parameters()` for mixed models (#238)
- bug fix for `survey::svyglm()` models with replicate weights (#240)

# broom.helpers 1.14.0

Expand Down
10 changes: 10 additions & 0 deletions R/model_get_weights.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#' This function does not cover `lavaan` models (`NULL` is returned).
#'
#' @param model a model object
#' @note
#' For class `svrepglm` objects (glm on a survey object with replicate weights),
#' it will return the original sampling weights of the data, not the replicate
#' weights.
#' @export
#' @family model_helpers
#' @examples
Expand Down Expand Up @@ -69,6 +73,12 @@ model_get_weights.svyglm <- function(model) {
stats::weights(model$survey.design)
}

#' @export
#' @rdname model_get_weights
model_get_weights.svrepglm <- function(model) {
model$survey.design$pweights
}

#' @export
#' @rdname model_get_weights
model_get_weights.model_fit <- function(model) {
Expand Down
8 changes: 8 additions & 0 deletions man/model_get_weights.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/testthat/test-tidy_plus_plus.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ test_that("tidy_plus_plus() works with survey::svyglm", {
res <- mod %>% tidy_plus_plus(),
NA
)

df_rep <- survey::as.svrepdesign(df)
mod_rep <- survey::svyglm(
response ~ age + grade * trt,
df_rep,
family = quasibinomial
)
expect_error(
res <- mod_rep %>% tidy_plus_plus(),
NA
)
})

test_that("tidy_plus_plus() works with survey::svycoxph", {
Expand Down

0 comments on commit 99294ff

Please sign in to comment.