I want to compare a percentile metric for control vs treatment. Using bootstrap, I see two ways of doing so and wonder which one makes more sense.
Approach 1: Every time:
- Bootstrap the control group and get the percentile,
- Bootstrap the treatment group and get the percentile
- Compute the difference. Repeat B times to get the differences and get the CI.
Approach 2:
- Bootstrap the control B times, get the average and variance of the metric
- Bootstrap the treatment B times, get the average and variance of the metric
- Compute the difference and its variance, assuming they are independent.
Below is a simulation code in R. The 2nd approach has narrower CI, but requires normal assumption.
A <- rnorm(1000, 0.1, 1)
B <- rnorm(1000, 0.15, 1)
pctA = quantile(A, 0.99)
pctB = quantile(B, 0.99)
# Approach 1:
# 1. Bootstrap each set
# 2. Compute the differences for each bootstrap sample
# 3. Get confidence intervals
N = 500
diffBoot = rep(NA, N)
for (i in 1:N) {
tempA = sample(A, size=1000, replace=TRUE)
tempB = sample(B, size=1000, replace=TRUE)
diff = quantile(tempA, 0.99) - quantile(tempB, 0.99)
diffBoot[i] = diff
}
mean(diffBoot)
quantile(diffBoot, c(0.025, 0.9725))
# Approach 2:
# 1. Bootstrap each set
# 2. Compute metrics and variances
# 3. Get differences and confidence intervals
N = 500
pctAboot = rep(NA, N)
pctBboot = rep(NA, N)
for (i in 1:N) {
tempA = sample(A, size=1000, replace=TRUE)
tempB = sample(B, size=1000, replace=TRUE)
pctAtemp = quantile(tempA, 0.99)
pctBtemp = quantile(tempB, 0.99)
pctAboot[i] = pctAtemp
pctBboot[i] = pctBtemp
}
meanboot <- mean(pctAboot - pctBboot)
sdboot <- sqrt(var(pctAboot) + var(pctBboot))
meanboot / (1.96 * sdboot)
```
tempB = sample(B, size=1000, replace=TRUE)
: here B is 500, not B <- rnorm(1000, 0.15, 1) $\endgroup$