rand.test {carat}  R Documentation 
Performs randomization test on treatment effects.
rand.test(data, Reps = 200, method = c("HuHuCAR", "PocSimMIN", "StrBCD",
"StrPBR", "DoptBCD", "AdjBCD"),
conf = 0.95, binwidth = 30, ...)
data 
a data frame. It consists of patients' profiles, treatment assignments and outputs. See 
Reps 
an integer. It is the number of randomized replications used in the randomization test. The default is 
method 
the randomization procedure to be used for testing. This package provides tests for 
conf 
confidence level of the interval. The default is 
binwidth 
the number of bins for each bar in histogram. The default is 30. 
... 
arguments to be passed to

The randomization test is described as follows:
1) For the observed responses Y_1,\dots,Y_n
and the treatment assignments T_1,T_2,\dots,T_n
, compute the observed test statistic
S_{obs} = \frac{\sum_{i=1}^nY_i*(T_i2)}{n_1}\frac{\sum_{i=1}^n Y_i*(T_i1)}{n_0}
where n_1
is the number of patients assigned to treatment 1
and n_0
is the number of patients assigned to treatment 2
;
2) Perform the covariateadaptive randomization procedure to obtain the new treatment assignments and calculate the corresponding test statistic S_i
. And repeat this process L
times;
3) Calculate the twosided Monte Carlo pvalue estimator
p = \frac{\sum_{l=1}^L I(S_l\ge S_{obs})}{L}
It returns an object of class "htest"
.
An object of class "htest"
is a list containing the following components:
p.value 
pvalue of the test, the null hypothesis is rejected if the pvalue is less than 
estimate 
the estimated difference in treatment effects between treatment 
conf.int 
a confidence interval under the chosen level 
method 
a character string indicating what type of test was performed. 
data.name 
a character string giving the name(s) of the data. 
statistic 
the value of the tstatistic. As the randomization test is a nonparametric method, we cannot calculate the tstatistic, so it is hidden in this result. 
Rosenberger W F, Lachin J M. Randomization in clinical trials: theory and practice[M]. John Wiley & Sons, 2015.
##generate data
set.seed(100)
n = 1000
cov_num = 5
level_num = c(2,2,2,2,2)
pr = rep(0.5,10)
beta = c(0.1,0.4,0.3,0.2,0.5)
mu1 = 0
mu2 = 0.01
sigma = 1
type = "linear"
p = 0.85
dataS = getData(n, cov_num, level_num, pr, type,
beta, mu1, mu2, sigma, "StrBCD", p)
#run the randomization test
library("ggplot2")
Strt = rand.test(data = dataS, Reps = 200,method = "StrBCD",
conf = 0.95, binwidth = 30,
p = 0.85)
Strt