Analyze Data from Stepped Wedge Cluster Randomized Trials
Overview
Provide various functions and tools to help fit models for estimating treatment effects in stepped wedge cluster randomized trials. Implements methods described in Kenny, Voldal, Xia, and Heagerty (2022) "Analysis of stepped wedge cluster randomized trials in the presence of a time-varying treatment effect", doi:10.1002/sim.9511.
Install
Health
ERRORexamplesr-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-release-linux-x86_64
r-devel-linux-x86_64-debian-gcc, r-release-linux-x86_64
Running examples in ‘steppedwedge-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: analyze
> ### Title: Analyze a stepped wedge dataset
> ### Aliases: analyze
>
> ### ** Examples
>
> # Load data
> test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL,
+ treatment = "trt", outcome = "outcome_cont", data = sw_data_example)
Stepped wedge dataset loaded. Discrete time design with 15 clusters, 5 sequences, and 6 time points.
>
> # Analysis example 1: TATE estimand for exposure times 1 through 4
> results_tate <- analyze(dat = test_data, method = "mixed", estimand_type = "TATE",
+ estimand_time = c(1, 4), exp_time = "ETI")
Error in model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, :
invalid type (closure) for variable '(offset)'
Calls: analyze ... mkFormula -> eval -> eval -> <Anonymous> -> model.frame.default
Execution haltedr-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc
Running examples in ‘steppedwedge-Ex.R’ failed The error most likely occurred in: > ### Name: analyze > ### Title: Analyze a stepped wedge dataset > ### Aliases: analyze > > ### ** Examples > > # Load data > test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, + treatment = "trt", outcome = "outcome_cont", data = sw_data_example) Stepped wedge dataset loaded. Discrete time design with 15 clusters, 5 sequences, and 6 time points. > > # Analysis example 1: TATE estimand for exposure times 1 through 4 > results_tate <- analyze(dat = test_data, method = "mixed", estimand_type = "TATE", + estimand_time = c(1, 4), exp_time = "ETI") Error in model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, : invalid type (closure) for variable '(offset)' Calls: analyze ... mkFormula -> eval -> eval -> <Anonymous> -> model.frame.default Execution halted
ERRORre-building of vignette outputsr-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-release-linux-x86_64
r-devel-linux-x86_64-debian-gcc, r-release-linux-x86_64
Error(s) in re-building vignettes:
...
--- re-building ‘steppedwedge.Rmd’ using rmarkdown
Quitting from steppedwedge.Rmd:62-73 [unnamed-chunk-5]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error in `model.frame.default()`:
! invalid type (closure) for variable '(offset)'
---
Backtrace:
▆
1. └─steppedwedge::analyze(...)
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'steppedwedge.Rmd' failed with diagnostics:
invalid type (closure) for variable '(offset)'
--- failed re-building ‘steppedwedge.Rmd’
SUMMARY: processing the following file failed:
‘steppedwedge.Rmd’
Error: Vignette re-building failed.
Execution haltedr-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc
Error(s) in re-building vignettes:
--- re-building ‘steppedwedge.Rmd’ using rmarkdown
Quitting from steppedwedge.Rmd:62-73 [unnamed-chunk-5]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error in `model.frame.default()`:
! invalid type (closure) for variable '(offset)'
---
Backtrace:
▆
1. └─steppedwedge::analyze(...)
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'steppedwedge.Rmd' failed with diagnostics:
invalid type (closure) for variable '(offset)'
--- failed re-building ‘steppedwedge.Rmd’
SUMMARY: processing the following file failed:
‘steppedwedge.Rmd’
Error: Vignette re-building failed.
Execution haltedERRORtestsr-devel-linux-x86_64-debian-gcc, r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-release-linux-x86_64
r-devel-linux-x86_64-debian-gcc
Running ‘testthat.R’ [3s/4s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
> # * https://testthat.r-lib.org/articles/special-files.html
>
> library(testthat)
> library(steppedwedge)
>
> test_check("steppedwedge")
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Saving _problems/test-analyze_data-33.R
Saving _problems/test-analyze_data-40.R
Saving _problems/test-analyze_data-47.R
Saving _problems/test-analyze_data-78.R
Saving _problems/test-analyze_data-88.R
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Stepped wedge dataset loaded. Discrete
...[truncated]...
└─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
── Error ('test-analyze_data.R:87:3'): Function handles different family and link functions ──
Error in `model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, formula = outcome ~ factor(time) - 1 + treatment + (1 + cluster_id) + (1 + ij))`: invalid type (closure) for variable '(offset)'
Backtrace:
▆
1. └─steppedwedge::analyze(...) at test-analyze_data.R:87:3
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 24 ]
Error:
! Test failures.
Execution haltedr-devel-linux-x86_64-fedora-clang
Running ‘testthat.R’
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
> # * https://testthat.r-lib.org/articles/special-files.html
>
> library(testthat)
> library(steppedwedge)
>
> test_check("steppedwedge")
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Saving _problems/test-analyze_data-33.R
Saving _problems/test-analyze_data-40.R
Saving _problems/test-analyze_data-47.R
Saving _problems/test-analyze_data-78.R
Saving _problems/test-analyze_data-88.R
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Stepped wedge dataset loaded. Discrete time de
...[truncated]...
└─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
── Error ('test-analyze_data.R:87:3'): Function handles different family and link functions ──
Error in `model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, formula = outcome ~ factor(time) - 1 + treatment + (1 + cluster_id) + (1 + ij))`: invalid type (closure) for variable '(offset)'
Backtrace:
▆
1. └─steppedwedge::analyze(...) at test-analyze_data.R:87:3
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 24 ]
Error:
! Test failures.
Execution haltedr-devel-linux-x86_64-fedora-gcc
Running ‘testthat.R’ [4s/11s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
> # * https://testthat.r-lib.org/articles/special-files.html
>
> library(testthat)
> library(steppedwedge)
>
> test_check("steppedwedge")
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Saving _problems/test-analyze_data-33.R
Saving _problems/test-analyze_data-40.R
Saving _problems/test-analyze_data-47.R
Saving _problems/test-analyze_data-78.R
Saving _problems/test-analyze_data-88.R
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Stepped wedge dataset loaded. Discret
...[truncated]...
└─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
── Error ('test-analyze_data.R:87:3'): Function handles different family and link functions ──
Error in `model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, formula = outcome ~ factor(time) - 1 + treatment + (1 + cluster_id) + (1 + ij))`: invalid type (closure) for variable '(offset)'
Backtrace:
▆
1. └─steppedwedge::analyze(...) at test-analyze_data.R:87:3
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 24 ]
Error:
! Test failures.
Execution haltedr-release-linux-x86_64
Running ‘testthat.R’ [5s/9s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
> # * https://testthat.r-lib.org/articles/special-files.html
>
> library(testthat)
> library(steppedwedge)
>
> test_check("steppedwedge")
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Saving _problems/test-analyze_data-33.R
Saving _problems/test-analyze_data-40.R
Saving _problems/test-analyze_data-47.R
Saving _problems/test-analyze_data-78.R
Saving _problems/test-analyze_data-88.R
Stepped wedge dataset loaded. Discrete time design with 2 clusters, 2 sequences, and 3 time points.
Stepped wedge dataset loaded. Discrete
...[truncated]...
└─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
── Error ('test-analyze_data.R:87:3'): Function handles different family and link functions ──
Error in `model.frame.default(data = dat, offset = offset, drop.unused.levels = TRUE, formula = outcome ~ factor(time) - 1 + treatment + (1 + cluster_id) + (1 + ij))`: invalid type (closure) for variable '(offset)'
Backtrace:
▆
1. └─steppedwedge::analyze(...) at test-analyze_data.R:87:3
2. ├─lme4::glmer(formula, family = family, data = dat, offset = offset)
3. │ └─base::eval(mc, parent.frame(1L))
4. │ └─base::eval(mc, parent.frame(1L))
5. ├─lme4::glFormula(...)
6. │ └─lme4:::mkFormula(...)
7. │ └─base::eval(mf, parent_env)
8. │ └─base::eval(mf, parent_env)
9. ├─stats::model.frame(...)
10. └─stats::model.frame.default(...)
[ FAIL 5 | WARN 0 | SKIP 0 | PASS 24 ]
Error:
! Test failures.
Execution halted- ERROR9 OK, 4 ERRORNow
- ERROR11 OK, 2 ERROR2026-10-24
- OK13 OK2026-08-04
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-07-23
- ERROR12 OK, 1 ERROR2026-07-07
Show 3 earlier changesHide 3 earlier changes
- OK13 OK2026-06-09
- ERROR12 OK, 1 ERROR2026-06-08
- OK14 OK2026-03-10
Documentation
- Help pages
- 6 (1 internal)includes a package overview page
- Examples that run
- 100%4 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 97%
- Return-value docs
- 100%
- Help pages citing references
- 0%
Downloads
Repository
- PRs merged (all time)
- not measured
- Median days to close, 50 most recently updated closed issues
- 48
- Median days to close, 50 most recently updated closed PRs
- not measured
Issues over time
Commits over time
10 development-tooling and community-health practices detected across 6 families in the upstream repository
Checks run against github.com/avi-kenny/steppedwedge on 2026-10-21.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-08-14 · The repository has a site deploy workflow
pkgdown site last built 2026-08-14
Show all practicesHide 2 practices
Dependencies
Installing steppedwedge adds 45 packages (23 with compiled code, 45 MB of source tarballs). Heaviest: stringi 11 MB, ggplot2 6.0 MB, lme4 4.3 MB.
CRAN will archive these unless their check problems are fixed by the date shown. This package needs each one to install.
- insight through performancefix by Nov 14
Code & Tests
Datasets
People & History
- RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- 1.0.0Latest2025-02-21 · current release
- RR 4.4.0 released · 2024-04-24
Package metadata
- First published
- 2025-02-21
- Total releases
- 1 / 1 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 2.10
- Bundled data
- 19 KB / 1 file
- Download size
- 478 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("steppedwedge")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-25, which the citation names so these numbers can be found later. More on citing and the projects behind them.