f_dst_norm_cdf_core Function

public elemental function f_dst_norm_cdf_core(x, mu, sigma, tail) result(p)

Cumulative distribution function for normal distribution.

Arguments

Type IntentOptional 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

Return Value real(kind=wp)

returned probability integral


Called by

proc~~f_dst_norm_cdf_core~~CalledByGraph proc~f_dst_norm_cdf_core f_dst_norm_cdf_core proc~f_dst_norm_cdf f_dst_norm_cdf proc~f_dst_norm_cdf->proc~f_dst_norm_cdf_core proc~f_dst_norm_ppf_core f_dst_norm_ppf_core proc~f_dst_norm_ppf_core->proc~f_dst_norm_cdf_core proc~s_tst_ranksum_core s_tst_ranksum_core proc~s_tst_ranksum_core->proc~f_dst_norm_cdf_core proc~s_tst_signedrank_1s_core s_tst_signedrank_1s_core proc~s_tst_signedrank_1s_core->proc~f_dst_norm_cdf_core interface~fsml_norm_cdf fsml_norm_cdf interface~fsml_norm_cdf->proc~f_dst_norm_cdf proc~f_dst_norm_ppf f_dst_norm_ppf proc~f_dst_norm_ppf->proc~f_dst_norm_ppf_core proc~s_tst_ranksum s_tst_ranksum proc~s_tst_ranksum->proc~s_tst_ranksum_core proc~s_tst_signedrank_1s s_tst_signedrank_1s proc~s_tst_signedrank_1s->proc~s_tst_signedrank_1s_core proc~s_tst_signedrank_2s_core s_tst_signedrank_2s_core proc~s_tst_signedrank_2s_core->proc~s_tst_signedrank_1s_core interface~fsml_norm_ppf fsml_norm_ppf interface~fsml_norm_ppf->proc~f_dst_norm_ppf interface~fsml_ranksum fsml_ranksum interface~fsml_ranksum->proc~s_tst_ranksum interface~fsml_signedrank_1sample fsml_signedrank_1sample interface~fsml_signedrank_1sample->proc~s_tst_signedrank_1s proc~s_tst_signedrank_2s s_tst_signedrank_2s proc~s_tst_signedrank_2s->proc~s_tst_signedrank_2s_core interface~fsml_signedrank_paired fsml_signedrank_paired interface~fsml_signedrank_paired->proc~s_tst_signedrank_2s

Source Code

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