SEVERITY Procedure

Predefined Utility Functions

The following predefined utility functions are provided with the SEVERITY procedure and are available in the Sashelp.Svrtdist library:

SVRTUTIL_EDF


This function computes the empirical distribution function (EDF) estimate at the specified value of the random variable given the EDF estimate for a sample.

  • Type: Function

  • Signature: SVRTUTIL_EDF(y, n, x{*}, F{*}, Ftype)

  • Argument description:

    y

    Value of the random variable at which the EDF estimate is desired

    n

    Dimension of the x and F input arrays

    x{*}

    Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.

    F{*}

    Input numeric array of dimension n in which each F[i] contains the EDF estimate for x[i]. These values must be sorted in nondecreasing order.

    Ftype

    Type of the empirical estimate that is stored in the x and F arrays. For definitions of types, see the section Supplying EDF Estimates to Functions and Subroutines.

  • Return value: The EDF estimate at y

The type of the sample EDF estimate determines how the EDF estimate at y is computed. For more information, see the section Supplying EDF Estimates to Functions and Subroutines.

SVRTUTIL_EMPLIMMOMENT


This function computes the empirical estimate of the limited moment of specified order for the specified upper limit, given the EDF estimate for a sample.

  • Type: Function

  • Signature: SVRTUTIL_EMPLIMMOMENT(k, u, n, x{*}, F{*}, Ftype)

  • Argument description:

    k

    Order of the desired empirical limited moment

    u

    Upper limit on the value of the random variable to be used in the computation of the desired empirical limited moment

    n

    Dimension of the x and F input arrays

    x{*}

    Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.

    F{*}

    Input numeric array of dimension n in which each F[i] contains the EDF estimate for x[i]. These values must be sorted in nondecreasing order.

    Ftype

    Type of the empirical estimate that is stored in the x and F arrays. For definitions of types, see the section Supplying EDF Estimates to Functions and Subroutines.

  • Return value: The desired empirical limited moment

The empirical limited moment is computed by using the empirical estimate of the CDF. If upper F Subscript n Baseline left-parenthesis x right-parenthesis denotes the EDF at x, then the empirical limited moment of order k with upper limit u is defined as

upper E Subscript n Baseline left-bracket left-parenthesis upper X logical-and u right-parenthesis Superscript k Baseline right-bracket equals k integral Subscript 0 Superscript u Baseline left-parenthesis 1 minus upper F Subscript n Baseline left-parenthesis x right-parenthesis right-parenthesis x Superscript k minus 1 Baseline d x

The SVRTUTIL_EMPLIMMOMENT function uses the piecewise linear nature of upper F Subscript n Baseline left-parenthesis x right-parenthesis as described in the section Supplying EDF Estimates to Functions and Subroutines to compute the integration.

SVRTUTIL_HILLCUTOFF


This function computes an estimate of the value where the right tail of a distribution is expected to begin. The function implements the algorithm described in Danielsson et al. 2001. The description of the algorithm uses the following notation:

n

Number of observations in the original sample

B

Number of bootstrap samples to draw

m 1

Size of the bootstrap sample in the first step of the algorithm (m 1 less-than n)

x Subscript left-parenthesis i right-parenthesis Superscript j comma m

ith order statistic of jth bootstrap sample of size m (1 less-than-or-equal-to i less-than-or-equal-to m comma 1 less-than-or-equal-to j less-than-or-equal-to upper B)

x Subscript left-parenthesis i right-parenthesis

ith order statistic of the original sample (1 less-than-or-equal-to i less-than-or-equal-to n)

Given the input sample x and values of B and m 1, the steps of the algorithm are as follows:

  1. Take B bootstrap samples of size m 1 from the original sample.

  2. Find the integer k 1 that minimizes the bootstrap estimate of the mean squared error:

    k 1 equals arg min Underscript 1 less-than-or-equal-to k less-than m 1 Endscripts upper Q left-parenthesis m 1 comma k right-parenthesis
  3. Take B bootstrap samples of size m 2 equals m 1 squared slash n from the original sample.

  4. Find the integer k 2 that minimizes the bootstrap estimate of the mean squared error:

    k 2 equals arg min Underscript 1 less-than-or-equal-to k less-than m 2 Endscripts upper Q left-parenthesis m 2 comma k right-parenthesis
  5. Compute the integer k Subscript opt, which is used for computing the cutoff point:

    k Subscript opt Baseline equals StartFraction k 1 squared Over k 2 EndFraction left-parenthesis StartFraction log left-parenthesis k 1 right-parenthesis Over 2 log left-parenthesis m 1 right-parenthesis minus log left-parenthesis k 1 right-parenthesis EndFraction right-parenthesis Superscript 2 minus 2 log left-parenthesis k 1 right-parenthesis slash log left-parenthesis m 1 right-parenthesis
  6. Set the cutoff point equal to x Subscript left-parenthesis k Sub Subscript opt Subscript plus 1 right-parenthesis.

The bootstrap estimate of the mean squared error is computed as

upper Q left-parenthesis m comma k right-parenthesis equals StartFraction 1 Over upper B EndFraction sigma-summation Underscript j equals 1 Overscript upper B Endscripts MSE Subscript j Baseline left-parenthesis m comma k right-parenthesis

The mean squared error of jth bootstrap sample is computed as

MSE Subscript j Baseline left-parenthesis m comma k right-parenthesis equals left-parenthesis upper M Subscript j Baseline left-parenthesis m comma k right-parenthesis minus 2 left-parenthesis gamma Subscript j Baseline left-parenthesis m comma k right-parenthesis right-parenthesis squared right-parenthesis squared

where upper M Subscript j Baseline left-parenthesis m comma k right-parenthesis is a control variate proposed by Danielsson et al. 2001,

upper M Subscript j Baseline left-parenthesis m comma k right-parenthesis equals StartFraction 1 Over k EndFraction sigma-summation Underscript i equals 1 Overscript k Endscripts left-parenthesis log left-parenthesis x Subscript left-parenthesis m minus i plus 1 right-parenthesis Superscript j comma m Baseline right-parenthesis minus log left-parenthesis x Subscript left-parenthesis m minus k right-parenthesis Superscript j comma m Baseline right-parenthesis right-parenthesis squared

and gamma Subscript j Baseline left-parenthesis m comma k right-parenthesis is the Hill’s estimator of the tail index (Hill 1975),

gamma Subscript j Baseline left-parenthesis m comma k right-parenthesis equals StartFraction 1 Over k EndFraction sigma-summation Underscript i equals 1 Overscript k Endscripts log left-parenthesis x Subscript left-parenthesis m minus i plus 1 right-parenthesis Superscript j comma m Baseline right-parenthesis minus log left-parenthesis x Subscript left-parenthesis m minus k right-parenthesis Superscript j comma m Baseline right-parenthesis

This algorithm has two tuning parameters, B and m 1. The number of bootstrap samples B is chosen based on the availability of computational resources. The optimal value of m 1 is chosen such that the following ratio, upper R left-parenthesis m 1 right-parenthesis, is minimized:

upper R left-parenthesis m 1 right-parenthesis equals StartFraction left-parenthesis upper Q left-parenthesis m 1 comma k 1 right-parenthesis right-parenthesis squared Over upper Q left-parenthesis m 2 comma k 2 right-parenthesis EndFraction

The SVRTUTIL_HILLCUTOFF utility function implements the preceding algorithm. It uses the grid search method to compute the optimal value of m 1.

  • Type: Function

  • Signature: SVRTUTIL_HILLCUTOFF(n, x{*}, b, s, status)

  • Argument description:

    n

    Dimension of the array x

    x{*}

    Input numeric array of dimension n that contains the sample

    b

    Number of bootstrap samples used to estimate the mean squared error. If b is less than 10, then a default value of 50 is used.

    s

    Approximate number of steps used to search the optimal value of m 1 in the range left-bracket n Superscript 0.75 Baseline comma n minus 1 right-bracket. If s is less than or equal to 1, then a default value of 10 is used.

    status

    Output argument that contains the status of the algorithm. If the algorithm succeeds in computing a valid cutoff point, then status is set to 0. If the algorithm fails, then status is set to 1.

  • Return value: The cutoff value where the right tail is estimated to start. If the size of the input sample is inadequate (n less-than-or-equal-to 5), then a missing value is returned and status is set to a missing value. If the algorithm fails to estimate a valid cutoff value (status = 1), then the fifth-largest value in the input sample is returned.

SVRTUTIL_PERCENTILE


This function computes the specified empirical percentile given the EDF estimates.

  • Type: Function

  • Signature: SVRTUTIL_PERCENTILE(p, n, x{*}, F{*}, Ftype)

  • Argument description:

    p

    Desired percentile. The value must be in the interval (0,1). The function returns the 100pth percentile.

    n

    Dimension of the x and F input arrays

    x{*}

    Input numeric array of dimension n that contains values of the random variable observed in the sample. These values are sorted in nondecreasing order.

    F{*}

    Input numeric array of dimension n in which each F[i] contains the EDF estimate for x[i]. These values must be sorted in nondecreasing order.

    Ftype

    Type of the empirical estimate that is stored in the x and F arrays. For definitions of types, see the section Supplying EDF Estimates to Functions and Subroutines.

  • Return value: The 100pth percentile of the input sample

The method used to compute the percentile depends on the type of the EDF estimate (Ftype argument).

Ftype = 1

Smoothed empirical estimates are computed using the method described in Klugman, Panjer, and Willmot (1998). Let left floor x right floor denote the greatest integer less than or equal to x. Define g equals left floor p left-parenthesis n plus 1 right-parenthesis right floor and h equals p left-parenthesis n plus 1 right-parenthesis minus g. Then the empirical percentile ModifyingAbove pi With caret Subscript p is defined as

ModifyingAbove pi With caret Subscript p Baseline equals left-parenthesis 1 minus h right-parenthesis x left-bracket g right-bracket plus h x left-bracket g plus 1 right-bracket

This method does not work if p less-than 1 slash left-parenthesis n plus 1 right-parenthesis or p greater-than n slash left-parenthesis n plus 1 right-parenthesis. If p less-than 1 slash left-parenthesis n plus 1 right-parenthesis, then the function returns ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket 1 right-bracket slash 2, which assumes that the EDF is 0 in the interval left-bracket 0 comma x left-bracket 1 right-bracket right-parenthesis. If p greater-than n slash left-parenthesis n plus 1 right-parenthesis, then ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket n right-bracket.

Ftype = 2

If p less-than upper F left-bracket 1 right-bracket, then ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket 1 right-bracket slash 2, which assumes that the EDF is 0 in the interval left-bracket 0 comma x left-bracket 1 right-bracket right-parenthesis. If StartAbsoluteValue p minus upper F left-bracket i right-bracket EndAbsoluteValue less-than epsilon for some value of i and i less-than n, then ModifyingAbove pi With caret Subscript p is computed as

ModifyingAbove pi With caret Subscript p Baseline equals StartFraction x left-bracket i right-bracket plus x left-bracket i plus 1 right-bracket Over 2 EndFraction

where epsilon is a machine-precision constant as returned by the SAS function CONSTANT('MACEPS'). If upper F left-bracket i minus 1 right-bracket less-than p less-than upper F left-bracket i right-bracket, then ModifyingAbove pi With caret Subscript p is computed as

ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket i right-bracket

If p greater-than-or-equal-to upper F left-bracket n right-bracket , then ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket n right-bracket.

Ftype = 3

If p less-than upper F left-bracket 1 right-bracket, then ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket 1 right-bracket slash 2, which assumes that the EDF is 0 in the interval left-bracket 0 comma x left-bracket 1 right-bracket right-parenthesis. If StartAbsoluteValue p minus upper F left-bracket i right-bracket EndAbsoluteValue less-than epsilon for some value of i and i less-than n, then ModifyingAbove pi With caret Subscript p is computed as

ModifyingAbove pi With caret Subscript p Baseline equals StartFraction x left-bracket i right-bracket plus x left-bracket i plus 1 right-bracket Over 2 EndFraction

where epsilon is a machine-precision constant as returned by the SAS function CONSTANT(’MACEPS’). If upper F left-bracket i minus 1 right-bracket less-than p less-than upper F left-bracket i right-bracket, then ModifyingAbove pi With caret Subscript p is computed as

ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket i minus 1 right-bracket plus left-parenthesis p minus upper F left-bracket i minus 1 right-bracket right-parenthesis StartFraction x left-bracket i right-bracket minus x left-bracket i minus 1 right-bracket Over upper F left-bracket i right-bracket minus upper F left-bracket i minus 1 right-bracket EndFraction

If p greater-than-or-equal-to upper F left-bracket n right-bracket , then ModifyingAbove pi With caret Subscript p Baseline equals x left-bracket n right-bracket.

SVRTUTIL_RAWMOMENTS


This subroutine computes the raw moments of a sample.

  • Type: Subroutine

  • Signature: SVRTUTIL_RAWMOMENTS(n, x{*}, nx{*}, nRaw, raw{*})

  • Argument description:

    n

    Dimension of the x and nx input arrays

    x{*}

    Input numeric array of dimension n that contains distinct values of the random variable that are observed in the sample

    nx{*}

    Input numeric array of dimension n in which each nx[i] contains the number of observations in the sample that have the value x[i]

    nRaw

    Desired number of raw moments. The output array raw contains the first nRaw raw moments.

    raw{*}

    Output array of raw moments. The kth element in the array (raw{k}) contains the kth raw moment, where 1 less-than-or-equal-to k less-than-or-equal-to nRaw.

  • Return value: Numeric array raw that contains the first nRaw raw moments. The array contains missing values if the sample has no observations (that is, if all the values in the nx array add up to zero).

SVRTUTIL_SORT


This function sorts the given array of numeric values in an ascending or descending order.

  • Type: Subroutine

  • Signature: SVRTUTIL_SORT(n, x{*}, flag)

  • Argument description:

    n

    Dimension of the input array x

    x{*}

    Numeric array that contains the values to be sorted at input. The subroutine uses the same array to return the sorted values.

    flag

    A numeric value that controls the sort order. If flag is 0, then the values are sorted in an ascending order. If flag has any value other than 0, then the values are sorted in descending order.

  • Return value: Numeric array x, which is sorted in place (that is, the sorted array is stored in the same storage area occupied by the input array x)

You can use the following predefined functions when you use the FCMP procedure to define functions and subroutines. They are summarized here for your information. For more information, see the FCMP procedure documentation in Base SAS Procedures Guide.

INVCDF


This function computes the quantile from any continuous probability distribution by numerically inverting the CDF of that distribution. You need to specify the CDF function of the distribution, the values of its parameters, and the cumulative probability to compute the quantile.

LIMMOMENT


This function computes the limited moment of order k with upper limit u for any continuous probability distribution. The limited moment is defined as

StartLayout 1st Row 1st Column upper E left-bracket left-parenthesis upper X logical-and u right-parenthesis Superscript k Baseline right-bracket 2nd Column equals integral Subscript 0 Superscript u Baseline x Superscript k Baseline f left-parenthesis x right-parenthesis d x plus integral Subscript u Superscript normal infinity Baseline u Superscript k Baseline f left-parenthesis x right-parenthesis d x 2nd Row 1st Column Blank 2nd Column equals integral Subscript 0 Superscript u Baseline x Superscript k Baseline f left-parenthesis x right-parenthesis d x plus u Superscript k Baseline left-parenthesis 1 minus upper F left-parenthesis u right-parenthesis right-parenthesis EndLayout

where f left-parenthesis x right-parenthesis and upper F left-parenthesis x right-parenthesis denote the PDF and the CDF of the distribution, respectively. The LIMMOMENT function uses the following alternate definition, which can be derived using integration-by-parts:

upper E left-bracket left-parenthesis upper X logical-and u right-parenthesis Superscript k Baseline right-bracket equals k integral Subscript 0 Superscript u Baseline left-parenthesis 1 minus upper F left-parenthesis x right-parenthesis right-parenthesis x Superscript k minus 1 Baseline d x

You need to specify the CDF function of the distribution, the values of its parameters, and the values of k and u to compute the limited moment.

Last updated: June 19, 2025