Description Usage Arguments Value Examples
Extreme Value Bounds with Double Sampling
1 2 | estimator_ds(Y, Z, R1, Attempt, R2, minY, maxY, strata = NULL, alpha = 0.05,
data)
|
Y |
The (unquoted) outcome variable. Must be numeric. |
Z |
The (unquoted) assignment indicator variable. Must be numeric and take values 0 or 1. |
R1 |
The (unquoted) initial sample respose indicator variable. Must be numeric and take values 0 or 1. |
Attempt |
The (unquoted) follow-up sample attempt indicator variable. Must be numeric and take values 0 or 1. |
R2 |
The (unquoted) follow-up sample respose indicator variable. Must be numeric and take values 0 or 1. |
minY |
The minimum possible value of the outcome (Y) variable. |
maxY |
The maximum possible value of the outcome (Y) variable. |
strata |
A single (unquoted) variable that indicates which strata units are in. |
alpha |
The desired significance level. 0.05 by default. |
data |
A dataframe |
A results matrix
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 | set.seed(343) # For reproducibility
N <- 1000
# Potential Outcomes
Y_0 <- sample(1:5, N, replace=TRUE, prob = c(0.1, 0.3, 0.3, 0.2, 0.1))
Y_1 <- sample(1:5, N, replace=TRUE, prob = c(0.1, 0.1, 0.4, 0.3, 0.1))
R1_0 <- rbinom(N, 1, prob = 0.7)
R1_1 <- rbinom(N, 1, prob = 0.8)
R2_0 <- rbinom(N, 1, prob = 0.9)
R2_1 <- rbinom(N, 1, prob = 0.95)
# Covariate
strata <- as.numeric(Y_0 > 2)
# Random Assignment
Z <- rbinom(N, 1, .5)
# Reveal Initial Sample Outcomes
R1 <- Z*R1_1 + (1-Z)*R1_0 # Initial sample response
Y_star <- Z*Y_1 + (1-Z)*Y_0 # True outcomes
Y <- Y_star
Y[R1==0] <- NA # Mask outcome of non-responders
# Conduct Double Sampling
Attempt <- rep(0, N)
Attempt[is.na(Y)] <- rbinom(sum(is.na(Y)), 1, .5)
R2 <- rep(0, N)
R2[Attempt==1] <- (Z*R2_1 + (1-Z)*R2_0)[Attempt==1]
Y[R2==1 & Attempt==1] <- Y_star[R2==1 & Attempt==1]
df <- data.frame(Y, Z, R1, Attempt, R2, strata)
# Without post-stratification
estimator_ds(Y, Z, R1, Attempt, R2, minY=1, maxY=5, data=df)
# With post-stratification
estimator_ds(Y, Z, R1, Attempt, R2, minY=1, maxY=5, strata=strata, data=df)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.