f_dst_logistic_cdf_core Function

public elemental function f_dst_logistic_cdf_core(x, mu, scale, tail) result(p)

Cumulative distribution function for logistic distribution.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x

sample position

real(kind=wp), intent(in) :: mu

distribution location

real(kind=wp), intent(in) :: scale

distribution scale

character(len=*), intent(in) :: tail

tail options

Return Value real(kind=wp)


Called by

proc~~f_dst_logistic_cdf_core~~CalledByGraph proc~f_dst_logistic_cdf_core f_dst_logistic_cdf_core proc~f_dst_logistic_cdf f_dst_logistic_cdf proc~f_dst_logistic_cdf->proc~f_dst_logistic_cdf_core interface~fsml_logistic_cdf fsml_logistic_cdf interface~fsml_logistic_cdf->proc~f_dst_logistic_cdf

Source Code

elemental function f_dst_logistic_cdf_core(x, mu, scale, tail) result(p)

! ==== Description
!! Cumulative distribution function for logistic distribution.

! ==== Declarations
  real(wp)        , intent(in) :: x     !! sample position
  real(wp)        , intent(in) :: mu    !! distribution location
  real(wp)        , intent(in) :: scale !! distribution scale
  character(len=*), intent(in) :: tail  !! tail options
  real(wp)                     :: z     !! z-score
  real(wp)                     :: p

! ==== Instructions

  ! compute z-score
  z = (x - mu) / scale

  ! compute integral (left tailed); partition by z for numerical stability
  if (z .ge. 0.0_wp) then
     p = 1.0_wp / (1.0_wp + exp(-z))
  else
     p = exp(z) / (1.0_wp + exp(z))
  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. mu) then
           p = 2.0_wp * (1.0_wp - p)
        else
           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)
        else
           p = 1.0_wp - 2.0_wp * p
        endif
  end select

end function f_dst_logistic_cdf_core