Skip to content

infer 1.1.0

Latest

Choose a tag to compare

@simonpcouch simonpcouch released this 18 Dec 14:12
8c51276

Arbitrary test statistics in calculate

In a change originally motivated by Allen Downey's posit::conf(2024) keynote notes, the package introduced support for arbitrary test statistics in calculate(). In addition to the pre-implemented calculate(stat) options, taken as strings, users can now supply any function defining a scalar-valued test statistic.

The function should have arguments stat(x, order, ...), where x is one replicate's worth of x. The order argument and ellipses will be supplied directly to the stat function. Internally, calculate() will split x up into data frames by replicate and pass them one-by-one to the supplied stat.

For example, to implement stat = "mean" as a function, one could write:

stat_mean <- function(x, order, ...) {mean(x$hours)}
obs_mean <-
  gss %>%
  specify(response = hours) %>%
  calculate(stat = stat_mean)

set.seed(1)

null_dist_mean <-
  gss %>%
  specify(response = hours) %>%
  hypothesize(null = "point", mu = 40) %>%
  generate(reps = 5, type = "bootstrap") %>%
  calculate(stat = stat_mean)

Note that the same stat_mean function is supplied to both generate()d and non-generate()d infer objects--no need to implement support for grouping by replicate yourself.

See?calculate() to learn more (#542).

Bug fixes

Also, fixed a bug where adding shade_confidence_interval(NULL) or shade_p_value(NULL) to plots resulted in list() rather than the unmodified plot (#566).