Skip to content

Commit

Permalink
experimental tidier for glmm package
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Apr 22, 2023
1 parent d948034 commit 2c2eaa0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions R/glmm_tidiers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
##' @importFrom dplyr bind_rows tibble
##' @export
tidy.glmm <- function(x, effects = "fixed") {
fix_nm <- names(coef(x))
ran_nm <- x$varcomps.names
res <- list()
if ("fixed" %in% effects) {
res[["fixed"]] <-
tibble(
term = fix_nm,
estimate = coef(x),
std.error = sqrt(diag(vcov(x)))[fix_nm]) |>
mutate(statistic = estimate/std.error,
p.value = 2*pnorm(-abs(statistic)))
}
if ("ran_pars" %in% effects) {
res[["fixed"]] <-
tibble(
term = ran_nm,
estimate = x$nu,
std.error = sqrt(diag(vcov(x)))[ran_nm]) |>
mutate(statistic = NA_real_,
p.value = NA_real_)
}
bind_rows(res, .id = "effect")
}

0 comments on commit 2c2eaa0

Please sign in to comment.