# NOT RUN {
# Simulate data (DGP-(2) in the linked paper)
set.seed(0)
x <- rchisq(2000, df=1)
y <- -x + (1 + 0.5 * x) * rnorm(1000)
# True quantile and expected shortfall regression parameters (for alpha=0.025)
alpha=0.025
true_pars <- c(-1.959964, -1.979982, -2.337803, -2.168901)
# Joint estimator
fit_joint <- esreg(y ~ x, alpha=alpha)
# Two-step estimator
fit_twostep <- esreg_twostep(y ~ x, alpha=alpha)
# Compare the estimates
print(rbind(Truth=true_pars, Joint=coef(fit_joint), `Two-Step`=coef(fit_twostep)))
# ... and the estimation times
print(c(Joint=fit_joint$time, `Two Step`=fit_twostep$time))
# }
Run the code above in your browser using DataLab