Title: | Sequential Allocation for Prospective Experiments |
---|---|
Description: | Potential randomization schemes are prospectively evaluated when units are assigned to treatment arms upon entry into the experiment. The schemes are evaluated for balance on covariates and on predictability (i.e., how well could a site worker guess the treatment of the next unit enrolled). |
Authors: | Xiaoshu Zhu and Sharon Lohr |
Maintainer: | Xiaoshu Zhu <[email protected]> |
License: | GPL-2 |
Version: | 1.0 |
Built: | 2024-12-01 08:45:21 UTC |
Source: | CRAN |
Potential randomization schemes are prospectively evaluated when units are assigned to treatment arms upon entry into the experiment. The schemes are evaluated for balance on covariates and on predictability (i.e., how well could a site worker guess the treatment of the next unit enrolled).
Package: | SeqAlloc |
Type: | Package |
Version: | 1.0 |
Date: | 2016-08-03 |
Imports: | stats, graphics |
License: | GPL-2 |
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
McEntegart, D. J. (2003). The Pursuit of Balance Using Stratified and Dynamic Randomization Techniques: An Overview. Drug information Journal 37: 293-308.
Rosenberger, W. F. and J. M. Lachin (2004). Randomization in Clinical Trials: Theory and Practice. New York: Wiley.
Allocates observations sequentially using a biased coin design. If equal numbers have been allocated to treatment and control, the next observation is allocated to treatment with probability 1/2. If there are more units assigned to treatment than control, the next observation is allocated to control with probability p; if there are more units assigned to control than treatment, the next observation is allocated to treatment with probability p.
bcdalloc(n, pbcd, tol = 1e-06)
bcdalloc(n, pbcd, tol = 1e-06)
n |
number of observations |
pbcd |
probability p used for biased coin |
tol |
tolerance used for allocation |
Vector of zeroes and ones indicating the allocation of each unit to treatment (1) or control (0)
Xiaoshu Zhu [email protected] and Sharon Lohr
Efron, B. (1971). Forcing a sequential experiment to be balanced. Biometrika, 58(3), 403-417.
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
bcdalloc(20,0.7)
bcdalloc(20,0.7)
Performs the sequential allocation for the covariate-adjusted-imbalance-tolerance (CAIT) method of allocating observations in a randomized experiment.
caitalloc(carwt_x1, p, tol)
caitalloc(carwt_x1, p, tol)
carwt_x1 |
matrix of dimension n x n, where n is the number of units to be randomly assigned to treatments. The (i,j) element of the matrix is the weighted match score of unit i and unit j. The matrix should be symmetric with diagonal elements of 1. |
p |
probability the next unit should be allocated to the experiment arm that currently has fewer observations. |
tol |
imbalance tolerance for deviation from equal allocation. |
Vector with the allocation to treatment (denoted by 1) and control (denoted by 0)
This function works for categorical as well as binary covariates. The matrix carwt_x1 can be created from an X matrix by using the function weight_x in this package.
Xiaoshu Zhu [email protected] and Sharon Lohr
Pocock, S.J. and R. Simon (1975). Sequential Treatment Assignment with Balancing for Prognostic Factors in a Controlled Clinical Trial. Biometrics 31, 103-115.
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
wtmat <- matrix(runif(10000), ncol=100) wtmat <- (wtmat * lower.tri(wtmat)) + t(wtmat * lower.tri(wtmat)) diag(wtmat) <- 1 caitalloc(wtmat,1,3)
wtmat <- matrix(runif(10000), ncol=100) wtmat <- (wtmat * lower.tri(wtmat)) + t(wtmat * lower.tri(wtmat)) diag(wtmat) <- 1 caitalloc(wtmat,1,3)
Performs the sequential allocation for the covariate-adjusted randomization (CAR) method of allocating observations in a randomized experiment.
caralloc(xmat, carwt, p, tol)
caralloc(xmat, carwt, p, tol)
xmat |
matrix or data frame of covariates for prospective enrollees in the experiment. |
carwt |
vector of weights |
p |
probability the next unit should be allocated to the experiment arm that currently has fewer observations. For CAR, use 0.5 < p < 1. |
tol |
tolerance for deviation from equal allocation. For CAR, set tol to be a small value, say 0.01. For CAIM, set tol to be the imbalance tolerance (d). |
Vector with the allocation to treatment (denoted by 1) and control (denoted by 0)
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
Pocock, S. J. and R. Simon (1975). Sequential Treatment Assignment with Balancing for Prognostic Factors in A Controlled Clinical Trial. Biometrics 31: 103-115.
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) carwt <- c(.4,.3,.2,.1) set.seed(5798) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) = c("C1","C2","C3","C4") strat_factor = xmat[,1]*4 + xmat[,2]*2 + xmat[,4] + 1 caralloc(xmat,carwt,1,3)
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) carwt <- c(.4,.3,.2,.1) set.seed(5798) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) = c("C1","C2","C3","C4") strat_factor = xmat[,1]*4 + xmat[,2]*2 + xmat[,4] + 1 caralloc(xmat,carwt,1,3)
This function calculates the optimal guess for the allocation of the next observation in a sequential allocation scheme, and evaluates whether that guess is correct.
cguess(alloc)
cguess(alloc)
alloc |
vector of zeroes and ones, indicating the allocation to treatment (1) and control (0) |
Blackwell and Hodges (1957) proposed evaluating the predictability of a randomized allocation scheme by having an observer guess that the next unit would be allocated to the treatment arm that currently has fewer subjects. This function creates the guesses that would be generated by an observer following this strategy, then compares them with the actual allocation. If units 1 through j have more treatment than control units, then the observer guesses that observation j+1 is assigned to the control arm. If units 1 through j have more control than treatment units, then the observer guesses that observation j+1 is assigned to the treatment arm. If units 1 through j have the same number of control and treatment units, then the observer flips a coin with probability 0.5 for the allocation of the next unit. To reduce the variability in the percentage guessed correctly, this is recorded as a response of 0.5; however, the function is easily changed to allow the observer to guess treatment or control with probability 0.5 for that case.
Vector of length length(alloc) containing values 0, 0.5, and 1. A value is 1 if the guess is correct, 0 if it is incorrect, and 0.5 if the allocation preceding the observation in question was equal.
Xiaoshu Zhu [email protected] and Sharon Lohr
Blackwell, David and Hodges, J. L. (1957). Design for the Control of Selection Bias. Annals of Mathematical Statistics 28: 449-460.
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
alloc <- rbinom(50,1,.5) cguess(alloc)
alloc <- rbinom(50,1,.5) cguess(alloc)
Evaluate imbalance in the covariates from the allocation by finding R-squared for a centered regression through the origin.
covimbal(y, xmatc)
covimbal(y, xmatc)
y |
vector of 0's and 1's representing allocation |
xmatc |
centered X matrix |
Value of R-squared from centered regression
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) xmatc <- scale(xmat,center=TRUE,scale=FALSE) covimbal(alloc,xmatc)
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) xmatc <- scale(xmat,center=TRUE,scale=FALSE) covimbal(alloc,xmatc)
Evaluate maximum of the allocation imbalance for all covariates
MAICimbal(alloc, xmat)
MAICimbal(alloc, xmat)
alloc |
vector of allocations to treatment (1) or control (0) |
xmat |
matrix describing covariates for each prospective observation |
maximum of covariate imbalances
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) MAICimbal(alloc, xmat)
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) MAICimbal(alloc, xmat)
Simulates results of allocations using complete randomization (CR), random allocation rule (RAR), biased coin design (BCD), permuted block design (PBD), stratified permuted block design (SPBD), covariate-adaptive randomization (CAR), big stick design (BSD), and covariate-adjusted imbalance tolerance (CAIT) designs. The order of the prospective enrollees is permuted for a preset number of iterations; for each iteration, the allocations are determined for each of the methods listed above. The allocations are then evaluated for balance on the covariates and for predictability (i.e., how well an observer could guess the next treatment assignment).
SeqAlloc(xmat, carwt, strata = NULL, blksize, pbcd, pcar, bsdtol, caittol, niter, seed = 12345)
SeqAlloc(xmat, carwt, strata = NULL, blksize, pbcd, pcar, bsdtol, caittol, niter, seed = 12345)
xmat |
matrix or data frame of covariates for prospective enrollees in the experiment. This matrix is to be used in CAR/CAIT methods, and should include strata or marginals of strata as columns |
carwt |
vector of weights to be used for CAR and CAIT methods |
strata |
vector of planned strata for study (if none, should be NULL) |
blksize |
vector of block sizes for PBDs and SPBDs |
pbcd |
probability for biased coin design (BCD) method |
pcar |
probability for CAR method |
bsdtol |
tolerance (d value) for BSD method |
caittol |
tolerance (d value) for CAIM method |
niter |
number of iterations for simulation |
seed |
random number seed, allows the allocation to be reproduced later |
List containing summary statistics (minimum, 25th percentile, median, mean, 75th percentile, 90th percentile, 95th percentile, maximum) for evaluation measures, including AI, Rsquared, MAIC, WAIC, perccorr, and perccorr_strat.
schemes |
names of schemes evaluated |
AI |
value of overall allocation imblance defined as | Proportion of observations that are allocated to the treatment group - 0.5 | |
Rsquared |
value of R-squared from regression through the origin |
MAIC |
maximum of allocation imbalance for all covariates |
WAIC |
weighted average of allocation imbalance for all covariates |
perccorr |
percentage of allocations that an observer could guess correctly using the Blackwell-Hodges rule |
perccorr_strat |
percentage of allocations that an observer could guess correctly using the Blackwell-Hodges rule within each stratum |
carwt |
weights used in CAR and CAIM procedures |
Because the program allows for sequential allocation methods, it can be slow when the data set and/or number of iterations is large.
Xiaoshu Zhu [email protected] and Sharon Lohr
Blackwell, David and J. L. Hodges (1957). Design for the Control of Selection Bias. Annals of Mathematical Statistics 28: 449-460.
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
Rosenberger, W. F. and Lachin, J. M. (2004). Randomization in Clinical Trials: Theory and Practice. New York: Wiley.
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) set.seed(200) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) <- c("C1","C2","C3","C4") strat_factor <- xmat[,2]*2 + xmat[,4] + 1 SeqAlloc(xmat,carwt=c(.4,.3,.2,.1),strata=strat_factor,blksize=c(2,6), pbcd=.7,pcar=.8,bsdtol=2,caittol=5,niter=10, seed = 20850)
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) set.seed(200) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) <- c("C1","C2","C3","C4") strat_factor <- xmat[,2]*2 + xmat[,4] + 1 SeqAlloc(xmat,carwt=c(.4,.3,.2,.1),strata=strat_factor,blksize=c(2,6), pbcd=.7,pcar=.8,bsdtol=2,caittol=5,niter=10, seed = 20850)
Provides boxplots and scatterplots of balance and predictability measures for candidate sequential allocations.
SeqAllocplot(mysim, bporder = NULL, stratum = F, cexsize = 0.7)
SeqAllocplot(mysim, bporder = NULL, stratum = F, cexsize = 0.7)
mysim |
output from function SeqAlloc |
bporder |
vector giving the randomization methods to be plotted, corresponding to the positions in mysim$schemes |
stratum |
logical variable of whether PBD designs should be plotted, default is FALSE |
cexsize |
size of characters in plot and axis, default is 0.7 |
Produces selected plots of predictability and balance for randomization schemes.Requires user to click window or press "enter" to progress through plots.
These are example plots; the plotting code can be extracted from this function or the function is easily modified if different plots are desired.
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) set.seed(200) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) <- c("C1","C2","C3","C4") strat_factor <- xmat[,1]*4 + xmat[,2]*2 + xmat[,4] + 1 mysim <- SeqAlloc(xmat,carwt=c(.4,.3,.2,.1),strata=strat_factor,blksize=c(2,6), pbcd=.7,pcar=.67,bsdtol=2,caittol=3,niter=10, seed = 30924) SeqAllocplot(mysim,bporder = c(3,4,7,8), stratum = FALSE, cexsize=0.6)
sampsize <- 200 percent <- c(0.5,0.8,0.2,0.4) set.seed(200) xmat <- matrix(rbinom(sampsize*length(percent),1,rep(percent,sampsize)), nrow=sampsize,ncol=length(percent),byrow=TRUE) colnames(xmat) <- c("C1","C2","C3","C4") strat_factor <- xmat[,1]*4 + xmat[,2]*2 + xmat[,4] + 1 mysim <- SeqAlloc(xmat,carwt=c(.4,.3,.2,.1),strata=strat_factor,blksize=c(2,6), pbcd=.7,pcar=.67,bsdtol=2,caittol=3,niter=10, seed = 30924) SeqAllocplot(mysim,bporder = c(3,4,7,8), stratum = FALSE, cexsize=0.6)
Allocates observations to treatment (1) or control (0) within strata
stratblockalloc(n, blksize)
stratblockalloc(n, blksize)
n |
number of observations |
blksize |
size of each block: must be even number |
Allocates observations within each block of size blksize so that half of the observations in each block are in the treatment group and the other half are in the control group.
vector of allocations to treatment (1) or control (0) group
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
stratblockalloc(20,2)
stratblockalloc(20,2)
Finds the Minimum, 25th percentile, Median, Mean, 75th percentile, 90th percentile, 95th percentile, and Maximum of the vector
summary95(x)
summary95(x)
x |
vector for which summary statistics are desired |
The code from the 'summary' function in R is modified to include the 90th and 95th percentiles
vector of summary statistics for data
Xiaoshu Zhu [email protected] and Sharon Lohr, adapted from 'summary' function in R.
summary95(rnorm(40))
summary95(rnorm(40))
Evaluate weighted average of the allocation imbalance for all covariates
WAICimbal(alloc, xmat, carwt)
WAICimbal(alloc, xmat, carwt)
alloc |
vector of allocations to treatment (1) or control (0) |
xmat |
matrix describing covariates for each prospective observation |
carwt |
vector of weights to be accorded to respective covariates |
Weighted average of covariate imbalances
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) carwt <- c(.1,.3,.2,.4) WAICimbal(alloc, xmat, carwt)
alloc <- rbinom(60,1,.5) xmat <- matrix(rbinom(240,1,.4),ncol=4) carwt <- c(.1,.3,.2,.4) WAICimbal(alloc, xmat, carwt)
Calculate a vector of weights relating vector xrow with the rows of xmat, according to the weights in vector carwt. For each row in xmat, the positions of agreement with xrow are found. The weight for that row of xmat is then the sum of the elements of carwt corresponding to the matches.
weight_x(xrow, xmat, carwt)
weight_x(xrow, xmat, carwt)
xrow |
vector used for matching |
xmat |
matrix of covariates |
carwt |
vector of weight for each match |
Vector of weights relating vector xrow to the rows of xmat
Xiaoshu Zhu [email protected] and Sharon Lohr
Lohr, S. and X. Zhu (2015). Randomized Sequential Individual Assignment in Social Experiments: Evaluating the Design Options Prospectively. Sociological Methods and Research. [Advance online publication: December 27, 2015] doi: 10.1177/0049124115621332.
xrow <- c(1,0,1,1) xmat <- matrix(rbinom(60,1,.4),ncol=4) carwt <- c(.6,.4,.2,.1) weight_x(xrow, xmat, carwt)
xrow <- c(1,0,1,1) xmat <- matrix(rbinom(60,1,.4),ncol=4) carwt <- c(.6,.4,.2,.1) weight_x(xrow, xmat, carwt)