When a specification curve analysis requires the estimation of several thousand models, the procedure can take quite a while. In those cases, it would be nice to have some sort of indicator of the progress (both to feel confident that the procedure is still running and to have an idea of how long the procedure will still take).

1. Create customized model function

To run the specification curve with a progress bar, we need to include pb$tick() in the model function.

library(specr)

# Set up specific lm function
linear <- function(formula, data) {
  pb$tick()
  glm(formula = formula, data = data, family = gaussian(link = "identity"))
}

2. Provide number of ticks

Next, we can use the function progress_bar() from the package progress. The only thing we need to due is provide the number of ticks (i.e., operations) that will be computed

library(progress)

# Provide number of ticks
pb <- progress_bar$new(format = "[:bar] | :percent (:current/:total) | Finished in:eta",
                       width = 100,
                       total = 192)

3. Run analysis

# run spec analysis
results <- run_specs(example_data,
                     y = c("y1", "y2"),
                     x = c("x1", "x2"),
                     model = "linear",      # use customized function
                     controls = c("c1", "c2"),
                     subset = list(group1 = unique(example_data$group1),
                                   group2 = unique(example_data$group2)))

The console will now show a progress bar during estimation. For more information and additional customizations see: https://github.com/r-lib/progress.

## # A tibble: 1 x 7
##   median   mad   min   max   q25   q75   obs
##    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1   3.59  4.56 -2.05  9.58  1.03  7.63   123