Learn R Programming

carat (version 1.1)

DoptBCD: Atkinson's \(D_A\)-optimal Biased Coin Design

Description

Allocates patients to one of two treatments based on the \(D_A\)-optimal biased coin design with in the presence of the prognostic factors proposed by Atkinson A C (1982) <Doi:10.2307/2335853>.

Usage

# S3 method for carandom
DoptBCD(data)

Arguments

data

a dataframe. A row of the dataframe contains the covariate profile of a patient.

Value

It returns an object of class "carandom".

The function print is used to obtain results. The generic accessor functions Cov_Assig, Diff, data, All strata and others extract various useful features of the value returned by DoptBCD.

An object of class "carandom" is a list containing at least the following components:

cov_num

the number of covariates.

n

the number of patients.

Cov_Assign

a (cov_num + 1) * n matrix containing covariate profiles for all patients and the corresponding assignments. The \(i\)th column represents the \(i\)th patient. The first cov_num rows include patients' covariate profiles and the last row contains the assignment.

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 marginal levels.

Data Type

the data type. Real or Simulated.

Details

To minimize the loss associated with an experiment involving \(n\) patients, Atkinson's optimal applied \(D_A\)-optimality to the method, in which the probability of assigning the \((n+1)\)th patient to treatment 1 in the presence of prognostic factors is $$\frac{[1 - (1; \bold{x}^t_{n+1})(\bold{F}^t_n\bold{F}_n)^{-1}\bold{b}_n]^2}{[1-(1; \bold{x}^t_{n+1})(\bold{F}_n^t\bold{F}_n)^{-1}\bold{b}_n]^2+[1 + (1; \bold{x}_{n+1}^t)(\bold{F}_n^t\bold{F}_n)^{-1}\bold{b}_n]^2},$$ where \(\bold{X} = (\bold{x_i}, i = 1, \dots, n)\) and \(\bold{x}_i = (x_{i1}, \dots, x_{in})\) denote the covariate profile of the \(i\)th patient; and \(\bold{F}_n = [\bold{1}_n; \bold{X}]\) is the information matrix; and \(\bold{b}_n^T=(2\bold{T}_n-\bold{1}_n)^T\bold{F}_n\), \(\bold{T}_n = (T_1, \dots, T_n)\) is a sequence containing the first \(n\) patients' allocations.

Details of the procedure can be found in A.C.Atkinson (1982).

References

Atkinson A C. Optimum biased coin designs for sequential clinical trials with prognostic factors[J]. Biometrika, 1982, 69(1): 61-67.

See Also

See DoptBCD.sim for allocating patients with covariate data generating mechanism. See DoptBCD.ui for the command-line user interface.

Examples

Run this code
# NOT RUN {
# a simple use
## Real Data
df <- data.frame("gender" = sample(c("female", "male"), 100, TRUE, c(1 / 3, 2 / 3)), 
                 "age" = sample(c("0-30", "30-50", ">50"), 100, TRUE), 
                 "jobs" = sample(c("stu.", "teac.", "others"), 100, TRUE), 
                 stringsAsFactors = TRUE)
Res <- DoptBCD(df)
## view the output
Res
# }
# NOT RUN {
## view all patients' profile and assignments
## Res$Cov_Assig
# }
# NOT RUN {
## Simulated Data
n <- 1000
cov_num <- 2 

level_num <- c(2, 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, rep(0.2, times = 5))
Res.sim <- DoptBCD.sim(n, cov_num, level_num, pr)
## view the output
Res.sim
# }
# NOT RUN {
## view the difference between treatment 1 and treatment 2 
##             at overall, within-strt. and overall levels
Res.sim$Diff
# }
# NOT RUN {
# }
# NOT RUN {
N <- 5
n <- 100
cov_num <- 2
level_num <- c(3, 5) # << adjust to your CPU and the length should correspond to cov_num
## 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.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))
DA <- 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)
  resultA <- StrBCD.sim(n, cov_num, level_num, pr)
  DH[ , i] <- result$Diff; DA[ , i] <- resultA$Diff
}
## do some analysis
require(dplyr)

## analyze the overall imbalance
Ana_O <- matrix(NA, nrow = 2, ncol = 3)
rownames(Ana_O) <- c("HuHuCAR", "DoptBCD")
colnames(Ana_O) <- c("mean", "median", "95%quantile")
temp <- DH[1, ] %>% abs
tempA <- DA[1, ] %>% abs
Ana_O[1, ] <- c((temp %>% mean), (temp %>% median),
                (temp %>% quantile(0.95)))
Ana_O[2, ] <- c((tempA %>% mean), (tempA %>% median),
                (tempA %>% quantile(0.95)))

## analyze the within-stratum imbalances
tempW <- DH[2 : (1 + prod(level_num)), ] %>% abs
tempWA <- DA[2 : 1 + prod(level_num), ] %>% abs
Ana_W <- matrix(NA, nrow = 2, ncol = 3)
rownames(Ana_W) <- c("HuHuCAR", "DoptBCD")
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((tempWA %>% apply(1, mean) %>% mean),
               (tempWA %>% apply(1, median) %>% mean),
               (tempWA %>% 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
tempMA <- DA[(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("HuHuCAR", "DoptBCD")
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((tempMA %>% apply(1, mean) %>% mean),
               (tempMA %>% apply(1, median) %>% mean),
               (tempMA %>% apply(1, mean) %>% quantile(0.95)))

AnaHP <- list(Ana_O, Ana_M, Ana_W)
names(AnaHP) <- c("Overall", "Marginal", "Within-stratum")

AnaHP
# }

Run the code above in your browser using DataLab