test_cdft_asymptotic.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # gh-14777 regression tests
  2. # Test stdtr and stdtrit with infinite df and large values of df
  3. import numpy as np
  4. from numpy.testing import assert_allclose, assert_equal
  5. from scipy.special import stdtr, stdtrit, ndtr, ndtri
  6. def test_stdtr_vs_R_large_df():
  7. df = [1e10, 1e12, 1e120, np.inf]
  8. t = 1.
  9. res = stdtr(df, t)
  10. # R Code:
  11. # options(digits=20)
  12. # pt(1., c(1e10, 1e12, 1e120, Inf))
  13. res_R = [0.84134474605644460343,
  14. 0.84134474606842180044,
  15. 0.84134474606854281475,
  16. 0.84134474606854292578]
  17. assert_allclose(res, res_R, rtol=2e-15)
  18. # last value should also agree with ndtr
  19. assert_equal(res[3], ndtr(1.))
  20. def test_stdtrit_vs_R_large_df():
  21. df = [1e10, 1e12, 1e120, np.inf]
  22. p = 0.1
  23. res = stdtrit(df, p)
  24. # R Code:
  25. # options(digits=20)
  26. # qt(0.1, c(1e10, 1e12, 1e120, Inf))
  27. res_R = [-1.2815515656292593150,
  28. -1.2815515655454472466,
  29. -1.2815515655446008125,
  30. -1.2815515655446008125]
  31. assert_allclose(res, res_R, rtol=1e-15)
  32. # last value should also agree with ndtri
  33. assert_equal(res[3], ndtri(0.1))
  34. def test_stdtr_stdtri_invalid():
  35. # a mix of large and inf df with t/p equal to nan
  36. df = [1e10, 1e12, 1e120, np.inf]
  37. x = np.nan
  38. res1 = stdtr(df, x)
  39. res2 = stdtrit(df, x)
  40. res_ex = 4*[np.nan]
  41. assert_equal(res1, res_ex)
  42. assert_equal(res2, res_ex)