Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_univar_estim_genpareto (g07bf)

## Purpose

nag_univar_estim_genpareto (g07bf) estimates parameter values for the generalized Pareto distribution by using either moments or maximum likelihood.

## Syntax

[xi, beta, asvc, obsvc, ll, ifail] = g07bf(y, optopt, 'n', n)
[xi, beta, asvc, obsvc, ll, ifail] = nag_univar_estim_genpareto(y, optopt, 'n', n)

## Description

Let the distribution function of a set of $n$ observations
 $yi , i=1,2,…,n$
be given by the generalized Pareto distribution:
 $Fy = 1- 1+ ξy β -1/ξ , ξ≠0 1-e-yβ , ξ=0;$
where
• $\beta >0$ and
• $y\ge 0$, when $\xi \ge 0$;
• $0\le y\le -\frac{\beta }{\xi }$, when $\xi <0$.
Estimates $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ of the parameters $\xi$ and $\beta$ are calculated by using one of:
• method of moments (MOM);
• probability-weighted moments (PWM);
• maximum likelihood estimates (MLE) that seek to maximize the log-likelihood:
 $L = -n ln⁡ β^ - 1+ 1ξ^ ∑ i=1 n ln 1+ ξ^yi β^ .$
The variances and covariance of the asymptotic Normal distribution of parameter estimates $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ are returned if $\stackrel{^}{\xi }$ satisfies:
• $\stackrel{^}{\xi }<\frac{1}{4}$ for the MOM;
• $\stackrel{^}{\xi }<\frac{1}{2}$ for the PWM method;
• $\stackrel{^}{\xi }<-\frac{1}{2}$ for the MLE method.
If the MLE option is exercised, the observed variances and covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$ is returned, given by the negative inverse Hessian of $L$.

## References

Hosking J R M and Wallis J R (1987) Parameter and quantile estimation for the generalized Pareto distribution Technometrics 29(3)
McNeil A J, Frey R and Embrechts P (2005) Quantitative Risk Management Princeton University Press

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
The $n$ observations ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$, assumed to follow a generalized Pareto distribution.
Constraints:
• ${\mathbf{y}}\left(i\right)\ge 0.0$;
• $\sum _{\mathit{i}=1}^{n}{\mathbf{y}}\left(i\right)>0.0$.
2:     $\mathrm{optopt}$int64int32nag_int scalar
Determines the method of estimation, set:
${\mathbf{optopt}}=-2$
For the method of probability-weighted moments.
${\mathbf{optopt}}=-1$
For the method of moments.
${\mathbf{optopt}}=1$
For maximum likelihood with starting values given by the method of moments estimates.
${\mathbf{optopt}}=2$
For maximum likelihood with starting values given by the method of probability-weighted moments.
Constraint: ${\mathbf{optopt}}=-2$, $-1$, $1$ or $2$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the array y.
The number of observations.
Constraint: ${\mathbf{n}}>1$.

### Output Parameters

1:     $\mathrm{xi}$ – double scalar
The parameter estimate $\stackrel{^}{\xi }$.
2:     $\mathrm{beta}$ – double scalar
The parameter estimate $\stackrel{^}{\beta }$.
3:     $\mathrm{asvc}\left(4\right)$ – double array
The variance-covariance of the asymptotic Normal distribution of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{asvc}}\left(1\right)$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{asvc}}\left(4\right)$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{asvc}}\left(2\right)$ and ${\mathbf{asvc}}\left(3\right)$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
4:     $\mathrm{obsvc}\left(4\right)$ – double array
If maximum likelihood estimates are requested, the observed variance-covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$. ${\mathbf{obsvc}}\left(1\right)$ contains the variance of $\stackrel{^}{\xi }$; ${\mathbf{obsvc}}\left(4\right)$ contains the variance of $\stackrel{^}{\beta }$; ${\mathbf{obsvc}}\left(2\right)$ and ${\mathbf{obsvc}}\left(3\right)$ contain the covariance of $\stackrel{^}{\xi }$ and $\stackrel{^}{\beta }$.
5:     $\mathrm{ll}$ – double scalar
If maximum likelihood estimates are requested, ll contains the log-likelihood value $L$ at the end of the optimization; otherwise ll is set to $-1.0$.
6:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
Constraint: ${\mathbf{n}}>1$.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{y}}\left(i\right)\ge 0.0$ for all $i$.
${\mathbf{ifail}}=3$
Constraint: ${\mathbf{optopt}}=-2$, $-1$, $1$ or $2$.
W  ${\mathbf{ifail}}=6$
The asymptotic distribution is not available for the returned parameter estimates.
W  ${\mathbf{ifail}}=7$
The distribution of maximum likelihood estimates cannot be calculated for the returned parameter estimates because the Hessian matrix could not be inverted.
W  ${\mathbf{ifail}}=8$
The asymptotic distribution of parameter estimates is invalid and the distribution of maximum likelihood estimates cannot be calculated for the returned parameter estimates because the Hessian matrix could not be inverted.
${\mathbf{ifail}}=9$
The optimization of log-likelihood failed to converge; no maximum likelihood estimates are returned. Try using the other maximum likelihood option by resetting optopt. If this also fails, moments-based estimates can be returned by an appropriate setting of optopt.
${\mathbf{ifail}}=10$
Variance of data in y is too low for method of moments optimization.
${\mathbf{ifail}}=11$
The sum of y is zero within machine precision.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The search for maximum likelihood parameter estimates is further restricted by requiring
 $1+ ξ^yi β^ > 0 ,$
as this avoids the possibility of making the log-likelihood $L$ arbitrarily high.

## Example

This example calculates parameter estimates for $23$ observations assumed to be drawn from a generalized Pareto distribution.
```function g07bf_example

fprintf('g07bf example results\n\n');

optopt = int64(2);

% Catch warnings for ifail=6,7,8
warn_state = nag_issue_warnings();
nag_issue_warnings(true);
wstat = warning();
warning('OFF');

y = [1.5800;  0.1390; 2.3624; 2.9435; 0.1363; 0.9688; 0.6585; 2.8011; ...
0.9880;  1.7887; 0.0630; 0.3862; 1.5130; 0.0669; 1.3659; 0.4256; ...
0.3485; 27.8760; 5.2503; 1.1028; 0.5273; 1.3189; 0.6490];

% Calculate the GPD parameter estimates
[xi, beta, asvc, obsvc, ll, ifail] = ...
g07bf(y, optopt);

if ifail == 0 || (ifail > 5 && ifail < 9)
% Display parameter estimates
fprintf('xi             %14.6f\n', xi);
fprintf('beta           %14.6f\n\n', beta);

% Display Parameter Distributions
if optopt > 0
if (ifail == 7 || ifail == 8)
fprintf('Invalid observed distribution\n');
else
fprintf('Observed distribution\n');
fprintf('Var(xi)               %14.6f\n', obsvc(1));
fprintf('Var(beta)             %14.6f\n', obsvc(4));
fprintf('Covar(xi,beta)        %14.6f\n', obsvc(2));
fprintf('Final log-likelihood: %14.6f\n\n', ll);
end
else
if (ifail == 6 || ifail == 7)
fprintf('Invalid asymptotic distribution\n');
else
fprintf('Asymptotic distribution\n');
fprintf('Var(xi)        %14.6f\n', asvc(1));
fprintf('Var(beta)      %14.6f\n', asvc(4));
fprintf('Covar(xi,beta) %14.6f\n', asvc(2));
end
end
end

warning(wstat);

nag_issue_warnings(warn_state);

```
```g07bf example results

xi                   0.540439
beta                 1.040549

Observed distribution
Var(xi)                     0.079932
Var(beta)                   0.119872
Covar(xi,beta)             -0.045509
Final log-likelihood:     -36.344327

```