Description Usage Arguments Value Author(s) References Examples
View source: R/randomization_inference.R
Performs Fisher's randomization test for sharp null hypotheses of the form H_0: c_1 Y_i(1) + c_2 Y_i(2) - τ = 0, for a vector of contrasts (c_1, c_2).
1 2 3 4 5 6 7 8 9 |
Y_obs |
Vector of observed outcome. |
alloc_obs |
Vector of observed treatment assignment. |
alloc |
A matrix of treatment assignments over which the randomization distribution of the test statistic
is computed. Each row of |
contrast |
A vector of the coefficients of the treatment contrast of interest. For example, for estimating the
average treatment effect of treatment 1 versus treatment 2, |
tau |
The value of the treatment contrast specified by the sharp null hypothesis. |
method |
The method of computing the test statistic. If |
alternative |
The type of alternative hypothesis used. For right-sided test, |
A list containing the following items.
test_stat_obs
: The observed value of the test statistic.
test_stat_iter
: A vector of values of the test statistic across repeated randomizations.
p_value
: p-value of the test.
Ambarish Chattopadhyay, Carl N. Morris and Jose R. Zubizarreta.
Chattopadhyay, A., Morris, C. N., and Zubizarreta, J. R. (2020), “Randomized and Balanced Allocation
of Units into Treatment Groups Using the Finite Selection Model for R
".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Consider N = 12, n1 = n2 = 6.
# We test the sharp null of no treatment effect under CRD.
df_sample = data.frame(index = 1:12, x = c(20,30,40,40,50,60,20,30,40,40,50,60))
# True potential outcomes.
Y_1_true = 100 + (df_sample$x - mean(df_sample$x)) + rnorm(12, 0, 4)
Y_2_true = Y_1_true + 50
# Generate the realized assignment under CRD.
fc = crd(data_frame = df_sample, n_treat = 2, treat_sizes = c(6,6), control = FALSE)
Z_crd_obs = fc$Treat
# Get the observed outcomes
Y_obs = Y_1_true
Y_obs[Z_crd_obs == 2] = Y_2_true[Z_crd_obs == 2]
# Generate 1000 assignments under CRD.
Z_crd_iter = matrix(rep(0, 1000 * 12), nrow = 1000)
for(i in 1:1000)
{
fc = crd(data_frame = df_sample, n_treat = 2, treat_sizes = c(6,6), control = FALSE)
Z_crd_iter[i,] = fc$Treat
}
# Test for the sharp null H0: Y_i(1) = Y_i(0) for all i.
# Alternative: not H0 (two-sided test).
perm = perm_test(Y_obs = Y_obs, alloc_obs = Z_crd_obs, alloc = Z_crd_iter,
contrast = c(1,-1), tau = 0, method = "marginal mean", alternative = 'not equal')
# Obtain the p-value.
perm$p_value
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.