rsimsum 0.11.0

rstats
rsimsum
release
Introducing the latest release of the {rsimsum} package, version 0.11.0.
Published

October 26, 2021

Hello!

It’s been a while since the last post on this website… don’t worry (I am sure you didn’t), I’m still here, just been busy with a bunch of life- and work-related things.

This post is to introduce the latest release of the {rsimsum} R package, version 0.11.0, which landed on CRAN last week, on October 20th.

This is a minor release, with some bug fixes and (more interestingly) the introduction of a new feature that was suggested in #22 on GitHub by Li Ge: print() methods for summary objects now invisibly return the formatted tables that are printed to the console.

Ok, but why should I care about that?

It’s simple: you can print subset of results (e.g. for a presentation) much more easily, as the internals of {rsimsum} will deal with some of the formatting for you.

Here’s an example, using the MIsim dataset that comes bundled with the package:

library(rsimsum)
data("MIsim", package = "rsimsum")

We summarise this simulation study as showed in the documentation here:

s <- simsum(
  data = MIsim,
  estvarname = "b",
  se = "se",
  true = 0.5,
  methodvar = "method",
  ref = "CC"
)
sums <- summary(s, stats = c("bias", "cover"))
sums
Values are:
    Point Estimate (Monte Carlo Standard Error)

Bias in point estimate:
              CC         MI_LOGT             MI_T
 0.0168 (0.0048) 0.0009 (0.0042) -0.0012 (0.0043)

Coverage of nominal 95% confidence interval:
              CC         MI_LOGT            MI_T
 0.9430 (0.0073) 0.9490 (0.0070) 0.9430 (0.0073)

This is the standard workflow, and we focus on bias and coverage probability for simplicity. At this point, we could copy-paste a subset of the above results in our slides-making tool of choice.

However, that’s not particularly user-friendly, nor easily reproducible (e.g. if you run more iterations and need to update your results). Here’s where invisibly-returned formatted tables come handy:

output <- print(sums)
Values are:
    Point Estimate (Monte Carlo Standard Error)

Bias in point estimate:
              CC         MI_LOGT             MI_T
 0.0168 (0.0048) 0.0009 (0.0042) -0.0012 (0.0043)

Coverage of nominal 95% confidence interval:
              CC         MI_LOGT            MI_T
 0.9430 (0.0073) 0.9490 (0.0070) 0.9430 (0.0073)

Note here that the output of sums is printed once again, but it is also stored in a variable named output, which contains the formatted tables for each summary statistic of interest:

str(output)
List of 2
 $ Bias in point estimate                     :'data.frame':    1 obs. of  3 variables:
  ..$ CC     : chr "0.0168 (0.0048)"
  ..$ MI_LOGT: chr "0.0009 (0.0042)"
  ..$ MI_T   : chr "-0.0012 (0.0043)"
 $ Coverage of nominal 95% confidence interval:'data.frame':    1 obs. of  3 variables:
  ..$ CC     : chr "0.9430 (0.0073)"
  ..$ MI_LOGT: chr "0.9490 (0.0070)"
  ..$ MI_T   : chr "0.9430 (0.0073)"

With this data at our disposal, we can finally print a better table using the general-purpose kable() function from the {knitr} package:

w <- output$`Bias in point estimate`
knitr::kable(
  x = w,
  align = rep("c", ncol(w))
)
CC MI_LOGT MI_T
0.0168 (0.0048) 0.0009 (0.0042) -0.0012 (0.0043)

Of course we would need to further improve on this for production (e.g. it now spans the whole width of the enclosing <div>, we might want to style it and resize it accordingly using css), but it is already a clear improvement. Most interestingly, consider including all of the above in a dynamically updated slides deck (e.g. created using the {xaringan} package): much better than before, with very little extra work, and plenty of room for further adjustments if you wish. Not bad!

Finally, the example above is for the summary.simsum() method: this is implemented for multiple estimands as well (in the summary.multisimsum() function), with an additional layer of nesting for the formatted output. I’m sure it’ll be straightforward to figure that out if you want to try it out, let me know if it isn’t.

That’s all for now, hope you find this useful and if you have further suggestions for features you’d like to see in {rsimsum}, don’t hesitate to get in touch or to open an issue on GitHub.