Cumulative distribution function for normal distribution.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x |
sample position |
||
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_norm_cdf_core(x, mu, sigma, tail) result(p) ! ==== Description !! Cumulative distribution function for normal distribution. ! ==== Declarations real(wp) , intent(in) :: x !! sample position 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) :: p !! returned probability integral ! ==== Instructions ! ---- compute CDF ! compute z-score z = (x - mu) / (sigma * sqrt(2.0_wp)) ! compute integral (left tailed) p = 0.5_wp * (1.0_wp + erf(z)) ! 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_norm_cdf_core