| Title: | Sequential Multiple Assignment Randomized Trials Design and Analyses |
|---|---|
| Description: | Implements the interim augmented inverse probability weighted estimator (IAIPWE) for estimating the value of treatment regimes embedded in sequential multiple assignment randomized trials (SMARTs). The IAIPWE subsumes both the inverse probability weighted estimator (IPWE) and the augmented inverse probability weighted estimator (AIPWE), enabling inference at interim and final analyses. The package provides functions for value estimation, sandwich variance computation, group sequential stopping boundaries, and sample size determination for multi-stage SMARTs with up to two treatment options at each stage. See Manschot, Laber, and Davidian (2023) <doi:10.1111/biom.13854> for additional details. |
| Authors: | Cole Manschot [aut, cre], Tabitha Peter [ctb], Gabriela Piasecki [ctb], Laura Frederick [ctb] |
| Maintainer: | Cole Manschot <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-10-14 02:22:16 UTC |
| Source: | https://github.com/msdllcpapers/rsmart |
Returns a randomization function compatible with sim_treatment
that implements permuted block randomization. Within each block, every
treatment appears exactly block_rep times, and the order within blocks
is randomly permuted. This ensures approximate balance across treatments at
any point during enrollment.
block_rand(block_rep = 2)block_rand(block_rep = 2)
block_rep |
A positive integer. Number of times each treatment appears
in every block. The block size is |
A function with signature function(n, n_treatments, prob)
suitable for use as rand_prob_fn in sim_treatment.
The prob argument is accepted but ignored, since blocked
randomization enforces equal allocation within each block.
# Use blocked randomization with sim_treatment set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2, rand_prob_fn = block_rand(block_rep = 2)) table(a) # Three treatments with block size 6 (block_rep = 2) set.seed(1) a <- sim_treatment(n = 300, n_treatments = 3, rand_prob_fn = block_rand(block_rep = 2)) table(a) # Stage 2 blocked randomization within prior treatment groups set.seed(1) df <- data.frame(a1 = c(rep(0, 50), rep(1, 50))) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2, rand_prob_fn = block_rand(block_rep = 3)) table(df$a1, df$a2)# Use blocked randomization with sim_treatment set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2, rand_prob_fn = block_rand(block_rep = 2)) table(a) # Three treatments with block size 6 (block_rep = 2) set.seed(1) a <- sim_treatment(n = 300, n_treatments = 3, rand_prob_fn = block_rand(block_rep = 2)) table(a) # Stage 2 blocked randomization within prior treatment groups set.seed(1) df <- data.frame(a1 = c(rep(0, 50), rep(1, 50))) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2, rand_prob_fn = block_rand(block_rep = 3)) table(df$a1, df$a2)
Wraps the outcome regression and value term functions to estimate the value of all regimes in the provided list. For each regime, Q-functions are fitted (if specified), augmentation and IPW terms are computed, and the regime value is estimated.
estimate_values(df, q_list, regime_all, feasible_sets_indicator, pis, nus)estimate_values(df, q_list, regime_all, feasible_sets_indicator, pis, nus)
df |
A data frame containing the trial data, including treatment
assignments, covariates, outcomes, and a |
q_list |
A list of outcome regression model specifications (one per
stage), or |
regime_all |
A list of regime objects, each containing a |
feasible_sets_indicator |
A logical value indicating whether feasible sets are present in the trial design. |
pis |
A data frame of estimated propensity scores with columns
|
nus |
A list as returned by |
A list with the following components:
A numeric vector of estimated regime values.
A list of matrices of value term components, augmentation terms 1 through 2K then the IPW term for each regime.
A list of fitted Q-function objects for each regime, or an
empty list if q_list is NULL.
This function generates data for a two-stage Sequential Multiple Assignment Randomized Trial (SMART) where responders are not re-randomized in the second stage. The function allows for different value patterns and treatment assignments.
gen_no_trt_resp(n, s2 = 100, block_rep = 2, r2p = 0.5)gen_no_trt_resp(n, s2 = 100, block_rep = 2, r2p = 0.5)
n |
A positive integer. Number of individuals to generate data for. |
s2 |
A positive numeric value. Variance of the error term. Default is 100. |
block_rep |
A positive integer. Number of times to duplicate treatments per block in the permuted block randomization. Default is 2. |
r2p |
A numeric value between 0 and 1. Probability of being a responder in the second stage. Default is 0.5. |
A data frame with n rows and the following columns:
Study day of enrollment.
Study day of second-stage randomization.
Study day of outcome assessment.
First-stage treatment assignment (0 or 1).
Response indicator at stage 2 (0 = non-responder, 1 = responder).
Second-stage treatment assignment (0 or 1 for non-responders, 0 for responders).
Baseline covariate (continuous, range 25–75).
Baseline covariate (binary, 0 or 1).
Stage 2 covariate (continuous, range 0–1).
Continuous outcome (higher is better).
Individual identifier (1 to n).
set.seed(1) dat <- gen_no_trt_resp(n=400, s2=100, block_rep=2, r2p = 0.5) head(dat)set.seed(1) dat <- gen_no_trt_resp(n=400, s2=100, block_rep=2, r2p = 0.5) head(dat)
Computes the An matrix, defined as ,
where is the stacked estimating equations vector. The estimating
equations are ordered to match Bn: ,
,
for each regime , and the value estimating equations
. Based on Section 7 of Boos and Stefanski for the
robust sandwich matrix.
get_an( df, pis, p_fits, nus, q_all, values, regime_all, dfs, feasible_sets_indicator, q_list )get_an( df, pis, p_fits, nus, q_all, values, regime_all, dfs, feasible_sets_indicator, q_list )
df |
A data frame containing the trial data, including treatment
assignments, covariates, outcomes, and a |
pis |
A data frame of estimated propensity scores with columns
|
p_fits |
A list of fitted propensity score model objects (one per stage),
each a |
nus |
A list as returned by |
q_all |
A list of fitted outcome regression objects for each regime,
as returned by |
values |
A numeric vector of estimated regime values. |
regime_all |
A list of regime objects, each containing a |
dfs |
A list of data frames of value term components for each regime,
as returned by |
feasible_sets_indicator |
A logical value indicating whether feasible sets are present in the trial design (i.e., some treatments are deterministic based on response status). |
q_list |
A list of outcome regression model specifications (one per stage), used to determine the number of Q-function models at each stage (e.g., separate models for responders and non-responders). |
A numeric matrix representing the An component of the sandwich variance estimator, with dimensions equal to the total number of estimated parameters.
Computes the Bn matrix, defined as ,
the empirical variance of the estimating equations. Each row of the
individual-level estimating equation matrix corresponds to one subject, with
columns ordered as , ,
for each regime
, and the value estimating equations .
Based on Section 7 of Boos and Stefanski for the robust sandwich matrix.
get_bn(df, p_fits, nus, q_all, dfs, values, feasible_sets_indicator, q_list)get_bn(df, p_fits, nus, q_all, dfs, values, feasible_sets_indicator, q_list)
df |
A data frame containing the trial data, including treatment
assignments, covariates, outcomes, and a |
p_fits |
A list of fitted propensity score model objects (one per stage),
each a |
nus |
A list as returned by |
q_all |
A list of fitted outcome regression objects for each regime,
as returned by |
dfs |
A list of data frames of value term components for each regime,
as returned by |
values |
A numeric vector of estimated regime values. |
feasible_sets_indicator |
A logical value indicating whether feasible sets are present in the trial design (i.e., some treatments are deterministic based on response status). |
q_list |
A list of outcome regression model specifications (one per stage), used to determine the number of Q-function models at each stage (e.g., separate models for responders and non-responders). |
A numeric matrix representing the Bn component of the sandwich variance estimator, with dimensions equal to the total number of estimated parameters.
Wrapper function that computes the stopping boundaries for both the first
and second analyses of a group sequential design with multiple treatment
regimes. Calls get_first_bound and get_next_bound
sequentially.
get_bounds( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, max_iter = 1000 )get_bounds( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, max_iter = 1000 )
alpha |
A numeric value specifying the overall type I error rate to control. Default is 0.05. |
inf_frac |
A numeric vector of information fractions indicating when analyses are conducted. |
spend_fn |
A character string specifying the alpha spending function.
Either |
corr |
A correlation matrix of Z-statistics at analysis time s.
Should have dimension |
test_type |
A character string specifying the type of test to be
performed. Either |
lambda |
A numeric value for the initial step size used in the iterative boundary search. Default is 0.1. |
tol |
A numeric value specifying the convergence tolerance. Default is 1e-6. |
max_iter |
A positive integer specifying the maximum number of iterations. Default is 1000. |
A list with the following components:
A numeric value (single analysis) or numeric
vector (sequential) of stopping boundaries. The key is "bounds"
for a single analysis and "bound" for multiple analyses.
A numeric value or vector of cumulative alpha spent at each analysis.
A logical value or vector indicating whether the algorithm converged at each analysis.
An integer value or vector of the number of iterations used at each analysis.
The input type I error rate.
The input information fractions.
The input spending function name.
The input correlation matrix.
The input test type.
Determines the first analysis stopping boundary based on a chi-squared global test statistic. This is used when the comparison type is a global chi-squared test (testing whether any regime differs from the others) rather than individual regime comparisons against a fixed control.
get_bounds_chi( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), mu = NULL, B = 1000001, seed = 1 )get_bounds_chi( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), mu = NULL, B = 1000001, seed = 1 )
alpha |
A numeric value specifying the overall type I error rate to control. Default is 0.05. |
inf_frac |
A numeric vector of information fractions indicating when
analyses are conducted. Values should be between 0 and 1. The length
determines the number of planned analyses |
spend_fn |
A character string specifying the alpha spending function.
Currently used to adjust the |
corr |
A correlation matrix of the expected correlation between
the Z-statistics of regimes against a fixed value. Should have
dimension |
mu |
An optional numeric vector of means for the multivariate normal
distribution for all regimes at a single analysis used in the Monte Carlo
simulation. Default is |
B |
A positive integer specifying the number of Monte Carlo samples. Default is 1000001. |
seed |
An integer seed for reproducibility of the Monte Carlo simulation. Default is 1. |
The function uses Monte Carlo simulation to estimate the boundary that
controls the familywise type I error rate at a specified level. A contrast
matrix is constructed to form linearly independent
comparisons among regimes, and the chi-squared statistic is
computed as .
A list with the following components:
A numeric vector of chi-squared stopping boundaries, one per analysis.
A numeric vector of observed cumulative alpha spent at each analysis.
The overall achieved type I error rate across all analyses.
A logical value; always TRUE for Monte Carlo
based computation.
The number of Monte Carlo samples used (B).
The degrees of freedom of the chi-squared statistic,
equal to the rank of .
The input type I error rate.
The input information fractions.
The input spending function name.
The input correlation matrix.
The input mean vector.
The input number of Monte Carlo samples.
The input random seed.
Determines the first analysis stopping boundary that controls the familywise type I error rate at a specified level, adjusting for the multiplicity of multiple treatment regimes. Uses an iterative search to find the boundary value. This function works only for superiority (one-sided) testing.
get_first_bound( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, max_iter = 1000 )get_first_bound( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, max_iter = 1000 )
alpha |
A numeric value specifying the overall type I error rate to control. Default is 0.05. |
inf_frac |
A numeric vector of information fractions indicating when analyses are conducted. Values should be between 0 and 1. |
spend_fn |
A character string specifying the alpha spending function.
Either |
corr |
A correlation matrix of Z-statistics at the first time point, accounting for multiple regimes. Default is a 1x1 identity matrix. |
test_type |
A character string specifying the type of test to be
performed. Either |
lambda |
A numeric value for the initial step size used in the iterative boundary search. Default is 0.1. |
tol |
A numeric value specifying the convergence tolerance for the type I error boundary. Default is 1e-6. |
max_iter |
A positive integer specifying the maximum number of iterations for the boundary search. Default is 1000. |
A list with the following components:
The computed stopping boundary for the first analysis.
The achieved type I error rate at the boundary.
A logical value indicating whether the algorithm converged.
The number of iterations used.
Determines the total number of stages each individual has reached by a
specified analysis time t_s, based on their arrival times
t1, ..., t_{K+1}.
get_kappa(df, t_s, K)get_kappa(df, t_s, K)
df |
A data frame containing columns |
t_s |
A numeric value specifying the analysis time point. |
K |
An integer specifying the number of treatment stages (decision points). |
An integer vector of length nrow(df) indicating the number of
stages each individual has reached by time t_s. Values range from 0
(not yet enrolled) to (outcome observed).
Given the boundary from the first analysis, determines the stopping boundary
for the -th analysis that controls the overall type I error rate.
Uses an iterative search with the joint distribution of test statistics
across analyses.
get_next_bound( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, prev_bound = NULL, s = 2, max_iter = 1000 )get_next_bound( alpha = 0.05, inf_frac = c(0.5, 1), spend_fn = "OF", corr = diag(x = 1, nrow = 1, ncol = 1), test_type = "one-sided", lambda = 0.1, tol = 1e-06, prev_bound = NULL, s = 2, max_iter = 1000 )
alpha |
A numeric value specifying the overall type I error rate to control. Default is 0.05. |
inf_frac |
A numeric vector of information fractions indicating when analyses are conducted. |
spend_fn |
A character string specifying the alpha spending function.
Either |
corr |
A correlation matrix of Z-statistics across all analyses and
regimes. Should have dimension |
test_type |
A character string specifying the type of test to be
performed. Either |
lambda |
A numeric value for the initial step size used in the iterative boundary search. Default is 0.1. |
tol |
A numeric value specifying the convergence tolerance. Default is 1e-6. |
prev_bound |
A numeric vector of previously computed boundaries from
analyses |
s |
An integer indicating the current analysis number. Default is 2. |
max_iter |
A positive integer specifying the maximum number of iterations. Default is 1000. |
A list with the following components:
The computed stopping boundary for analysis s.
The achieved cumulative type I error rate through analysis
s.
A logical value indicating whether the algorithm converged.
The number of iterations used.
Estimates the probability that an individual has reached each stage given
they are enrolled in the trial. Requires the data frame to have a
kappa column indicating the stage reached. The returned list uses
indexing such that nu[[k]] corresponds to stage , and
nu[[K+1]] is the probability that an individual has their final
outcome observed.
get_nu(df, K)get_nu(df, K)
df |
A data frame containing a |
K |
An integer specifying the number of treatment stages (decision points). |
A list with the following components:
A list of length where nu[[k]] is the
estimated probability that an individual has reached stage
given enrollment.
The total number of individuals enrolled in the trial
(kappa > 0).
The proportion of individuals who have reached their last treatment stage and have their outcome observed.
Extracts and concatenates the regression coefficients from all fitted Q-function models across all regimes and stages.
get_q_coefs(q_all)get_q_coefs(q_all)
q_all |
A list of fitted outcome regression objects for each regime,
as returned by |
A numeric vector of all Q-function regression coefficients, ordered by regime and then by stage.
Fits Q-function models backwards from the last stage to the first for a single treatment regime. At each stage, both regime-modified and unmodified predicted values are computed. Handles feasible sets (where responders may not be re-randomized) and interim analyses.
get_q_fits(df, q_list, regime, feasible_sets_indicator = FALSE)get_q_fits(df, q_list, regime, feasible_sets_indicator = FALSE)
df |
A data frame containing the trial data, including treatment
assignments, covariates, outcomes ( |
q_list |
A list of outcome regression model specifications (one per
stage). Each element is either a |
regime |
A matrix of treatment assignments under the regime being evaluated, with columns corresponding to stages. |
feasible_sets_indicator |
A logical value indicating whether feasible sets
are present. Default is |
A list with the following components:
A list of fitted modelObj objects, one per stage.
When feasible sets with multiple models are used, the element is a
named list with "r0" and "r1".
A matrix of regime-modified predicted values
with columns q1, ..., q_{K+1}.
A matrix of unmodified predicted values with
columns q1_nochange, ..., q_{K+1}_nochange.
For specified operating characteristics, iteratively increases the sample size until the desired power is achieved. Assumes the information fraction remains unchanged as the sample size increases, which is reasonable for small changes or at the design stage.
get_sample_size( variances, beta, delta, bounds, n_init = 100, corr = bounds$corr, inf_frac = bounds$inf_frac, n_split = NULL )get_sample_size( variances, beta, delta, bounds, n_init = 100, corr = bounds$corr, inf_frac = bounds$inf_frac, n_split = NULL )
variances |
A numeric vector of length |
beta |
A numeric value between 0 and 1 specifying the type II error
rate. Power is |
delta |
A numeric vector of length |
bounds |
A numeric vector of length |
n_init |
A positive integer specifying the initial total trial sample
size |
corr |
A correlation matrix of dimension |
inf_frac |
A numeric vector of information fractions indicating when analyses are conducted. |
n_split |
A numeric vector indicating the proportion of the sample size at the analysis times s=1,...,S. If no argument is given, assumes the split is proportional to the information available. |
A list with the following components:
A numeric vector of sample sizes at each analysis.
The achieved power at the final sample size.
A numeric vector of cumulative rejection probabilities at each analysis.
The input variances.
The input type II error rate.
The input alternative differences.
The input stopping boundaries.
The input initial sample size.
The input correlation matrix.
The input information fractions.
The input sample size split proportions.
For specified operating characteristics, iteratively increases the sample size until the desired power is achieved using a chi-squared global test statistic. The chi-squared test assesses whether any treatment regime differs from the others, rather than comparing individual regimes against a fixed control.
get_sample_size_chi( variances, beta, delta, bounds, n_init = 100, corr = bounds$corr, inf_frac = bounds$inf_frac, n_split = NULL, seed = 2, B = 10001, lambda = 20, max_iter = 100 )get_sample_size_chi( variances, beta, delta, bounds, n_init = 100, corr = bounds$corr, inf_frac = bounds$inf_frac, n_split = NULL, seed = 2, B = 10001, lambda = 20, max_iter = 100 )
variances |
A numeric vector of length |
beta |
A numeric value between 0 and 1 specifying the type II error
rate. Power is |
delta |
A numeric vector of length |
bounds |
A numeric vector of chi-squared stopping boundaries for
analyses |
n_init |
A positive integer specifying the initial total trial sample
size |
corr |
A correlation matrix of dimension |
inf_frac |
A numeric vector of information fractions indicating when
analyses are conducted. Defaults to the information fractions from the
|
n_split |
A numeric vector indicating the proportion of the sample
size at the analysis times |
seed |
An integer seed for reproducibility of the Monte Carlo simulation. Default is 2. |
B |
A positive integer specifying the number of Monte Carlo samples for power estimation. Default is 10001. |
lambda |
A positive numeric value specifying the incremental sample
size increases when raising the sample size to find the required power
via simulation. After this is found, iteration from |
max_iter |
The maximum sample sizes n to evaluate. |
The function uses Monte Carlo simulation to estimate power at each
candidate sample size. A contrast matrix is constructed to form
linearly independent comparisons among regimes, and
the chi-squared statistic is computed as
.
A list with the following components:
A numeric vector of sample sizes at each analysis.
The achieved power at the final sample size.
A numeric vector of cumulative rejection probabilities at each analysis.
The input variances.
The input type II error rate.
The input alternative differences.
The input stopping boundaries.
The input initial sample size.
The input correlation matrix.
The input information fractions.
The input sample size split proportions.
The input random seed.
The input number of Monte Carlo samples.
The input step size for the sample size search.
The IAIPWE was developed for arbitrary K stage SMART and subsumes both IPWE and AIPWE. To implement the IPWE, q_list should be NULL and the t_s should be set to the maximum available time of the outcome observed. To implement the AIPWE, t_s should be set to the maximum available time of the outcome observed.
iaipwe(df, pi_list, q_list, regime_all, feasible_sets_indicator, t_s, B = NULL)iaipwe(df, pi_list, q_list, regime_all, feasible_sets_indicator, t_s, B = NULL)
df |
A data frame containing the data. It should include columns for the treatment assignments, response status, covariates, and outcomes. |
pi_list |
A list of |
q_list |
A list of |
regime_all |
A list of length equal to the number of regimes to be
estimated. Each element is a list with two components: |
feasible_sets_indicator |
A logical value indicating whether feasible
sets are present in the trial design. If |
t_s |
A numeric value indicating the time point at which the analysis should occur. |
B |
A positive integer specifying the number of empirical bootstrap
samples to use for variance estimation, or |
If times are not recorded for the study, "dummy" times can be used with the analysis time set to be the maximum of the dummy times.
A list with the following components:
A numeric vector of estimated regime values.
A numeric vector of standard errors for the regime values.
The estimated L x L covariance matrix of the regime value estimators.
A numeric vector of all estimated parameters.
A list of estimated stage arrival probabilities, as returned
by get_nu().
A list of fitted Q-function objects for each regime.
The input regime list, returned for convenience.
A list of value term matrices for each regime.
A character string indicating the variance
estimation method used ("Asymptotic" or "Bootstrap").
A list with Statistic (the chi-squared test
statistic for equality of regime values) and p_value.
A dataset containing simulated patient data to mimic the characteristics of the Pain Coping Skills Training trial presented in Manschot, Laber, and Davidian (2023).
pcsttrialpcsttrial
A data frame with 284 rows and 14 variables:
Percent change in outcome from baseline at final assessment
Patient height (cm)
Patient weight (kg)
Comorbidity indicator (0 = no, 1 = yes)
Pain medication use indicator (0 = no, 1 = yes)
Chemotherapy indicator (0 = no, 1 = yes)
Percent change in outcome at stage 2
Treatment adherence measure, from 0.5 to 1 in increments of 0.1
First-stage treatment assignment
Second-stage treatment assignment
Response indicator at stage 2 (0 = non-responder, 1 = responder)
Study day of enrollment
Study day of re-randomization
Study day of outcome assessment
Note: this dataset is for illustrative purposes and does not use the actual trial data.
Fits propensity score models at each stage of the SMART, using only individuals who have reached that stage. Returns estimated propensity scores and fitted model objects for all stages.
pi_fits(df, p_list)pi_fits(df, p_list)
df |
A data frame containing the trial data, including treatment
assignments ( |
p_list |
A list of |
A list with the following components:
A data frame of estimated propensity scores with columns
pi1, ..., piK. Individuals who have not reached a stage are
assigned a value of 99.
A list of fitted modelObj objects, one per stage.
Fits a propensity score model at a single stage of the SMART and returns the fitted probabilities. The probability that each individual received the treatment they actually received is computed.
pstep(pmodel, data, response, k)pstep(pmodel, data, response, k)
pmodel |
A |
data |
A data frame of individuals to fit the model on (typically those
who have reached stage |
response |
A vector or data frame column of treatment assignments at
stage |
k |
An integer indicating the stage number. |
A list with the following components:
A numeric vector of predicted probabilities that treatment
is 1 at stage k.
A numeric vector of estimated propensity scores (probability that the individual received the treatment they actually received).
The fitted modelObj object.
Fits a single Q-function model at one stage of the SMART. Predictions are obtained both for the unmodified data and for data where the treatment is set to the recommended regime.
qstep(qmodel, data, response, newdata, regime, txName)qstep(qmodel, data, response, newdata, regime, txName)
qmodel |
A |
data |
A data frame of individuals used to fit the model (typically those who have completed the stage). |
response |
A numeric vector or single-column data frame of responses (pseudo-outcomes from later stages or observed outcomes). |
newdata |
A data frame of individuals for whom predictions are desired (typically those who have reached the stage). |
regime |
A vector of recommended treatment assignments under the regime being evaluated. |
txName |
A character string specifying the name of the treatment column
to modify (e.g., |
A list with the following components:
A numeric vector of predicted values under the regime-consistent treatment.
A numeric vector of predicted values under the actual (unmodified) treatment.
The fitted modelObj object.
Constructs the treatment assignment matrices and consistency indicator matrices for each embedded regime in a two-stage SMART. For stages where response status determines treatment deterministically, the regime matrix is updated to reflect the responder treatment.
regime_list_no_trt_resp( emb_regimes, dat, resp_trt = list(r2 = list(0, 0, 0, 0)) )regime_list_no_trt_resp( emb_regimes, dat, resp_trt = list(r2 = list(0, 0, 0, 0)) )
emb_regimes |
A list of numeric vectors, each of length K, specifying
the treatment codes (0 or 1) for non-responders at each stage. For
example, |
dat |
A data frame containing the SMART data. Expected to contain
columns |
resp_trt |
A named list where each element corresponds to a stage with
deterministic responder treatment (e.g., |
A list of length length(emb_regimes). Each element is a list with
two components:
An n x K matrix of treatment assignments each individual would receive if they followed that regime.
An n x K indicator matrix (0 or 1) of whether each individual's observed treatment was consistent with the regime at each stage.
Generates treatment assignments for n individuals given a specified
number of possible treatments and a randomization probability function. This
is a utility function for constructing SMART simulations with flexible
randomization schemes. If an input data frame is provided, the treatment
assignments are appended as a new column a<stage>.
sim_treatment( n = NULL, n_treatments, rand_prob_fn = function(n, n_treatments, prob) { sample(0:(n_treatments - 1), size = n, replace = TRUE, prob = prob) }, dat = NULL, stage = 1, randomize_response = NULL, prob = NULL )sim_treatment( n = NULL, n_treatments, rand_prob_fn = function(n, n_treatments, prob) { sample(0:(n_treatments - 1), size = n, replace = TRUE, prob = prob) }, dat = NULL, stage = 1, randomize_response = NULL, prob = NULL )
n |
A positive integer. Number of individuals to assign treatments to.
If |
n_treatments |
A positive integer. Number of possible treatments.
Treatments are coded as integers |
rand_prob_fn |
A function that takes |
dat |
An optional data frame. If provided, the function appends the
treatment assignments as a new column named |
stage |
A positive integer indicating the stage number. The treatment
column will be named |
randomize_response |
One of |
prob |
A numeric vector or a named list specifying randomization
probabilities. If a numeric vector, it is used as the probability weights
for all groups (must have length equal to |
If dat is NULL (default), an integer vector of length
n with treatment assignments coded as
0, 1, ..., n_treatments - 1. If dat is provided, the input
data frame with a new integer column a<stage> appended.
# Default: Bernoulli randomization with 2 treatments (prob 0.5) set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2) table(a) # Unequal randomization: 70% to treatment 0, 30% to treatment 1 set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2, prob = c(0.7, 0.3)) table(a) # Three treatments with equal probability set.seed(1) a <- sim_treatment(n = 300, n_treatments = 3) table(a) # With an input data frame set.seed(1) df <- data.frame(x1 = rnorm(100), x2 = rbinom(100, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df) head(df) # With an input data frame at stage 2 set.seed(1) df <- data.frame(x1 = rnorm(100), a1 = rbinom(100, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2) head(df) # Stage 2 with different randomization probabilities depending on a1: # equal (50/50) if a1 == 0, unequal (70/30) if a1 == 1 # Using a named list for prob, where names match group levels set.seed(1) n <- 200 df <- data.frame(a1 = rbinom(n, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2, prob = list("0" = c(0.5, 0.5), "1" = c(0.7, 0.3))) table(df$a1, df$a2)# Default: Bernoulli randomization with 2 treatments (prob 0.5) set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2) table(a) # Unequal randomization: 70% to treatment 0, 30% to treatment 1 set.seed(1) a <- sim_treatment(n = 100, n_treatments = 2, prob = c(0.7, 0.3)) table(a) # Three treatments with equal probability set.seed(1) a <- sim_treatment(n = 300, n_treatments = 3) table(a) # With an input data frame set.seed(1) df <- data.frame(x1 = rnorm(100), x2 = rbinom(100, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df) head(df) # With an input data frame at stage 2 set.seed(1) df <- data.frame(x1 = rnorm(100), a1 = rbinom(100, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2) head(df) # Stage 2 with different randomization probabilities depending on a1: # equal (50/50) if a1 == 0, unequal (70/30) if a1 == 1 # Using a named list for prob, where names match group levels set.seed(1) n <- 200 df <- data.frame(a1 = rbinom(n, 1, 0.5)) df <- sim_treatment(n_treatments = 2, dat = df, stage = 2, prob = list("0" = c(0.5, 0.5), "1" = c(0.7, 0.3))) table(df$a1, df$a2)
Calculates the stopping boundaries and required sample size for a group
sequential design with multiple treatment regimes embedded in a SMART. The
boundaries are found first to control the type I error rate, then the sample
size is determined to achieve the desired power. This function wraps
get_bounds and get_sample_size.
smart_design( test_type = "one-sided", comp_type = "fixed.control", alpha = 0.05, beta = 0.1, delta = NULL, n_init = 400, inf_frac = 1, spend_fn = "OF", corr = NULL, variances = NULL, lambdaB = 0.1, lambdaC = 20, tol = 1e-06, max_iterB = 1000, max_iterC = 100, seed = 1, Bb = 100001, Bc = 10001, mu = NULL )smart_design( test_type = "one-sided", comp_type = "fixed.control", alpha = 0.05, beta = 0.1, delta = NULL, n_init = 400, inf_frac = 1, spend_fn = "OF", corr = NULL, variances = NULL, lambdaB = 0.1, lambdaC = 20, tol = 1e-06, max_iterB = 1000, max_iterC = 100, seed = 1, Bb = 100001, Bc = 10001, mu = NULL )
test_type |
A character string specifying the type of hypothesis test. A test type of either one-sided or two-sided. Two-sided testing must be symmetric. This input is ignored for a global Chi-squared test. |
comp_type |
A character string specifying what comparison will be tested. Character string for either "fixed.control" or "global.chi.sq". |
alpha |
A numeric value between 0 and 1 specifying the overall
familywise type I error rate. Default is |
beta |
A numeric value between 0 and 1 specifying the type II error
rate. Power is |
delta |
A numeric vector of length equal to the number of treatment regimes specifying the alternative differences between each regime's value and the null (or control) value. |
n_init |
A positive integer specifying the initial total sample size to begin the iterative sample size search. |
inf_frac |
A numeric vector of information fractions indicating when
analyses are conducted. Values should be between 0 and 1, with the last
element equal to 1. Default is |
spend_fn |
A character string specifying the alpha spending function.
Either |
corr |
A correlation matrix of Z-statistics across all regimes and
analyses. The dimension should be |
variances |
A numeric vector of length equal to the number of treatment
regimes giving the variance of each value estimator scaled by sample
size, i.e., |
lambdaB |
A numeric value for the initial step size used in the iterative boundary search. Default is 0.1. |
lambdaC |
A numeric value for the initial step size used in the iterative sample size search. Default is 20. |
tol |
A numeric value specifying the convergence tolerance. Default is 1e-6. |
max_iterB |
A positive integer specifying the maximum number of iterations for the boundary search. Default is 1000. |
max_iterC |
A positive integer specifying the maximum number of iterations for the sample size search. Default is 100. |
seed |
An integer seed for reproducibility of the Monte Carlo simulation. Default is 1. |
Bb |
A positive integer specifying the number of Monte Carlo samples for the boundary computation. Default is 100001. |
Bc |
A positive integer specifying the number of Monte Carlo samples for the sample size computation. Default is 10001. |
mu |
A parameter vector for the multivariate normal distribution of the treatment effect mean, used only for the chi-square distribution in the case of a non-centrality assumption, though unlikely to be needed. |
A list with the following components:
The output from get_bounds (when
comp_type = "fixed.control") or get_bounds_chi
(when comp_type = "global.chi.sq"), containing the stopping
boundaries and associated metadata. See those functions for details.
The output from get_sample_size or
get_sample_size_chi, containing the required sample sizes,
achieved power, cumulative rejection probabilities, and echoed input
parameters. If delta is NULL (no alternative
specified), the sample size is not computed and this element is
NULL.
A list echoing all input parameters passed to
smart_design.
Computes the coarsening-level value terms for each individual
under a single treatment regime. These include augmentation terms for levels
and the IPW term for (i.e.,
). When outcome regression models (qs) are provided,
the augmented terms are computed; otherwise only the IPW term is non-zero.
value_terms(df, regime_ind, pis, qs, nus)value_terms(df, regime_ind, pis, qs, nus)
df |
A data frame containing the trial data, including treatment
assignments, covariates, outcomes ( |
regime_ind |
A matrix of regime consistency indicators for a single regime, with columns indicating whether each individual followed the regime at each stage. |
pis |
A data frame of estimated propensity scores with columns
|
qs |
A list containing outcome regression fitted values for a single
regime (as returned by |
nus |
A list as returned by |
A numeric matrix with nrow(df) rows and columns,
where each column corresponds to a coarsening-level term in the value
estimator.