Type: | Package |
Title: | Sequential Allocation for Prospective Experiments |
Version: | 1.0 |
Date: | 2016-08-03 |
Author: | Xiaoshu Zhu and Sharon Lohr |
Maintainer: | Xiaoshu Zhu <xiaoshuzhu@westat.com> |
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). |
Imports: | stats, graphics |
License: | GPL-2 |
RoxygenNote: | 5.0.1 |
NeedsCompilation: | no |
Packaged: | 2016-08-03 18:49:44 UTC; zhu_x |
Repository: | CRAN |
Date/Publication: | 2016-08-04 01:09:17 |
Sequential Allocation for Randomized 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).
Details
Package: | SeqAlloc |
Type: | Package |
Version: | 1.0 |
Date: | 2016-08-03 |
Imports: | stats, graphics |
License: | GPL-2 |
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Maximum Allocation Imbalance for Covariates
Description
Evaluate maximum of the allocation imbalance for all covariates
Usage
MAICimbal(alloc, xmat)
Arguments
alloc |
vector of allocations to treatment (1) or control (0) |
xmat |
matrix describing covariates for each prospective observation |
Value
maximum of covariate imbalances
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
See Also
Examples
alloc <- rbinom(60,1,.5)
xmat <- matrix(rbinom(240,1,.4),ncol=4)
MAICimbal(alloc, xmat)
Sequential Allocation for Prospective Experiments
Description
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).
Usage
SeqAlloc(xmat, carwt, strata = NULL, blksize, pbcd, pcar, bsdtol, caittol,
niter, seed = 12345)
Arguments
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 |
Value
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 |
Note
Because the program allows for sequential allocation methods, it can be slow when the data set and/or number of iterations is large.
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
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)
Plot the evaluation criteria for the designs
Description
Provides boxplots and scatterplots of balance and predictability measures for candidate sequential allocations.
Usage
SeqAllocplot(mysim, bporder = NULL, stratum = F, cexsize = 0.7)
Arguments
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 |
Value
Produces selected plots of predictability and balance for randomization schemes.Requires user to click window or press "enter" to progress through plots.
Note
These are example plots; the plotting code can be extracted from this function or the function is easily modified if different plots are desired.
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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
See Also
Examples
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)
Weighted Average of Allocation Imbalance for Covariates
Description
Evaluate weighted average of the allocation imbalance for all covariates
Usage
WAICimbal(alloc, xmat, carwt)
Arguments
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 |
Value
Weighted average of covariate imbalances
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
See Also
Examples
alloc <- rbinom(60,1,.5)
xmat <- matrix(rbinom(240,1,.4),ncol=4)
carwt <- c(.1,.3,.2,.4)
WAICimbal(alloc, xmat, carwt)
Biased Coin Design Allocation
Description
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.
Usage
bcdalloc(n, pbcd, tol = 1e-06)
Arguments
n |
number of observations |
pbcd |
probability p used for biased coin |
tol |
tolerance used for allocation |
Value
Vector of zeroes and ones indicating the allocation of each unit to treatment (1) or control (0)
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
bcdalloc(20,0.7)
Sequential Allocation for CAIT Method
Description
Performs the sequential allocation for the covariate-adjusted-imbalance-tolerance (CAIT) method of allocating observations in a randomized experiment.
Usage
caitalloc(carwt_x1, p, tol)
Arguments
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. |
Value
Vector with the allocation to treatment (denoted by 1) and control (denoted by 0)
Note
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.
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
See Also
Examples
wtmat <- matrix(runif(10000), ncol=100)
wtmat <- (wtmat * lower.tri(wtmat)) + t(wtmat * lower.tri(wtmat))
diag(wtmat) <- 1
caitalloc(wtmat,1,3)
Sequential Allocation Using Covariate Adaptive Randomization
Description
Performs the sequential allocation for the covariate-adjusted randomization (CAR) method of allocating observations in a randomized experiment.
Usage
caralloc(xmat, carwt, p, tol)
Arguments
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). |
Value
Vector with the allocation to treatment (denoted by 1) and control (denoted by 0)
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
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)
Evaluate Optimal Guess
Description
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.
Usage
cguess(alloc)
Arguments
alloc |
vector of zeroes and ones, indicating the allocation to treatment (1) and control (0) |
Details
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.
Value
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.
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
alloc <- rbinom(50,1,.5)
cguess(alloc)
Evaluate covariate imbalance using R-squared.
Description
Evaluate imbalance in the covariates from the allocation by finding R-squared for a centered regression through the origin.
Usage
covimbal(y, xmatc)
Arguments
y |
vector of 0's and 1's representing allocation |
xmatc |
centered X matrix |
Value
Value of R-squared from centered regression
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
alloc <- rbinom(60,1,.5)
xmat <- matrix(rbinom(240,1,.4),ncol=4)
xmatc <- scale(xmat,center=TRUE,scale=FALSE)
covimbal(alloc,xmatc)
Stratified permuted block allocation
Description
Allocates observations to treatment (1) or control (0) within strata
Usage
stratblockalloc(n, blksize)
Arguments
n |
number of observations |
blksize |
size of each block: must be even number |
Details
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.
Value
vector of allocations to treatment (1) or control (0) group
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
stratblockalloc(20,2)
Find summary statistics
Description
Finds the Minimum, 25th percentile, Median, Mean, 75th percentile, 90th percentile, 95th percentile, and Maximum of the vector
Usage
summary95(x)
Arguments
x |
vector for which summary statistics are desired |
Details
The code from the 'summary' function in R is modified to include the 90th and 95th percentiles
Value
vector of summary statistics for data
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr, adapted from 'summary' function in R.
Examples
summary95(rnorm(40))
Calculate weight matrix from matrix of covariates
Description
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.
Usage
weight_x(xrow, xmat, carwt)
Arguments
xrow |
vector used for matching |
xmat |
matrix of covariates |
carwt |
vector of weight for each match |
Value
Vector of weights relating vector xrow to the rows of xmat
Author(s)
Xiaoshu Zhu xiaoshuzhu@westat.com and Sharon Lohr
References
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.
Examples
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)