Skip to content

Commit

Permalink
d.f. for mira models (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlenth committed May 28, 2024
1 parent e842322 commit 3af99bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: emmeans
Type: Package
Title: Estimated Marginal Means, aka Least-Squares Means
Version: 1.10.2
Date: 2024-05-19
Version: 1.10.2.090001
Date: 2024-05-27
Authors@R: c(person("Russell V.", "Lenth", role = c("aut", "cre", "cph"),
email = "russell-lenth@uiowa.edu"),
person("Ben", "Bolker", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
title: "NEWS for the emmeans package"
---

## emmeans 1.10.2-09xxxxx
* Updated `mice::mira` support to use Barnard-Rubin adjusted d.f. (#494)


## emmeans 1.10.2
This update is focused mostly on trying to clear up confusion with some users
on the distinction between `emmGrid` objects and their summaries, since they
Expand Down
16 changes: 15 additions & 1 deletion R/multiple-models.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ emm_basis.mira = function(object, trms, xlev, grid, ...) {
}
bas$bhat = apply(allb, 1, mean) # averaged coef
notna = which(!is.na(bas$bhat))
bas$V = V + (k + 1)/k * cov(t(allb[notna, , drop = FALSE])) # pooled via Rubin's rules
bas$dfargs$m = k
bas$dfargs$df1 = bas$dffun # this is the dffun for the 1st analysis
bas$dfargs$B = cov(t(allb[notna, , drop = FALSE]))
bas$V = bas$dfargs$T = V + (k + 1)/k * bas$dfargs$B # pooled via Rubin's rules
bas$dffun = function(a, dfargs) { # pretty much copied from mice:::barnard.rubin
dfcom = dfargs$df1(a, dfargs)
with(dfargs, {
b = sum(a * (B %*% a))
t = sum(a * (T %*% a))
lambda = (1 + 1/m) * b / t
dfold = (m - 1)/lambda*2
dfobs = (dfcom + 1)/(dfcom + 3) * dfcom * (1 - lambda)
ifelse(is.infinite(dfcom), dfold,
dfold * dfobs/(dfold + dfobs))
}) }
bas
}
4 changes: 3 additions & 1 deletion vignettes/models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ a smoothing method like `pb()`.
These objects are the results of fitting several models with different predictor
subsets or imputed values. The `bhat` and `V` slots are obtained via averaging
and, in the case of multiple imputation, adding a multiple of the between-imputation
covariance per Rubin's rules. In the case of `mira` models with model classes not
covariance per Rubin's rules, along with an associated degrees-of-freedom
adjustment (Barnard & Rubin 1999).
In the case of `mira` models with model classes not
supported by **emmeans**, [GitHub issue #446](https://github.com/rvlenth/emmeans/issues/446)
includes a function `pool_estimates_for_qdrg()` that may be useful for obtaining
results via `qdrg()`.
Expand Down

0 comments on commit 3af99bb

Please sign in to comment.