# Kernel density estimation in R

## Catalina Bolancé & Montserrat Guillén

This page presents an introduction to kernel density estimation using data from the book Quantitative Operational Risk Models.   A methodological overview can be found in:

### DATA DESCRIPTION

 Name Content of operational risk loss data Internal data set 75 observed loss amounts External data set 700 observed loss amounts Public data risk no. 1 1000 observed loss amounts for category no. 1 Public data risk no. 2 400 observed loss amounts for category no. 2

#### DESCRIPTIVE STATISTICS

 Internal data External data Public data risk no. 1 Public data risk no. 2 N 75 700 1000 400 Mean 0.1756 0.6788 42.0594 20.8933 Std Deviation 0.2777 4.0937 291.9634 95.9138 Min 0.0030 0.0010 0.0020 0.0030 Max 1.7730 52.1300 5122.1360 1027.5270

##### KERNEL DENSITY ESTIMATION

- Classical kernel density estimation

For a random sample of n independent and identically distributed observations x1, x2,..., xn of a random variable X with pdf fX, the kernel density estimator is
$$\hat{f}_X\left( x\right) =\frac{1}{n}\sum_{i=1}^{n}K_{b}\left(x-x_{i}\right), \label{Kerdens1}$$
where
$$K_b(\cdot )=\frac{1}{b}K(\cdot /b)$$
K is the kernel function and b is the bandwidth.

- Transformations and kernel density estimation

Classical kernel density estimation does not generally perform well when the true density is asymmetric. For instance, when one is interested in the density of the claim cost variable, the presence of many small claims produces a concentration of mass near the low values of the domain and the presence of some very large claims causes positive skewness.

The lack of information in the right tail of the domain makes it difficult to obtain a reliable nonparametric estimate of the density in that area. Many authors have worked with heavy-tailed distributions and have adapted kernel estimation methods to this context. Different papers have proposed different transformed kernel estimation (TKE) methods for a pdf, based on parametric families (see Wand et al. (1991), Clements et al. (2003), Buch-Larsen et al. (2005), Bolancé (2010), Bolancé et al. (2003), (2008) and (2009)). Here we implement the shifted power transformation family as in Bolancé et al. (2003).

- Selecting the transformation parameters and the bandwidth

We select λ=(λ12) and transform the original sample yi = (x + λ1)λ2 sign(λ2) if (λ2 ≠0) and yi = ln(x + λ1) if 2 =0), i = 1,...,n.
As in Bolancé et al. (2003), we restrict the set of transformation parameters, λ=(λ12), to those values that give approximately zero skewness for the transformed data (y1,..,yn) (which have also been scaled to have the same variance as the original sample, see Wand et al. (1991)).

We define our sample measure of skewness as: $$\widehat{\gamma }_{y}=\frac{n^{-1}\sum\limits_{i=1}^{n}(y_{i}-\overline{y})^{3}}{\left\{ n^{-1}\sum\limits_{i=1}^{n}(y_{i}-\overline{y} )^{2}\right\} ^{\frac{3}{2}}}$$
where y̅ is the sample mean of the transformed observations.

###### MEASURING THE GOODNESS OF FIT

We are interested in evaluating the quality of our density estimates obtained using both parametric and non-parametric methods over the whole domain. Let us begin with the log-likelihood function. This function is not appropriate for evaluating the performance of non-parametric density estimates. The log-likelihood depends on the values of the density exclusively at sample points. In kernel estimation the density shows bumps around isolated sample observations.

The parametric estimates of the normal and the lognormal densities have been obtained using maximum likelihood estimation. We can compare the difference between the value of log-likelihood under several estimation alternatives, i.e. for any given pdf estimate, we can compute the sum of the logarithm of the estimated density at the sample points. This will provide with a straightforward measure of comparative goodness of fit. Additionaly an estimated integrated square error (ISE) and an estimated weighted integrated square error (WISE) are presented.

###### REFERENCES

[1] Bolancé, C. (2010) Optimal Inverse Beta(3,3) Transformation in kernel density estimation, SORT Statistics and Operations Research Transaction, 34, 223-238.

[2] Bolancé, C., Guillén, M., Gustafsson J. and Nielsen, J.P. (2012) Quantitative Operational Risk Models Chapman & Hall/CRC.

[3] Bolancé, C., Guillén, M. and Nielsen, J.P. (2009) Transformation kernel estimation of insurance claim cost distribution, in Corazza, M. and Pizzi, C. (Eds), Mathematical and Statistical Methods for Actuarial Sciences and Finance, Springer, Roma, 223-231.

[4] Bolancé, C., Guillén, M. and Nielsen, J.P. (2008) Inverse Beta transformation in kernel density estimation. Statistics & Probability Letters, 78, 1757-1764.

[5] Bolancé, C., Guillén, M. and Nielsen, J.P. (2003) Kernel density estimation of actuarial loss functions, Insurance: Mathematics and Economics, 32, 19-36.

[6] Bolancé, C., Guillén, M. and Pitt, D. (2014) Non-parametric models for univariate claim severity distributions - an approach using R, UB Riskcenter Working Papers Series 2014-01.

[7] Buch-Larsen, T., Guillen, M., Nielsen, J.P. and Bolancé, C. (2005) Kernel density estimation for heavy-tailed distributions using the Champernowne transformation. Statistics, 39, 503-518.

[8] Clements, A.E., Hurn, A.S. and Lindsay, K.A. (2003) Möebius-like mappings and their use in kernel density estimation, Journal of the American Statistical Association, 98, 993-1000.

• Universitat de Barcelona - Last Updated: 05-23-2014