Percent point function/quantile functionfor the chi-squared distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | p |
probability between 0.0 and 1.0 |
||
real(kind=wp), | intent(in) | :: | df |
degrees of freedom |
||
real(kind=wp), | intent(in) | :: | loc |
location parameter |
||
real(kind=wp), | intent(in) | :: | scale |
scale parameter |
sample position
elemental function f_dst_chi2_ppf_core(p, df, loc, scale) result(x) ! ==== Description !! Percent point function/quantile functionfor the chi-squared distribution. ! ==== Declarations real(wp), intent(in) :: p !! probability between 0.0 and 1.0 real(wp), intent(in) :: df !! degrees of freedom real(wp), intent(in) :: loc !! location parameter real(wp), intent(in) :: scale !! scale parameter integer(i4), parameter :: i_max = c_bisect_i !! max. number of iterations real(wp), parameter :: tol = c_bisect_tol !! tolerance for convergence real(wp) :: a, b !! interval bounds real(wp) :: x_mid, p_mid !! midpoint and corresponding CDF value integer(i4) :: i !! iteration counter real(wp) :: x !! sample position ! ==== Instructions ! ---- compute PPF ! set initial section (min possible approaches 0) a = loc b = loc + df * 10.0_wp ! iteratively refine with bisection method do i = 1, i_max x_mid = 0.5_wp * (a + b) p_mid = f_dst_chi2_cdf_core(x_mid, df, loc=loc& &, scale=scale, tail="left") - p if (abs(p_mid) .lt. tol) then x = x_mid return else if (p_mid .lt. 0.0_wp) then a = x_mid else b = x_mid end if end do ! if x not found in iterations, pass sentinel if (i .ge. i_max) x = c_sentinel_r end function f_dst_chi2_ppf_core