Title: | Analyze Data from Stepped Wedge Cluster Randomized Trials |
---|---|
Description: | 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>. |
Authors: | Avi Kenny [aut, cre, cph], David Arthur [aut], Yongdong Ouyang [aut] |
Maintainer: | Avi Kenny <[email protected]> |
License: | GPL-3 |
Version: | 1.0.0 |
Built: | 2025-03-13 20:19:48 UTC |
Source: | https://github.com/avi-kenny/steppedwedge |
Analyze a stepped wedge dataset
analyze( dat, method = "mixed", estimand_type = "TATE", estimand_time = c(1, attr(dat, "n_seq")), exp_time = "IT", cal_time = "categorical", family = stats::gaussian, re = c("clust", "time"), corstr = "exchangeable", offset = NULL, n_knots_exp = 4, n_knots_cal = 4 )
analyze( dat, method = "mixed", estimand_type = "TATE", estimand_time = c(1, attr(dat, "n_seq")), exp_time = "IT", cal_time = "categorical", family = stats::gaussian, re = c("clust", "time"), corstr = "exchangeable", offset = NULL, n_knots_exp = 4, n_knots_cal = 4 )
dat |
A dataframe containing the stepped wedge trial data. |
method |
A character string; either "mixed", for a mixed-effects model, or "GEE", for generalized estimating equations. |
estimand_type |
One of c("TATE", "PTE"); "TATE" represents the time-averaged treatment effect and "PTE" represents the point treatment effect. |
estimand_time |
An integer vector of length 1 or 2. When estimand_type="TATE", 'estimand_time' must be a numeric vector of length 2, representing the start and end times of the exposure time period to average over. When estimand_type="PTE", 'estimand_time' must be a numeric vector of length 1, representing the time period of interest. See examples. |
exp_time |
One of c("IT", "ETI", "NCS", "TEH"); model for exposure time. "IT" encodes an immediate treatment model with a single treatment effect parameter. "ETI" is an exposure time indicator model, including one indicator variable for each exposure time point. "NCS" uses a natural cubic spline model for the exposure time trend. "TEH" includes a random slope term in the model, allowing the treatment effect to vary by timepoint. |
cal_time |
One of c("categorical", "NCS", "linear", "none"); model for calendar time. "categorical" uses indicator variables for discrete time points, as in the Hussey and Hughes model. "NCS" uses a natural cubic spline, useful for datasets with continuous time. "linear" uses a single slope parameter. "none" assumes that there is no underlying calendar time trend. |
family |
A family object; see documentation for 'glm'. |
re |
A character vector of random effects to include; only relevant if method="mixed" is used. Possible random effects include "clust" (random intercept for cluster), "time" (random intercept for cluster-time interaction), "ind" (random intercept for individuals; appropriate when a cohort design is used), "tx" (random treatment effect) |
corstr |
One of c("independence", "exchangeable", "ar1"); only relevant if method="GEE" is used. Defines the GEE working correlation structure; see the documentation for 'geepack::geeglm'. |
offset |
A linear predictor offset term; see docs for 'lme4::lmer'. |
n_knots_exp |
An integer; only relevant when exp_time="NCS". Specifies the number of knots to use for exposure time, including boundary knots. The spline basis includes an intercept, and the degree of the basis is equal to the number of knots. |
n_knots_cal |
An integer; only relevant when exp_time="NCS". Specifies the number of knots to use for calendar time, including boundary knots. The spline basis includes an intercept, and the degree of the basis is equal to the number of knots. |
A list with the model object, model type as a string, estimand type as a string, numeric treatment effect estimate, numeric treatment effect standard error, treatment effect 95 dataframe with treatment effect at each exposure timepoint.
# Load data test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) # 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") results_tate # Analysis example 2: PTE estimand for exposure time 3 results_pte <- analyze(dat = test_data, method = "mixed", estimand_type = "PTE", estimand_time = 3, exp_time = "ETI") results_pte
# Load data test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) # 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") results_tate # Analysis example 2: PTE estimand for exposure time 3 results_pte <- analyze(dat = test_data, method = "mixed", estimand_type = "PTE", estimand_time = 3, exp_time = "ETI") results_pte
Load and format data object
load_data( time, cluster_id, individual_id = NULL, treatment, outcome, time_type = "discrete", data )
load_data( time, cluster_id, individual_id = NULL, treatment, outcome, time_type = "discrete", data )
time |
A character string; the name of the numeric variable representing time. Time can be either discrete or continuous. |
cluster_id |
A character string; the name of the numeric variable identifying the cluster. |
individual_id |
A character string (optional); the name of the numeric variable identifying the individual. |
treatment |
A character string; the name of the binary variable indicating treatment. Values must be either integers (0/1) or Boolean (T/F). |
outcome |
Either a character string or a vector of two character strings; for a numeric or binary outcome, the single character string indicates the name of the numeric or binary outcome variable; for binomial outcome data, the vector of two character strings indicates the "# of successes" variable and the "# of trials" variable, respectively. Values in the outcome variable(s) must be either numeric or Boolean (T/F). |
time_type |
One of c("discrete", "continuous"); whether the model treats time as discrete or continuous. |
data |
A dataframe containing the stepped wedge trial data. |
An object of class sw_data
example_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) base::summary(example_data)
example_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) base::summary(example_data)
Plot stepped wedge design
plot_design(dat)
plot_design(dat)
dat |
A dataframe containing the stepped wedge trial data. |
A list with a plot of the stepped wedge design.
# Load data example_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) # Plot design plot_design(example_data)
# Load data example_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_cont", data = sw_data_example) # Plot design plot_design(example_data)
Summarize a list returned by steppedwedge::analysis()
## S3 method for class 'sw_analysis' print(x, ...)
## S3 method for class 'sw_analysis' print(x, ...)
x |
A list returned by steppedwedge::analysis() |
... |
Additional arguments |
A summary of the analysis object, including an estimate and 95
# Load data test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_bin", data = sw_data_example) # Analysis example: 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", family = poisson) results_tate
# Load data test_data <- load_data(time ="period", cluster_id = "cluster", individual_id = NULL, treatment = "trt", outcome = "outcome_bin", data = sw_data_example) # Analysis example: 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", family = poisson) results_tate
Data generated for the purpose of demonstrating the steppedwedge package
sw_data_example
sw_data_example
## 'sw_data_example' A data frame with 2,063 rows and 6 columns:
Cluster id
Time period
Treatment indicator
Binary outcome
Continuous outcome
...