Description Usage Arguments Details Value References See Also Examples

Performs Monte-Carlo based Goodness-of-Fit tests. `mctest`

is called by the GoF tests
defined in this package. For internal use only.

1 | ```
mctest(x, distn, parm, H, sim, tol, STATISTIC, estfun)
``` |

`x` |
numerical vector of data values |

`distn` |
character string specifying the null distribution |

`parm` |
parameters of the null distribution |

`H` |
a treshold value |

`sim` |
maximum number of szenarios within the Monte-Carlo-Simulation |

`tol` |
if the difference of two subsequent p-value calculations is lower than |

`STATISTIC` |
function of the test statistic |

`estfun` |
an function as character string or |

From the fitted null distribution `mctest`

draws samples each with length
of the observed sample `x`

and with treshold `H`

. The random numbers are
taken from the conditional distribution with support *[H, +Inf)*. The maximum
number of samples is specified by `sim`

. For
each of these samples the conditional distribution is fitted and the statistic given in
`STATISTIC`

is calculated. The p-value is the proportion of times the sample statistics
values exceed the statistic value of the observed sample.

For each szenario sample `mctest`

uses a Maximum-likelihood fitting of the
distribution `distn`

as default. This is done by direct optimization of the log-likelihood
function using `optim`

.

Alternativly the fitting parameters for the szenario samples might be estimated with a user-specified
function assigned in `estfun`

. It must be a function with argument `x`

(and `H`

if desired) which can be parsed. The return value of the evaluated function
must be a list with the parameters which should be fitted. Inside `mctest`

the evaluation of
`estfun`

is performed with `H`

as assigned in the call of `mctest`

and `x`

the
szenario sample.

By assigning a function to `estfun`

, the fitting procedure can be done faster and more
appropriate to a given problem. The 'evir' package for example defines a function `gpd`

to fit the
Generalized Pareto Model. To start a test it is more reasonable to set `estfun = gpd(x, y)`

,
where `y`

must be a defined numeric value.

named list of

`TS` |
value of the test statistic for |

`p.value` |
Monte-Carlo simulation based p-value of the statistic |

`sim` |
number of simulated szenarios in the Monte-Carlo simulation |

Chernobay, A., Rachev, S., Fabozzi, F. (2005), *Composites goodness-of-fit tests
for left-truncated loss samples*, Tech. rep., University of Calivornia Santa Barbara

Ross, S. M. (2002), *Simulation*, 3rd Edition, Academic Press. Pages 205-208.

`ad2.test`

, `ad2up.test`

, `w2.test`

for quadratic class GoF tests and `ks.test`

, `v.test`

,
`adup.test`

, `ad.test`

for supremum class GoF tests.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ```
set.seed(123)
treshold <- 10
xc <- rgamma(100, 20, 2) # complete sample
xt <- xc[xc > treshold] # left truncated sample
## function for parameter fitting
estimate <- function(x, H){
cgamma <- cdens("pgamma", H)
ll <- function(p, y) {
res <- -sum(do.call("cgamma", list(c(y), p[1], p[2], log = TRUE)))
if (!is.finite(res)) return(-log(.Machine$double.xmin)*length(x))
return(res)
}
est <- optim(c(1,1), ll, y = x, lower = c(.Machine$double.eps, 0),
method = "L-BFGS-B")
as.list(est$par)
}
fit <- estimate(xt, treshold)
cat("fitting parameters:", unlist(fit), "\n")
## calculate p-value with fitting algorithm defined in 'mctest' ...
ad2up.test(xt, "pgamma", fit, H = treshold, estfun = NA, tol = 1e-02)
## ... or with the function 'estimate'
ad2up.test(xt, "pgamma", fit, H = treshold, estfun = "estimate(x, H)",
tol = 1e-02)
## not run:
## if the 'evir' package is loaded:
## ad.test(xt, "pgpd", list(2,3), H = treshold,
## estfun = "as.list(gpd(x, 0)$par.ests)", tol = 1e-02)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.