Code
library(tidyverse)
library(targets)
library(brms)
library(glue)
library(gt)
library(lubridate)
library(here)

tar_config_set(store = here::here('_targets'),
               script = here::here('_targets.R'))

# Models
tar_load(c(m_policies, m_human_rights))
Code
model_times <- bind_rows(list("**H<sub>1</sub>: Derogations and emergency policies**" = m_policies, 
                              "**H<sub>2</sub>: Derogations and human rights**" = m_human_rights), 
                         .id = "hypothesis") %>%  
  mutate(family = case_when(
    family == "cumulative" ~ "Ordered logistic",
    family == "bernoulli" | is.na(family) ~ "Logistic"
  )) %>% 
  mutate(duration = map(model, ~{
    .$fit %>% 
      rstan::get_elapsed_time() %>% 
      as_tibble() %>% 
      summarize(total = as.duration(max(warmup + sample)))
  })) %>% 
  select(-prior, -y, -never, -data, -model) %>% 
  unnest(duration)

dur <- as.period(as.duration(sum(model_times$total)))

total_run_time <- glue("{hours} hours, {minutes} minutes, and {seconds} seconds",
                       hours = hour(dur), minutes = minute(dur), seconds = round(second(dur), 0))

We ran these models on a 2021 M1 MacBook Pro with 32 GB of RAM, with 4 MCMC chains spread across 8 cores, with two CPU threads per chain, using Stan through brms through cmdstanr.

In total, it took 0 hours, 40 minutes, and 7 seconds to run everything.

Code
model_times %>% 
  gt(rowname_col = "nice",
     groupname_col = "hypothesis",
     process_md = TRUE) %>% 
  cols_label(
    family = md("**Model family**"),
    total = md("**Total time** (i.e. longest chain)")
  ) %>% 
  tab_stubhead(label = md("**Outcome**")) %>% 
  cols_align(
    align = "left",
    columns = everything()
  ) %>%
  summary_rows(
    groups = everything(), 
    columns = c(total),
    fns = list(Total = ~as.duration(sum(.)))
  ) %>% 
  grand_summary_rows(
    columns = c(total),
    fns = list(`Overall total` = ~as.duration(sum(.)))
  ) %>% 
  tab_style(
    style = cell_text(align = "left", indent = px(15)),
    locations = cells_stub()
  ) %>% 
  opt_horizontal_padding(scale = 3) %>% 
  opt_vertical_padding(scale = 1) %>% 
  tab_options(table.width = pct(80))
Outcome Model family Total time (i.e. longest chain)
H1: Derogations and emergency policies

Cancel Public Events

Logistic 49.739s

Gathering Restrictions

Logistic 164.38s (~2.74 minutes)

Close Public Transit

Logistic 42.471s

Movement

Logistic 39.162s

International Travel

Logistic 64.474s (~1.07 minutes)
Total 360.226s (~6 minutes)
H2: Derogations and human rights

Discriminatory Policy

Ordered logistic 670.246s (~11.17 minutes)

Non-Derogable Rights

Logistic 37.946s

No Time Limit Measures

Ordered logistic 728.143s (~12.14 minutes)

Abusive Enforcement

Ordered logistic 610.684s (~10.18 minutes)
Total 2047.019s (~34.12 minutes)
Overall total 2407.245s (~40.12 minutes)