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()
  lm(formula = formula, data = data)
}

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. Attention: If you want to rerun the analysis, you also need to reinitialize this pb object.

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 show a progress bar during estimation. For more information, see the documentation of the package progress.

[==========================================================-------------]  81% (156/192) Finished in 1s