MyNixOS website logo
Description

Power of Interrupted Time Series (ITS) Studies.

Provides tools for estimating the statistical power of Interrupted Time Series (ITS) designs, with a focus on healthcare applications. The package supports prospective power calculations before a study begins, and retrospective assessments of whether a completed study was adequately powered. It includes functions to estimate nuisance parameters (baseline, residual standard deviation, autocorrelation) from data observed before the intervention, and to estimate power via Monte Carlo simulation for single-site and multi-site designs. Utility functions for design optimisation sweeps and publication- ready plots are also provided.

PITS — Power of an Interrupted Time Series

R-CMD-check License: MIT R >= 4.0

An R package for estimating the statistical power of Interrupted Time Series (ITS) studies, with a focus on healthcare applications.

Use PITS to answer:

"How many months of post-intervention follow-up do I need to reliably detect a meaningful effect in my ITS study?"


Installation

# From GitHub (once published):
# install.packages("remotes")
# remotes::install_github("drdaviddelorenzo/PITS")

# From source:
install.packages("path/to/PITS", repos = NULL, type = "source")

Dependency:nlme (ships with base R). No other dependencies required.


Workflow

Pre-intervention data (CSV or data frame)
             ↓
  estimate_its_params()
             ↓
  baseline, sigma, rho
             ↓
  + level_change  ← your clinical hypothesis
             ↓
  calculate_power() / power_sweep()
             ↓
  Choose n_post that achieves ≥ 80% power

Quick start

library(PITS)

# 1. Load your pre-intervention data (or use the built-in example)
data("example_cfr_data")

# 2. Estimate nuisance parameters
params <- estimate_its_params(example_cfr_data)
#   n_pre     = 24
#   baseline  = 15.0   (mean pre-intervention CFR, %)
#   sigma     = 2.15   (residual SD)
#   rho       = 0.22   (AR(1) autocorrelation)

# 3. Calculate power for a candidate design
result <- calculate_power(
  n_pre        = params$n_pre,
  n_post       = 30,             # planned follow-up months
  baseline     = params$baseline,
  level_change = -3,             # minimum clinically meaningful effect
  sigma        = params$sigma,
  rho          = params$rho,
  n_sim        = 1000,
  seed         = 123
)
result$power_pct      # e.g. 78.4%
result$interpretation # "Borderline (60-79%)"

# 4. Optimise with a sweep
sweep <- power_sweep(
  sweep_post   = c(12, 18, 24, 30, 36, 48),
  n_pre        = params$n_pre,
  baseline     = params$baseline,
  level_change = -3,
  sigma        = params$sigma,
  rho          = params$rho,
  n_sim        = 1000
)
plot_power_curve(sweep)

# 5. One-call shortcut
result <- estimate_and_calculate(
  data         = example_cfr_data,
  level_change = -3,
  n_post       = 30
)

Function reference

Parameter estimation

FunctionDescription
estimate_its_params(data)Estimate all nuisance parameters at once
estimate_baseline(outcome)Baseline (intercept at t = 1)
estimate_sigma(outcome)Residual standard deviation
estimate_rho(outcome)AR(1) autocorrelation
estimate_trend(outcome)Pre-intervention trend (slope)

Power simulation

FunctionDescription
calculate_power(...)Monte Carlo power — single site
calculate_power_multi(sites, ...)Monte Carlo power — multiple sites
power_sweep(sweep_post, ...)Power across a range of n_post values
build_param_grid(...)Factorial parameter grid
run_power_grid(grid, ...)Power across a full parameter grid

Plots and diagnostics

FunctionDescription
plot_power_curve(sweep)Line plot of power vs n_post
plot_power_heatmap(grid)Colour grid of power over two parameters
plot_its_example(...)Simulated ITS series with fitted model
diagnose_params(data)2×2 diagnostic panel for pre-intervention data

Utilities and wrappers

FunctionDescription
interpret_power(power)Qualitative label (Adequate / Borderline / Underpowered)
validate_params(...)Check parameters before simulation
simulate_predata(...)Generate synthetic pre-intervention data
export_results(result)Save results to CSV and text file
run_its_power(...)Full single-site workflow with console output
estimate_and_calculate(data, ...)Parameter estimation + power in one call

Key parameters

ParameterWhat it isHow to set it
n_prePre-intervention time pointsFixed — use your historical data
n_postPost-intervention time pointsDesign lever — use power_sweep() to optimise
baselineMean pre-intervention outcomeFrom estimate_its_params()
sigmaResidual SD (noise)From estimate_its_params()
rhoAR(1) autocorrelationFrom estimate_its_params(); use 0.4 if unknown
level_changeMinimum meaningful step changeClinical hypothesis — set based on expert judgement
slope_changeMinimum meaningful trend changeClinical hypothesis — set to 0 if testing level only
testEffect to test: "level", "slope", or "both"Depends on intervention type

Multi-site designs

sites <- list(
  list(name = "Hospital A", n_pre = 24, n_post = 30,
       baseline = 15, level_change = -3, slope_change = 0,
       sigma = 2.5, rho = 0.4),
  list(name = "Hospital B", n_pre = 24, n_post = 30,
       baseline = 18, level_change = -3, slope_change = 0,
       sigma = 3.0, rho = 0.4)
)
result <- calculate_power_multi(sites, n_sim = 1000, seed = 123)
result$power_pct

References

  • Lopez Bernal J, et al. (2017). Interrupted time series regression for the evaluation of public health interventions: a tutorial. Int J Epidemiol 46:348–355.
  • Zhang F, et al. (2011). Simulation-based power calculation for designing interrupted time series analyses. J Clin Epidemiol 64:1252–1261.
  • Wagner AK, et al. (2002). Segmented regression analysis of interrupted time series studies. J Clin Pharm Ther 27:299–309.

Citing PITS

@software{PITS_2026,
  title  = {PITS: Power of Interrupted Time Series Studies},
  author = {de Lorenzo, David},
  year   = {2026},
  url    = {https://github.com/drdaviddelorenzo/PITS}
}

Author

David de Lorenzo (ORCID 0000-0003-2042-0961) — UCL Great Ormond Street Institute of Child Health, London, UK; Neotree, London, UK.


Licence

MIT — see LICENSE.

Metadata

Version

0.1.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows