Cumulative distribution function for the chi-squared distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x |
sample position |
||
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 |
||
character(len=*), | intent(in) | :: | tail |
tail options |
resulting CDF value
elemental function f_dst_chi2_cdf_core(x, df, loc, scale, tail) result(p) ! ==== Description !! Cumulative distribution function for the chi-squared distribution. ! ==== Declarations real(wp) , intent(in) :: x !! sample position real(wp) , intent(in) :: df !! degrees of freedom real(wp) , intent(in) :: loc !! location parameter real(wp) , intent(in) :: scale !! scale parameter character(len=*), intent(in) :: tail !! tail options real(wp) :: z !! standardised variable real(wp) :: p !! resulting CDF value ! ==== Instructions ! ----compute CDF ! compute integral (left tailed) z = (x - loc) / scale if (z .le. 0.0_wp .or. df .le. 0.0_wp .or. scale .le. 0.0_wp) then p = 0.0_wp else p = f_dst_gammai_core(df / 2.0_wp, z / 2.0_wp) endif ! tail options select case(tail) ! left-tailed; P(z<x) case("left") p = p ! right-tailed; P(z>x) case("right") p = 1.0_wp - p ! two-tailed case("two") if (x .gt. loc) then p = 2.0_wp * (1.0_wp - p) elseif (x .le. loc) then p = 2.0_wp * p endif ! confidence interval case("confidence") if (x .gt. loc) then p = 1.0_wp - 2.0_wp * (1.0_wp - p) elseif (x .le. loc) then p = 1.0_wp - 2.0_wp * p endif end select end function f_dst_chi2_cdf_core