Skip to content

Mice package compatibility #194

@abrisco17

Description

@abrisco17

Hi, is there any intention in adding mice comparability? I wanted to have a table for the pooled regression, so I wrote an extractor function for the "mira" object, which is the output after the new imputed datasets are fitted onto the original data. The pooling occurs in the extraction.

library(texreg)
library(mice)

extract.mira <- function(model, include.rsquared = TRUE, include.adjrs = TRUE, include.nobs = TRUE, ...){
  s <- summary(pool(model, ...))
  names <- as.character(s$term)
  co <- s$estimate
  se <- s$std.error
  pval <- s$p.value
  rs <- pool.r.squared(model)[1,1]
  adj <- pool.r.squared(model, adjusted = T)[1,1]
  n <- nobs(summary(model))[1]
  gof <- numeric()
  gof.names <- character()
  gof.decimal <- logical()
  
  if (include.rsquared == T) {
    gof <- c(gof, rs)
    gof.names <- c(gof.names, "R$^2$")
    gof.decimal <- c(gof.decimal, TRUE)
  }
  if (include.adjrs == T) {
    gof <- c(gof, adj)
    gof.names <- c(gof.names, "Adj.\ R$^2$")
    gof.decimal <- c(gof.decimal, TRUE)
  }
  if (include.nobs == T) {
    gof <- c(gof, n)
    gof.names <- c(gof.names, "Num.\ obs.")
    gof.decimal <- c(gof.decimal, FALSE)
  }
  
  tr <- createTexreg(
    coef.names=names,
    coef=co,
    se=se,
    pvalues=pval,
    gof.names=gof.names,
    gof=gof,
    gof.decimal=gof.decimal
  )
  return(tr)
}

setMethod("extract", signature = className("mira", "mice"), definition = extract.mira)

airquality_lm <- lm(Temp ~ Solar.R + Ozone + Wind, airquality)
airquality_imp <- mice(airquality, seed = 1)
airquality_fitted <- with(airquality_imp, lm(Temp ~ Solar.R + Ozone + Wind))

screenreg(list(airquality_lm, airquality_fitted))

It seems to work fine, but I wasn't sure if this was the best way, especially mice has some many objects, and it's not necessarily clear what to do if you want all the calculated regressions instead. Is there anymore development here?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions