# NOT RUN {
# Heterogeneous example
set.seed(123)
n = 200
X = cbind(rep(1, n), 1:n/n)
beta = c(-1, 0.2)
ind = c(rep(0, 0.9*n), rep(1, .1*n)) # cluster indicator
y = X %*% beta + rnorm(n, sd= (1-ind) * 0.1 + ind * 5) # heteroskedastic
confint(lm(y ~ X + 0)) # normal OLS CI is imprecise
cl = list(which(ind==0), which(ind==1)) # define the clustering
rrinf_clust(y, X, "perm", cl) # improved CI through clustered errors
# }
Run the code above in your browser using DataLab