Title: | Semi Parametric Distribution |
---|---|
Description: | The Semi Parametric Piecewise Distribution blends the Generalized Pareto Distribution for the tails with a kernel based interior. |
Authors: | Alexios Ghalanos <[email protected]> |
Maintainer: | Alexios Ghalanos <[email protected]> |
License: | GPL |
Version: | 2.0-1 |
Built: | 2025-01-16 04:07:30 UTC |
Source: | https://github.com/cran/spd |
The Semi-Parametric Distribution is a piecewise distribution constructed by parametrically modelling the tails of the distribution using an appropriate distribution (e.g. generalized pareto) and the interior by kernel methods. The package implements fit, distribution, density, quantile and random number generation. Currently, only the generalized pareto distribution is implemented for modelling the tails, but the package can easily be extended.
Package: | spd |
Type: | Package |
Version: | 2.0-0 |
Date: | 2013-12-15 |
License: | GPL |
LazyLoad: | yes |
Depends: | methods |
The main functionality of the package is contained in the SPD
class, created by calling spdfit
. Methods for density
dspd
, distribution pspd
, quantile qspd
and random number generation rspd
exist and take 2 main arguments,
the input value and the fitted object.
The spd package uses the "bkde"
function from the package KernSmooth for
the kernel interior fit, while for the tail fit borrows from the fExtremes
package and implements a locally modified copy of the gpd functionality and
methods.
Alec Stephenson for the functions from R\'s "evd-package"
,
Alec Stephenson for the functions from R\'s "evir-package"
,
Alexander McNeil for the EVIS functions underlying the "evir-package"
,
Diethelm Wuertz for the functions from R\'s "fExtremes-package"
,
M.P.Wand and M.C.Jones for the functions from R\'s "KernSmooth-package"
,
Alexios Ghalanos for this package.
Carmona, R. and J. Morrisson (2001). Heavy Tails and Copulas with Evanesce,
ORFE Tech. Report, Princeton University
Carmona, R. (2001). Statistical Analysis of Financial Data, with an
implementation in Splus
Embrechts, P., Klueppelberg, C., Mikosch, T. (1997); Modelling Extremal
Events, Springer
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) show(fit) ## End(Not run)
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) show(fit) ## End(Not run)
Locally implemented and slightly modified class for the generalized
pareto distribution (gpd) fit, borrowed from package fExtremes
. Created
on modelling the tails of the data by spdfit
Objects of this class cannot be created by user as the methods are not exported.
call
:Object of class "call"
method
:Object of class "character"
parameter
:Object of class "list"
data
:Object of class "list"
fit
:Object of class "list"
residuals
:Object of class "numeric"
title
:Object of class "character"
description
:Object of class "character"
S3 plot method exists which provides for visual inspection of the fit
and is called by the higher level S3 plot method of the SPD
class
Alec Stephenson for the functions from R\'s "evd-package"
,
Alec Stephenson for the functions from R\'s "evir-package"
,
Alexander McNeil for the EVIS functions underlying the "evir-package"
,
Diethelm Wuertz for the functions from R\'s "fExtremes-package"
,
M.P.Wand and M.C.Jones for the functions from R\'s "KernSmooth-package"
,
Alexios Ghalanos for this package.
Carmona, R. and J. Morrisson (2001). Heavy Tails and Copulas with Evanesce,
ORFE Tech. Report, Princeton University
Carmona, R. (2001). Statistical Analysis of Financial Data, with an
implementation in Splus
Embrechts, P., Klueppelberg, C., Mikosch, T. (1997); Modelling Extremal
Events, Springer
Class: SPD with Generalized Pareto Distribution (GPD) Tails
Objects can be created by calling spdfit
. The main implemented
class of the spd package holding the details of the fitted object with gpd tails.
call
:...
method
:the gpd fitting method
kernel
:the kernel type
data
:the original dataset
threshold
:the upper and lower thresholds fitted
ptails
:the upper and lower cutoff points.
fit
:the upper and lower gpd fit and the interior kernel fit objects.
title
:optional title of project
description
:optional description
Class SPD
, directly.
Alexios Ghalanos
Carmona, R. and J. Morrisson (2001). Heavy Tails and Copulas with
Evanesce, ORFE Tech. Report, Princeton University
Carmona, R. (2001). Statistical Analysis of Financial Data, with an
implementation in Splus
Locally implemented and modified methods for plotting the fit of the
GPDFIT
object (taken from package fExtremes
), and
the overall fit of the GPDTAILS
object.
plot(x,y,...)
plot(x,y,...)
x |
|
y |
missing |
... |
[which] - |
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) plot(fit,which=1) # this in fact exctracts the GPDFIT object (from GPDTAILS) for which plot # methods exist. plot(fit,which=3) ## End(Not run)
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) plot(fit,which=1) # this in fact exctracts the GPDFIT object (from GPDTAILS) for which plot # methods exist. plot(fit,which=3) ## End(Not run)
Virtual Class for holding the tail fit and kernel interior objects.
signature(x = "numeric", fit = "SPD", linear = "logical")
:
density function
signature(q = "numeric", fit = "SPD", linear = "logical")
:
distribution function
signature(p = "numeric", fit = "SPD", linear = "logical")
:
quantile function
signature(n = "numeric", fit = "SPD", linear = "logical")
:
random number generation function
signature(object = "SPD")
: show method
A virtual Class: No objects may be created from it.
Alexios Ghalanos
Carmona, R. and J. Morrisson (2001). Heavy Tails and Copulas with
Evanesce, ORFE Tech. Report, Princeton University
Carmona, R. (2001). Statistical Analysis of Financial Data, with an
implementation in Splus
showClass("SPD")
showClass("SPD")
Density, Distribution, Quantile and Random Number Generation methods for the Semi-Parametric Distribution.
dspd(x, fit, linear) pspd(q, fit, linear) qspd(p, fit, linear) rspd(n, fit, linear)
dspd(x, fit, linear) pspd(q, fit, linear) qspd(p, fit, linear) rspd(n, fit, linear)
n |
[rspd] - |
p |
a vector of probability levels, the desired probability for the quantile estimate (e.g. 0.99 for the 99th percentile). |
x , q
|
[pspd,dspd] - |
fit |
[all] - |
linear |
[all] - |
All values are numeric vectors: d*
returns the density (pdf), p*
returns the probability (cdf), q*
returns the quantiles (inverse cdf), and r*
generates random deviates.
The density is computed using the generalized pareto distribution in the tails, while for the middle, the density is computed by using a smooth gradient approach. Interpolation is used to splice together the ends with the middle portion, providing for an approximate piecewise constant density function. As such, caution should be used when interpreting results obtained by use of this function.
Alec Stephenson for the functions from R\'s evd
package,
Alec Stephenson for the functions from R\'s evir
package,
Alexander McNeil for the EVIS functions underlying the evir
package,
Diethelm Wuetrz for the fExtremes
Implementation of the gpd,
Alexios Ghalanos for the SPD Implementation,
Embrechts, P., Klueppelberg, C., Mikosch, T. (1997); Modelling Extremal
Events, Springer.
Carmona, R. (2004);Statistical Anlaysis of Financial Data in Splus,
Springer.
## Not run: library(MASS) x = SP500/100 fit=spdfit(x, upper=0.9, lower=0.1) ## rspd - par(mfrow = c(2, 2), cex = 0.7) r = rspd(n = 1000, fit) hist(r, n = 100, probability = TRUE, xlab = "r", col = "steelblue", border = "white",main = "Density") box() ## dspd - # Plot empirical density and compare with true density: r = rspd(n = 1000, fit) hist(r, n = 100, probability = TRUE, xlab = "r", col = "steelblue", border = "white",main = "Density") box() x = seq(-0.3, 0.3, length.out = 1000) lines(x, dspd(x, fit), col = "darkorange",lwd=2) ## pspd - # Plot df and compare with true df: plot(sort(r), (1:length(r)/length(r)), ylim = c(0, 1), pch = 19, cex = 0.5, ylab = "p", xlab = "q", main = "CDF") grid() q = seq(-0.3, 0.3, length.out = 1000) lines(q, pspd(q, fit), col = "darkorange",lwd=2) ## End(Not run)
## Not run: library(MASS) x = SP500/100 fit=spdfit(x, upper=0.9, lower=0.1) ## rspd - par(mfrow = c(2, 2), cex = 0.7) r = rspd(n = 1000, fit) hist(r, n = 100, probability = TRUE, xlab = "r", col = "steelblue", border = "white",main = "Density") box() ## dspd - # Plot empirical density and compare with true density: r = rspd(n = 1000, fit) hist(r, n = 100, probability = TRUE, xlab = "r", col = "steelblue", border = "white",main = "Density") box() x = seq(-0.3, 0.3, length.out = 1000) lines(x, dspd(x, fit), col = "darkorange",lwd=2) ## pspd - # Plot df and compare with true df: plot(sort(r), (1:length(r)/length(r)), ylim = c(0, 1), pch = 19, cex = 0.5, ylab = "p", xlab = "q", main = "CDF") grid() q = seq(-0.3, 0.3, length.out = 1000) lines(q, pspd(q, fit), col = "darkorange",lwd=2) ## End(Not run)
The semi-parametric distribution fitting method.
spdfit(data, upper = 0.9, lower = 0.1, tailfit="GPD", type = c("mle", "pwm"), kernelfit = c("normal", "box", "epanech", "biweight", "triweight"), information = c("observed", "expected"), title = NULL, description = NULL, ...)
spdfit(data, upper = 0.9, lower = 0.1, tailfit="GPD", type = c("mle", "pwm"), kernelfit = c("normal", "box", "epanech", "biweight", "triweight"), information = c("observed", "expected"), title = NULL, description = NULL, ...)
data |
An object coercible to a |
upper |
Upper tail cutoff for fitting the generalized pareto or other distribution. |
lower |
Lower tail cutoff for fitting the generalized pareto or other distribution. |
tailfit |
Distribution to Use for fitting the tails. |
type |
A character string selecting the desired estimation method, either "mle" for the maximum likelihood method or "pwm" for the probability weighted moment method. By default, the first will be selected. |
kernelfit |
Type of kernel to fit to the interior of the distribution. |
information |
Whether tail distribution standard errors should be calculated with "observed" or "expected" information. This only applies to the maximum likelihood method; for the probability-weighted moments method "expected" information is used if possible. |
title |
A character string which allows for a project title. |
description |
A character string which allows for a brief description. |
... |
Control parameters and plot parameters optionally passed to the optimization and/or plot function. Parameters for the optimization function are passed to components of the control argument of optim. |
Returns an object of class SPD
.
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) show(fit) #plot(fit,which="all") ## End(Not run)
## Not run: library(MASS) x<-SP500/100 fit<-spdfit(x) show(fit) #plot(fit,which="all") ## End(Not run)