Cumulative distribution function for student t 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) | :: | mu |
distribution location (mean) |
||
real(kind=wp), | intent(in) | :: | sigma |
distribution dispersion/scale (standard deviation) |
||
character(len=*), | intent(in) | :: | tail |
tail options |
returned probability integral
elemental function f_dst_t_cdf_core(x, df, mu, sigma, tail) result(p) ! ==== Description !! Cumulative distribution function for student t distribution. ! ==== Declarations real(wp) , intent(in) :: x !! sample position real(wp) , intent(in) :: df !! degrees of freedom real(wp) , intent(in) :: mu !! distribution location (mean) real(wp) , intent(in) :: sigma !! distribution dispersion/scale (standard deviation) character(len=*), intent(in) :: tail !! tail options real(wp) :: z !! z-score real(wp) :: xbeta, a, b !! parameters for beta function real(wp) :: p !! returned probability integral ! ==== Instructions ! ---- compute CDF ! compute z-score z = (x - mu) / sigma ! shape parameters for beta function a = 0.5_wp * df b = 0.5_wp xbeta = df / (df + z**2) ! compute integral (left tailed) if (z .ge. 0.0_wp) then p = 1.0_wp - 0.5_wp * f_dst_betai_core(xbeta, a, b) else p = 0.5_wp * f_dst_betai_core(xbeta, a, b) endif ! tail options ! NOTE: alternatively, compare z to 0.0 instead of x to mu 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. mu) then p = 2.0_wp * (1.0_wp - p) elseif (x .le. mu) then p = 2.0_wp * p endif ! confidence interval case("confidence") if (x .gt. mu) then p = 1.0_wp - 2.0_wp * (1.0_wp - p) elseif (x .le. mu) then p = 1.0_wp - 2.0_wp * p endif end select end function f_dst_t_cdf_core