Package 'gnFit'

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

Help Index


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). 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.

Usage

gnfit(dat, dist, df = NULL, pr = NULL, threshold = NULL)

Arguments

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.

Details

To test H0:X1,,XnH_0: X_1,\ldots, X_n is a random sample from a continuous distribution with cumulative distribution function F(x;θ)F(x;\theta), where the form of FF is known but θ\theta is unknown. We first esitmate θ\theta by θ\theta^* (for eg. maximum likelihood estimation method). Next, we compute vi=F(xi,θ)v_i=F(x_i,\theta^*), where the xix_i's are in ascending order.

The Cramer-von Mises test statistic is

W2=i=1n(ui(2i1)2n)2+112n,W^2=\sum_{i=1}^{n}(u_i-\frac{(2i-1)}{2n})^2+\frac{1}{12n},

and

A2=n1ni=1n((2i1)log(ui)+(2n+12i)log(1ui));A^2=-n-\frac{1}{n}\sum_{i=1}^{n}((2i-1)\log(u_i)+(2n+1-2i)\log(1-u_i));

where, ui=Φ((yiyˉi)/sy)u_i=\Phi((y_i-\bar{y}_i)/s_y), yi=Φ1(vi)y_i=\Phi^{-1}(v_i), and Φ\Phi is the standard normal CDF and Φ1\Phi^{-1} its inverse.

Modify W2W^2 and A2A^2 into

W=W2(1+0.5/n),W^*=W^2(1+0.5/n),

and

A=A2(1+0.75/n+2.25/n2).A^*=A^2(1+0.75/n+2.25/n^2).

The p-value is computed from the modified statistic WW^* and AA^* according to Table 4.9 in Stephens (1986).

Value

The output is an object of the class "htest" for the Cramer-von Mises and Anderson-Darling statistics corresponding to p-values.

References

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>

See Also

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).

Examples

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)

Risk Factors

Description

The Value at Risk (VaR) of level α\alpha (α\alpha-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".

Usage

rskFac(dat, alpha = 0.1, dist = "norm", df = NULL)

Arguments

dat

A numeric vector of object data.

alpha

Confidence level α\alpha (0<α<0.50<\alpha<0.5).

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.

Details

Suppose XX is random variable (rv) has distribution function (df) FF. Given a confidence level α(0,1),\alpha\in (0, 1), Value at Risk (VaR) of the underlying XX at the confidence level α\alpha is the smallest number xx such that the probability that the underlying XX exceeds xx is at least 1α.1-\alpha. In other word, if XX is a rv with symmetric distribution function FF (e.g., the return value of a portfolio), then VaRαVaR_{\alpha} is the negative of the α\alpha quantile, i.e.,

VaRα(X)=Q(α)=infxReal:Pr(Xx)α.VaR_{\alpha}(X)=Q(\alpha)=inf{x \in Real : Pr( X \le x )\le \alpha}.

where, Q(.)=F1(.).Q(.)=F^{-1}(.).

Since, the VaRα(X)VaR_\alpha(X) is the nagative of α\alpha quantile in the left tail, VaR1α(X)-VaR_{1-\alpha}(-X) is positive value of VaR in right tail.

The average VaRα,VaR_\alpha, (AVaRα)(AVaR_\alpha) for 0<α10<\alpha\le 1 of XX is defined as

AVaRα(X)=1α0αVaR(x)dx,AVaR_\alpha(X)= \frac{1}{\alpha}\int_{0}^{\alpha}VaR(x) dx,

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

AVaRα(X)=VaRα(X)1αE((XVaRα(X))).AVaR_\alpha (X) = VaR_\alpha(X) - \frac{1}{\alpha} E((X - VaR_\alpha(X))^{-}).

where, (y)=min(y,0)(y)^{-} = min (y,0). To approximate the integral, it is given by

AVaRα(X)=VaRα(X)+1tαi=1tmax(VaRα(X)X),0,AVaR_\alpha(X)=VaR_\alpha(X)+\frac{1}{t \alpha}\sum_{i=1}^{t}max{(VaR_\alpha(X) - X), 0},

where, tt is number of observations. By considering the rv X-X, the AVaR1α-AVaR_{1-\alpha} in right tail is obtainable.

Value

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.

References

Pflug and Romisch (2007, ISBN: 9812707409)

Examples

library(rmutil)
r <- rlaplace(1000, m = 1, s = 2)
rskFac(r, dist = "laplace", alpha = 0.1)