StrBCD {carat} | R Documentation |
Shao's Method in the Two-Arms Case
Description
Allocates patients to one of the two treatments using Shao's method proposed by Shao J, Yu X, Zhong B (2010) <doi:10.1093/biomet/asq014>.
Usage
StrBCD(data, p = 0.85)
Arguments
data |
a data frame. A row of the dataframe corresponds to the covariate profile of a patient. |
p |
the biased coin probability. |
Details
Consider covariates and
levels for the
th covariate,
.
is the assignment of the
th patient and
indicates the covariate profile of this patient,
. For convenience,
and
denote the stratum and margin, respectively.
is the difference between the numbers of patients assigned to treatment
and treatment
at the corresponding levels after
patients have been assigned. The stratified biased coin design is as follows:
(1) The first patient is assigned to treatment with probability
;
(2) Suppose patients have been assigned (
) and the
th patient falls within
;
(3) If the th patient were assigned to treatment
, then the potential within-stratum difference between the two treatments would be
for stratum . Similarly, the potential difference would be obtained in the same way if the
th patient were assigned to treatment
;
(4) An imbalance measure is defined by
(5) Conditional on the assignments of the first () patients as well as the covariates'profiles of the first
patients, assign the
th patient to treatment
with probability
for
for , and
for
Details of the procedure can be found in Shao J, Yu X, Zhong B (2010).
Value
It returns an object of class
"carandom"
.
An object of class "carandom"
is a list containing the following components:
datanumeric |
a bool indicating whether the data is a numeric data frame. |
covariates |
a character string giving the name(s) of the included covariates. |
strt_num |
the number of strata. |
cov_num |
the number of covariates. |
level_num |
a vector of level numbers for each covariate. |
n |
the number of patients. |
Cov_Assig |
a |
assignments |
the randomization sequence. |
All strata |
a matrix containing all strata involved. |
Diff |
a matrix with only one column. There are final differences at the overall, within-stratum, and within-covariate-margin levels. |
method |
a character string describing the randomization procedure to be used. |
Data Type |
a character string giving the data type, |
framework |
the framework of the used randomization procedure: stratified randomization, or model-based method. |
data |
the data frame. |
References
Ma W, Ye X, Tu F, Hu F. carat: Covariate-Adaptive Randomization for Clinical Trials[J]. Journal of Statistical Software, 2023, 107(2): 1-47.
Shao J, Yu X, Zhong B. A theory for testing hypotheses under covariate-adaptive randomization[J]. Biometrika, 2010, 97(2): 347-360.
See Also
See StrBCD.sim
for allocating patients with covariate data generating mechanism.
See StrBCD.ui
for command-line user interface.
Examples
# a simple use
## Real Data
## creat a dataframe
df <- data.frame("gender" = sample(c("female", "male"), 1000, TRUE, c(1 / 3, 2 / 3)),
"age" = sample(c("0-30", "30-50", ">50"), 1000, TRUE),
"jobs" = sample(c("stu.", "teac.", "others"), 1000, TRUE),
stringsAsFactors = TRUE)
Res <- StrBCD(data = df)
## view the output
Res
## view all patients' profile and assignments
Res$Cov_Assig
## Simulated Data
cov_num = 3
level_num = c(2, 3, 3)
pr = c(0.4, 0.6, 0.3, 0.4, 0.3, 0.4, 0.3, 0.3)
Res.sim <- StrBCD.sim(n = 1000, cov_num, level_num, pr)
## view the output
Res.sim
## view the detials of difference
Res.sim$Diff
N <- 5
n <- 1000
cov_num <- 3
level_num <- c(2, 3, 5)
# Set pr to follow two tips:
# (1) length of pr should be sum(level_num);
# (2)sum of probabilities for each margin should be 1
pr <- c(0.4, 0.6, 0.3, 0.4, 0.3, rep(0.2, times = 5))
omega <- c(0.2, 0.2, rep(0.6 / cov_num, times = cov_num))
## generate a container to contain Diff
DH <- matrix(NA, ncol = N, nrow = 1 + prod(level_num) + sum(level_num))
DS <- matrix(NA, ncol = N, nrow = 1 + prod(level_num) + sum(level_num))
for(i in 1 : N){
result <- HuHuCAR.sim(n, cov_num, level_num, pr, omega)
resultS <- StrBCD.sim(n, cov_num, level_num, pr)
DH[ , i] <- result$Diff; DS[ , i] <- resultS$Diff
}
## do some analysis
require(dplyr)
## analyze the overall imbalance
Ana_O <- matrix(NA, nrow = 2, ncol = 3)
rownames(Ana_O) <- c("NEW", "Shao")
colnames(Ana_O) <- c("mean", "median", "95%quantile")
temp <- DH[1, ] %>% abs
tempS <- DS[1, ] %>% abs
Ana_O[1, ] <- c((temp %>% mean), (temp %>% median),
(temp %>% quantile(0.95)))
Ana_O[2, ] <- c((tempS %>% mean), (tempS %>% median),
(tempS %>% quantile(0.95)))
## analyze the within-stratum imbalances
tempW <- DH[2 : (1 + prod(level_num)), ] %>% abs
tempWS <- DS[2 : 1 + prod(level_num), ] %>% abs
Ana_W <- matrix(NA, nrow = 2, ncol = 3)
rownames(Ana_W) <- c("NEW", "Shao")
colnames(Ana_W) <- c("mean", "median", "95%quantile")
Ana_W[1, ] = c((tempW %>% apply(1, mean) %>% mean),
(tempW %>% apply(1, median) %>% mean),
(tempW %>% apply(1, mean) %>% quantile(0.95)))
Ana_W[2, ] = c((tempWS %>% apply(1, mean) %>% mean),
(tempWS %>% apply(1, median) %>% mean),
(tempWS %>% apply(1, mean) %>% quantile(0.95)))
## analyze the marginal imbalance
tempM <- DH[(1 + prod(level_num) + 1) :
(1 + prod(level_num) + sum(level_num)), ] %>% abs
tempMS <- DS[(1 + prod(level_num) + 1) :
(1 + prod(level_num) + sum(level_num)), ] %>% abs
Ana_M <- matrix(NA, nrow = 2, ncol = 3)
rownames(Ana_M) <- c("NEW", "Shao")
colnames(Ana_M) <- c("mean", "median", "95%quantile")
Ana_M[1, ] = c((tempM %>% apply(1, mean) %>% mean),
(tempM %>% apply(1, median) %>% mean),
(tempM %>% apply(1, mean) %>% quantile(0.95)))
Ana_M[2, ] = c((tempMS %>% apply(1, mean) %>% mean),
(tempMS %>% apply(1, median) %>% mean),
(tempMS %>% apply(1, mean) %>% quantile(0.95)))
AnaHP <- list(Ana_O, Ana_M, Ana_W)
names(AnaHP) <- c("Overall", "Marginal", "Within-stratum")
AnaHP