`tidy` and `glance` methods
Closed this issue · 2 comments
I am the developer of the modelsummary
package which creates summary tables and plots for statistical models.
To extract info from fitted model, this package uses tidy
and glance
methods which conform to the broom
standard: https://broom.tidymodels.org/
The broom
standard is nice because it gives users a single unified interface to extract info from various objects. I'm opening this issue in case you think it would be a good idea to include such methods in your package. The benefit is that your objects would be automatically supported by packages like modelsummary
and gtsummary
and texreg
. Users could then do this:
library(mitml)
library(lme4)
library(modelsummary)
data(studentratings)
fml <- ReadAchiev + ReadDis + SchClimate ~ 1 + (1|ID)
imp <- panImpute(studentratings, formula = fml, silent = TRUE, m = 24)
implist <- mitmlComplete(imp, "all")
fit <- with(implist, lmer(ReadAchiev ~ 1 + ReadDis + (1|ID)))
modelsummary(fit)
Here are minimal working methods:
tidy.mitml.result <- function(x, ...) {
out <- testEstimates(x)
out <- as.data.frame(out$estimates[, c(1:3, 5)])
colnames(out) <- c("estimate", "std.error", "statistic", "p.value")
out$term <- row.names(out)
return(out)
}
glance.mitml.result <- function(x, ...) {
data.frame(nimp = length(x),
nobs = nobs(x[[1]]))
}
Thanks. I think this is a good idea, but I was wondering: Shouldn't these methods be included in broom
instead? This seems to be the intended way of expanding the scope of tidy
and glance
methods (including them in mitml
might lead to duplicate methods in the future). I'm going to close this issue for now, but I can reopen and you're of course also welcome to create a PR on the broom
repo.
Some remarks on the methods:
-
I would prefer if these methods were defined for class
mitml.testEstimates
(the pooled results) rather thanmitml.result
(the individual results) and similar methods could be included formitml.testModels
(the output from pooled model comparisons). From what I see, the only disadvantage would be the lack of an "nobs", but this could be replaced with thedf.com
slot (if non-NULL). -
The tidy method should ideally refer to the columns by name, and I think some options to include the degrees of freedom and FMI per parameter would be useful.
-
testEstimates(..., extra.pars = TRUE)
also gives additional results depending on the model type. I'm not sure how best to deal with these, but it'd be great if they were included.
Thanks for the suggestions!
Currently, the broom
developers (mostly) do not merge in new methods, and instead recommend that modeling package developers supply their own methods (loading the dependency-free and very thin generics
package).
FWIW, I do not use mitml
myself, so I am unlikely to work on PR, and it's perfectly fine if you prefer to close this.
Thanks for releasing open source software!