Package 'steppedwedge'

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-02-21 13:31:36 UTC
Source: CRAN

Help Index


Analyze a stepped wedge dataset

Description

Analyze a stepped wedge dataset

Usage

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
)

Arguments

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'.

Value

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, and treatment effect 95

Examples

# 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

Description

Load and format data object

Usage

load_data(
  time,
  cluster_id,
  individual_id = NULL,
  treatment,
  outcome,
  time_type = "discrete",
  data
)

Arguments

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.

Value

An object of class sw_data

Examples

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

Description

Plot stepped wedge design

Usage

plot_design(dat)

Arguments

dat

A dataframe containing the stepped wedge trial data.

Value

A list with a plot of the stepped wedge design.

Examples

# 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()

Description

Summarize a list returned by steppedwedge::analysis()

Usage

## S3 method for class 'sw_analysis'
print(x, ...)

Arguments

x

A list returned by steppedwedge::analysis()

...

Additional arguments

Value

A summary of the analysis object, including an estimate and 95

Examples

# 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

Example stepped wedge data

Description

Data generated for the purpose of demonstrating the steppedwedge package

Usage

sw_data_example

Format

## 'sw_data_example' A data frame with 2,063 rows and 6 columns:

cluster

Cluster id

period

Time period

trt

Treatment indicator

outcome_bin

Binary outcome

outcome_cont

Continuous outcome

...