Description Usage Arguments Value References Examples
View source: R/Function_CRTBound.R
Reform the data to a compatible form for ITT
, HTE
, SharpBound
, and LongHudgens
functions.
1 | Data.Reform(Y, Z, A, C, X, seed=1)
|
Y |
N-by-1 vector containing the outcome of individuals where N is the number of individuals in the population. |
Z |
N-by-1 0-1 vector containing the treatment assignment where Z=1 indicates an individual was assigned to treatment. |
A |
N-by-1 0-1 vector containing the actual treatment usage of individuals where A=1 indicates an individual actually used treatment. |
C |
N-by-1 numeric vector containing cluster ID where individuals from the same cluster have the same C value. |
X |
N-by-p numeric matrix or data frame containing the pre-treatment covariates. |
seed |
(Optional) A random seed to generate the random noise used in |
Y |
N-by-1 vector; same as input Y. |
Z |
N-by-1 vector; same as input Z. |
A |
N-by-1 vector; same as input A. |
C |
N-by-1 vector; same as input C. |
X |
N-by-p matrix or data frame; same as input X. |
N |
The number of individuals in the population. |
J |
The number of clusters in the population. |
Class |
J-by-1 vector of cluster ID. |
nc |
J-by-1 vector of cluster sizes. |
n |
N-by-1 vector of cluster sizes and the same as |
Zc |
J-by-1 vector of treatment assignment and the simplified form of input Z. |
m |
The number of clusters that were assigned to treatment. |
error |
N-by-3 vector of the random noises and are used in |
Chan Park & Hyunseung Kang (2021+) Assumption-Lean Analysis of Cluster Randomized Trials in Infectious Diseases for Intent-to-Treat Effects and Network Effects, Journal of the American Statistical Association [Link]
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #################################
# Generate Population
#################################
J <- 100 ; m <- 60
nc <- sample(c(3,4,5),J,replace=T)
N <- sum(nc)
C <- rep(1:J,nc)
n <- rep(nc,nc)
X1 <- rnorm(N)
X2 <- rbinom(N,1,0.3)
X3 <- rep(rnorm(J),nc)
A0 <- rbinom(N,1,logistic(-2+2*X3))
A1 <- apply(cbind(A0,rbinom(N,1,logistic(-2+3*X1+3*X2+2*X3))),1,max)
OtherA1 <- (rep(aggregate(A1~C,FUN="sum")[,2],nc)-A1)/(n-1)
NT <- which(A1==0 & A0==0)
AT <- which(A1==1 & A0==1)
CO <- which(A1==1 & A0==0)
Y0 <- Y1 <- rep(0,N)
for(jj in NT){
Y0[jj] <- rbinom(1,1,logistic(-2+2*OtherA1[jj]))
Y1[jj] <- max(Y0[jj],rbinom(1,1,logistic(-2+2*OtherA1[jj])))
}
for(jj in AT){
Y0[jj] <- rbinom(1,1,logistic(2+X1[jj]+X2[jj]))
Y1[jj] <- max(Y0[jj],rbinom(1,1,logistic(2+X1[jj]+X2[jj])))
}
for(jj in CO){
Y0[jj] <- rbinom(1,1,logistic(-2+2*OtherA1[jj]))
Y1[jj] <- max(Y0[jj],rbinom(1,1,logistic(2+X1[jj]+X2[jj])))
}
X <- cbind(1,X1,X2,X3,n)
Zc <- rep(0,J)
Zc[sort(sample(J,m))] <- 1
Z <- rep(Zc,nc)
A <- Z*A1 + (1-Z)*A0
Y <- Z*Y1 + (1-Z)*Y0
#################################
# Reform the Data
#################################
Reformed.Data <- Data.Reform(Y,Z,A,C,X,seed=1)
Simulated.Data <- Simulation.Reform(Y0,Y1,Z,A0,A1,C,X,seed=1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.