from scipy.special import ncfdtr, chndtr, chdtrc
import numpy as np
import matplotlib.pyplot as plt
v2 = 3
v1 = 2
nc = 1.
f = 1.5
fig, (top, bottom) = plt.subplots(2, 1)
v1_plot = np.logspace(-5, 5, 10000)
p = ncfdtr(v1_plot, v2, nc, f)
top.semilogx(v1_plot, p)
left_limit = np.exp(-0.5 * nc)
right_limit_chi_sq =chdtrc(v2, v2 / f)
top.set_xlabel('v1')
top.set_ylabel('p')
top.set_title(f'Noncentral F CDF(v1, {v2}, {nc}, {f})')
top.hlines(left_limit, v1_plot.min(), v1_plot.max(), colors='r', linestyles='--', label='left limit: exp(-0.5 * nc)')
top.hlines(right_limit_chi_sq, v1_plot.min(), v1_plot.max(), colors='b', linestyles='--', label='Right limit: 1 - Chi Sq.(v2 / f, v2)')
top.legend()
v2_plot = np.logspace(-5, 5, 10000)
p_v2 = ncfdtr(v1, v2_plot, nc, f)
bottom.semilogx(v2_plot, p_v2)
v2_right_limit = chndtr( f * v1, v1, nc)
bottom.set_xlabel('v2')
bottom.set_ylabel('p')
bottom.set_title(f'Noncentral F CDF({v1}, v2, {nc}, {f})')
bottom.hlines(0, v2_plot.min(), v2_plot.max(), colors='r', linestyles='--', label='left limit: 0')
bottom.hlines(v2_right_limit, v2_plot.min(), v2_plot.max(), colors='g', linestyles='--', label='right limit: Nonc. Chi Sq.(f * v1, v1, nc)')
bottom.legend()
fig.tight_layout()
plt.show()
The check for the monotonicity of the noncentral F CDF as a function of the degrees of freedom parameters relies on asymptotic expressions for the right limit. For the left limits on the other hands, we still use an arbitrary
smallValueand compute the CDF for it. Instead, we could also use simple asymptotic expressions.For the
v1case we simply getF=exp(-nc/2)and for thev1caseF=0. This can be seen in the following plot. It can also be formally proven using the incomplete beta formulation of the CDF.CC @NAThompson This is what I had in mind here.
Python code