gofCustomTest: Function to derive own tests

Description Usage Arguments Details Value Examples

View source: R/tests_CustomTest.R

Description

gofCustomTest allows to include own Goodness-of-Fit tests and perform the test with the package. The margins can be estimated by a bunch of distributions and the time which is necessary for the estimation can be given. The approximate p-values are computed with a parametric bootstrap, which computation can be accelerated by enabling in-build parallel computation. It is possible to insert datasets of all dimensions above 1 and the possible copulae are "normal", "t", "clayton", "gumbel", "frank", "joe", "amh", "galambos", "huslerReiss", "tawn", "tev", "fgm" and "plackett". The parameter estimation is performed with pseudo maximum likelihood method. In case the estimation fails, inversion of Kendall's tau is used.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
gofCustomTest(
  copula = c("normal", "t", "clayton", "gumbel", "frank", "joe", "amh", "galambos",
    "huslerReiss", "tawn", "tev", "fgm", "plackett"),
  x,
  customTest = NULL,
  param = 0.5,
  param.est = TRUE,
  df = 4,
  df.est = TRUE,
  margins = "ranks",
  flip = 0,
  M = 1000,
  dispstr = "ex",
  lower = NULL,
  upper = NULL,
  seed.active = NULL,
  processes = 1
)

Arguments

copula

The copula to test for. Possible are "normal", "t", "clayton", "gumbel", "frank", "joe", "amh", "galambos", "huslerReiss", "tawn", "tev", "fgm" and "plackett".

x

A matrix containing the data with rows being observations and columns being variables.

customTest

A character string with the name of the customized test. The test has to be loaded into the workspace. Currently the function containing the test has to have 2 arguments, the first one for the dataset and the second one for the copula to test for. The arguments have to be named "x" and "copula" respectively.

param

The copula parameter to use, if it shall not be estimated.

param.est

Shall be either TRUE or FALSE. TRUE means that param will be estimated.

df

Degrees of freedom, if not meant to be estimated. Only necessary if tested for "t"-copula.

df.est

Indicates if df shall be estimated. Has to be either FALSE or TRUE, where TRUE means that it will be estimated.

margins

Specifies which estimation method for the margins shall be used. The default is "ranks", which is the standard approach to convert data in such a case. Alternatively the following distributions can be specified: "beta", "cauchy", Chi-squared ("chisq"), "f", "gamma", Log normal ("lnorm"), Normal ("norm"), "t", "weibull", Exponential ("exp"). Input can be either one method, e.g. "ranks", which will be used for estimation of all data sequences. Also an individual method for each margin can be specified, e.g. c("ranks", "norm", "t") for 3 data sequences. If one does not want to estimate the margins, set it to NULL.

flip

The control parameter to flip the copula by 90, 180, 270 degrees clockwise. Only applicable for bivariate copula. Default is 0 and possible inputs are 0, 90, 180, 270 and NULL.

M

Number of bootstrapping loops.

dispstr

A character string specifying the type of the symmetric positive definite matrix characterizing the elliptical copula. Implemented structures are "ex" for exchangeable and "un" for unstructured, see package copula.

lower

Lower bound for the maximum likelihood estimation of the copula parameter. The constraint is also active in the bootstrapping procedure. The constraint is not active when a switch to inversion of Kendall's tau is necessary. Default NULL.

upper

Upper bound for the maximum likelihood estimation of the copula parameter. The constraint is also active in the bootstrapping procedure. The constraint is not active when a switch to inversion of Kendall's tau is necessary. Default NULL.

seed.active

Has to be either an integer or a vector of M+1 integers. If an integer, then the seeds for the bootstrapping procedure will be simulated. If M+1 seeds are provided, then these seeds are used in the bootstrapping procedure. Defaults to NULL, then R generates the seeds from the computer runtime. Controlling the seeds is useful for reproducibility of a simulation study to compare the power of the tests or for reproducibility of an empirical study.

processes

The number of parallel processes which are performed to speed up the bootstrapping. Shouldn't be higher than the number of logical processors. Please see the details.

Details

The approximate p-value is computed by the formula, see copula,

sum(|T[b]| >= |T|, b=1, .., M) / M,

where T and T[b] denote the test statistic and the bootstrapped test statistc, respectively.

For small values of M, initializing the parallelisation via processes does not make sense. The registration of the parallel processes increases the computation time. Please consider to enable parallelisation just for high values of M.

Value

An object of the class gofCOP with the components

method

a character which informs about the performed analysis

copula

the copula tested for

margins

the method used to estimate the margin distribution.

param.margins

the parameters of the estimated margin distributions. Only applicable if the margins were not specified as "ranks" or NULL.

theta

dependence parameters of the copulae

df

the degrees of freedem of the copula. Only applicable for t-copula.

res.tests

a matrix with the p-values and test statistics of the hybrid and the individual tests

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# For illustration we load here the test statistic of the gofSn test
Testfunc = function(x, copula) {
            C.theo = pCopula(x, copula = copula)
            C.n = F.n(x, X = x)
            CnK = sum((C.n - C.theo)^2)
            return(CnK)
}

data(IndexReturns2D)

gofCustomTest(copula = "normal", x = IndexReturns2D, 
              customTest = "Testfunc", M=10)

gofCopula documentation built on April 22, 2021, 5:10 p.m.