def bias_corrected_ci(true_coeff, samples, conf=95):
"""
Return the bias-corrected bootstrap confidence interval, using the method from the book.
:param true_coeff: The estimates in the original sample
:param samples: The bootstrapped estimates
:param conf: The level of the desired confidence interval
:return: The bias-corrected LLCI and ULCI for the bootstrapped estimates.
"""
ptilde = (samples < true_coeff).mean()
Z = norm.ppf(ptilde)
Zci = z_score(conf)
Zlow, Zhigh = -Zci + 2 * Z, Zci + 2 * Z
plow, phigh = norm._cdf(Zlow), norm._cdf(Zhigh)
llci = np.percentile(samples, plow * 100, interpolation='lower')
ulci = np.percentile(samples, phigh * 100, interpolation='higher')
return llci, ulci
评论列表
文章目录