你只需要一个近似a的CDF的函数和一个近似B的逆CDF(或PPF)的函数
q
已更正
=磅/平方英尺
B
(CDF)
A.
(q) )
.
对于您的示例数据,我们可以简单地使用
.cdf
和
.ppf
方法
scipy.stats.gamma
frozen distributions
具有适当的参数:
from scipy import stats
distA = stats.gamma(0.7, scale=50)
distB = stats.gamma(0.5, scale=70)
corrected_quantiles = distB.ppf(distA.cdf(quantiles[1:]))
当然,对于真实数据,您不太可能知道真正的底层分布的参数。如果您对它们的功能形式有很好的了解,您可以尝试对数据进行最大似然拟合,以估计它们:
distA = stats.gamma(*stats.gamma.fit(A))
distB = stats.gamma(*stats.gamma.fit(B))
如果做不到这一点,您可以尝试根据经验CDF进行插值/外推,例如使用
scipy.interpolate.InterpolatedUnivariateSpline
:
from scipy.interpolate import InterpolatedUnivariateSpline
# cubic spline interpolation
itp_A_cdf = InterpolatedUnivariateSpline(quantiles[1:], A_cdf, k=3)
# the PPF is the inverse of the CDF, so we simply reverse the order of the
# x & y arguments to InterpolatedUnivariateSpline
itp_B_ppf = InterpolatedUnivariateSpline(B_cdf, quantiles[1:], k=3)
itp_corrected_quantiles = itp_B_ppf(itp_A_cdf(quantiles[1:]))
fig, ax = plt.subplots(1, 1)
ax.hold(True)
ax.plot(quantiles[1:], A_cdf, '-r', lw=3, label='A')
ax.plot(quantiles[1:], B_cdf, '-k', lw=3, label='B')
ax.plot(corrected_quantiles, A_cdf, '--xr', lw=3, ms=10, mew=2, label='exact')
ax.plot(itp_corrected_quantiles, A_cdf, '--+b', lw=3, ms=10, mew=2,
label='interpolated')
ax.legend(loc=5)