Title: | Goodness of Fit Test for Continuous Distribution Functions |
---|---|
Description: | Computes the test statistic and p-value of the Cramer-von Mises and Anderson-Darling test for some continuous distribution functions proposed by Chen and Balakrishnan (1995) <http://asq.org/qic/display-item/index.html?item=11407>. In addition to our classic distribution functions here, we calculate the Goodness of Fit (GoF) test to dataset which follows the extreme value distribution function, without remembering the formula of distribution/density functions. Calculates the Value at Risk (VaR) and Average VaR are another important risk factors which are estimated by using well-known distribution functions. Pflug and Romisch (2007, ISBN: 9812707409) is a good reference to study the properties of risk measures. |
Authors: | Ali Saeb |
Maintainer: | Ali Saeb <[email protected]> |
License: | GPL |
Version: | 0.2.0 |
Built: | 2024-10-13 03:17:12 UTC |
Source: | https://github.com/cran/gnFit |
Computes the test statistic and p-value of the Cramer-von Mises and Anderson-Darling test for some continuous distribution functions proposed by Chen and Balakrishnan (1995). In addition to our classic distribution functions here, we calculate the Goodness of Fit (GoF) test to dataset which follows the extreme value distribution function, without remembering the formula of distribution/density functions.
gnfit(dat, dist, df = NULL, pr = NULL, threshold = NULL)
gnfit(dat, dist, df = NULL, pr = NULL, threshold = NULL)
dat |
A numeric vector of data values. |
dist |
A named distribution function in R, such as "norm", "t", "laplace", "logis", "gev", "gum", "gpd". |
df |
Degrees of freedom (> 2) for Student-t's distribution. This value is set to NULL by default. |
pr |
An object returned by maximum likelihood estimation of gev.fit, gum.fit or gpd.fit. It is also numeric vector giving the maximum likelihood estimation for the nonstationary model with location, scale and shape parameters for "gev" (generalized extreme value distribution), location and scale parameters in gumbel distribution or scale and shape parameters in case of "gpd" (generalized pareto distribution), resp. |
threshold |
The threshold is a single number. It is allocated by "gpd" with shape and scale parameters. |
To test is a random sample from a continuous distribution with cumulative distribution function
, where the form of
is known but
is unknown. We first esitmate
by
(for eg. maximum likelihood estimation method). Next, we compute
, where the
's are in ascending order.
The Cramer-von Mises test statistic is
and
where, ,
, and
is the standard normal CDF and
its inverse.
Modify and
into
and
The p-value is computed from the modified statistic and
according to Table 4.9 in Stephens (1986).
The output is an object of the class "htest" for the Cramer-von Mises and Anderson-Darling statistics corresponding to p-values.
Stephens (1986, ISBN:0824774876)
Chen and Balakrishnan (1995) <http://asq.org/qic/display-item/index.html?item=11407>
Marsaglia (2004) <doi:10.18637/jss.v009.i02>
The package of nortest for performing the Anderson-Darling test for normality. ADGofTest implementation of the Anderson-Darling goodness of fit test based on Marsaglia's (2004).
library(rmutil) r <- rlaplace(1000, m = 1, s = 2) gnfit(r, "laplace") library(ismev) pr <- c(-0.5, 1, 0.2) r <- gevq(pr, runif(1000, 0, 1)) model <- gev.fit(r)$mle gnfit(r, "gev", pr = model) library(ismev) r <- gum.q(runif(1000, 0, 1), -0.5, 1) n <- length(r) time <- matrix(1:n, ncol=1) model <- gum.fit(r, ydat=time, mul=1)$mle mle<-dim(2) mle[1] <- model[1] + model[2] * (n+1) mle[2] <- model[3] gnfit(r, "gum", pr = mle)
library(rmutil) r <- rlaplace(1000, m = 1, s = 2) gnfit(r, "laplace") library(ismev) pr <- c(-0.5, 1, 0.2) r <- gevq(pr, runif(1000, 0, 1)) model <- gev.fit(r)$mle gnfit(r, "gev", pr = model) library(ismev) r <- gum.q(runif(1000, 0, 1), -0.5, 1) n <- length(r) time <- matrix(1:n, ncol=1) model <- gum.fit(r, ydat=time, mul=1)$mle mle<-dim(2) mle[1] <- model[1] + model[2] * (n+1) mle[2] <- model[3] gnfit(r, "gum", pr = mle)
The Value at Risk (VaR) of level (
-quantile) of an event is a number attempting to summarize the risk of that event and define the worst expected loss of the event over a period of time. The Average VaR is another important measure of the risk at a given confidence level, which calculated by using the function of "rskFac".
rskFac(dat, alpha = 0.1, dist = "norm", df = NULL)
rskFac(dat, alpha = 0.1, dist = "norm", df = NULL)
dat |
A numeric vector of object data. |
alpha |
Confidence level |
dist |
A named of distribution function which should be fitted to data values. The distibution function is selected by the name of "laplace", "logis", "gum", "t" and "norm". |
df |
degrees of freedom from a specified distribution function. |
Suppose is random variable (rv) has distribution function (df)
. Given a confidence level
Value at Risk (VaR) of the underlying
at the confidence level
is the smallest number
such that the probability that the underlying
exceeds
is at least
In other word, if
is a rv with symmetric distribution function
(e.g., the return value of a portfolio), then
is the negative of the
quantile, i.e.,
where,
Since, the is the nagative of
quantile in the left tail,
is positive value of VaR in right tail.
The average
for
of
is defined as
The AVaR is known under the names of conditional VaR (CVaR), tail VaR (TVaR) and expected shortfall.
Pflug and Romisch (2007, ISBN: 9812707409) shows the AVaR may be represented as the optimal value of the following optimization problem
where, .
To approximate the integral, it is given by
where, is number of observations. By considering the rv
, the
in right tail is obtainable.
The values of output are "VaR", "AVaR_n" and "AVaR_p" correspond to the VaR, Average VaR in left tail, Average VaR in right tail.
Pflug and Romisch (2007, ISBN: 9812707409)
library(rmutil) r <- rlaplace(1000, m = 1, s = 2) rskFac(r, dist = "laplace", alpha = 0.1)
library(rmutil) r <- rlaplace(1000, m = 1, s = 2) rskFac(r, dist = "laplace", alpha = 0.1)