f_dst_chi2_ppf_core Function

public elemental function f_dst_chi2_ppf_core(p, df, loc, scale) result(x)

Percent point function/quantile functionfor the chi-squared distribution.

Arguments

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

probability between 0.0 and 1.0

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

Return Value real(kind=wp)

sample position


Calls

proc~~f_dst_chi2_ppf_core~~CallsGraph proc~f_dst_chi2_ppf_core f_dst_chi2_ppf_core proc~f_dst_chi2_cdf_core f_dst_chi2_cdf_core proc~f_dst_chi2_ppf_core->proc~f_dst_chi2_cdf_core proc~f_dst_gammai_core f_dst_gammai_core proc~f_dst_chi2_cdf_core->proc~f_dst_gammai_core

Called by

proc~~f_dst_chi2_ppf_core~~CalledByGraph proc~f_dst_chi2_ppf_core f_dst_chi2_ppf_core proc~f_dst_chi2_ppf f_dst_chi2_ppf proc~f_dst_chi2_ppf->proc~f_dst_chi2_ppf_core interface~fsml_chi2_ppf fsml_chi2_ppf interface~fsml_chi2_ppf->proc~f_dst_chi2_ppf

Source Code

elemental function f_dst_chi2_ppf_core(p, df, loc, scale) result(x)

! ==== Description
!! Percent point function/quantile functionfor the chi-squared distribution.

! ==== Declarations
  real(wp), intent(in)   :: p                  !! probability between 0.0 and 1.0
  real(wp), intent(in)   :: df                 !! degrees of freedom
  real(wp), intent(in)   :: loc                !! location parameter
  real(wp), intent(in)   :: scale              !! scale parameter
  integer(i4), parameter :: i_max = c_bisect_i !! max. number of iterations
  real(wp), parameter    :: tol = c_bisect_tol !! tolerance for convergence
  real(wp)               :: a, b               !! interval bounds
  real(wp)               :: x_mid, p_mid       !! midpoint and corresponding CDF value
  integer(i4)            :: i                  !! iteration counter
  real(wp)               :: x                  !! sample position

! ==== Instructions

! ---- compute PPF

  ! set initial section (min possible approaches 0)
  a = loc
  b = loc + df * 10.0_wp

  ! iteratively refine with bisection method
  do i = 1, i_max
     x_mid = 0.5_wp * (a + b)
     p_mid = f_dst_chi2_cdf_core(x_mid, df, loc=loc&
          &, scale=scale, tail="left") - p
     if (abs(p_mid) .lt. tol) then
        x = x_mid
        return
     else if (p_mid .lt. 0.0_wp) then
        a = x_mid
     else
        b = x_mid
     end if
  end do

  ! if x not found in iterations, pass sentinel
  if (i .ge. i_max) x = c_sentinel_r

end function f_dst_chi2_ppf_core