Title: | Simulate from Arbitrary Copulae |
---|---|
Description: | Provides a framework to generating random variates from arbitrary multivariate copulae, while concentrating on (bivariate) extreme value copulae. Particularly useful if the multivariate copulae are not available in closed form. |
Authors: | Berwin A. Turlach [aut, cre], Nader Tajvidi [ctb] |
Maintainer: | Berwin A. Turlach <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.7.0 |
Built: | 2024-11-02 02:55:43 UTC |
Source: | https://github.com/cran/SimCop |
A generic to sample random variates from an object.
GenerateRV(obj, n, ...)
GenerateRV(obj, n, ...)
obj |
object from which to sample. |
n |
number of items to sample. |
... |
further arguments for methods. |
Berwin A. Turlach <[email protected]>
Method to sample random variates from an object of class
‘CopApprox’.
## S3 method for class 'CopApprox' GenerateRV(obj, n, MH = FALSE, trace = FALSE, PDF = NULL, burnin = 500, thinning = 5, ...)
## S3 method for class 'CopApprox' GenerateRV(obj, n, MH = FALSE, trace = FALSE, PDF = NULL, burnin = 500, thinning = 5, ...)
obj |
object from which to sample. |
n |
number of items to sample. |
MH |
logical, should a Metropolis-Hastings algorithm be used to refine the sample? Default is |
trace |
logical, indicating whether the function should be verbose. |
PDF |
probability density function corresponding to copula used to create |
burnin |
the number of burn-in iterations of the MH sampler, only used if |
thinning |
the thining parameter, only used if |
... |
not used. |
If argument MH
is FALSE
, the default, random variates are directly sampled from the approximation, as described in Tajvidi and Turlach (2017).
If MH
is TRUE
, GenerateRV
uses additionally a Metropolis-Hastings refinement. It first samples from the approximation, but uses those samples then as proposals in a Metropolis-Hastings algorithm. The latter needs the probability density function of the copula. This density function has either to be passed to the argument PDF
, or the copula (stored in argument obj
) belonging to the approximation must have the density function (with name ‘pdfCopula
’) stored in its environment. In the latter case, the argument PDF
can be NULL
(its default).
A matrix of dimension n
times dim
, where dim
is the dimension for which the copula approximation was determined.
If MH
was TRUE
the return value has an attribute called ‘AcceptanceRate
’, indicating the fraction of samples that were accepted in the Metropolis-Hastings step. This fraction is based on all burnin + (n-1)*thinning + 1
samples that are initially generated from the approximation.
Tajvidi, N. and Turlach, B.A. (2017). A general approach to generate random variates for multivariate copulae, Australian & New Zealand Journal of Statistics. Doi:10.1111/anzs.12209.
cop <- NewBEVAsyMixedModelCopula(theta=1, phi=-0.25) approx1 <- GetApprox(cop) approx2 <- GetApprox(cop, type = 1) sample1 <- GenerateRV(approx1, 100) plot(sample1) sample2 <- GenerateRV(approx2, 100) plot(sample2) sample1 <- GenerateRV(approx1, 50, MH = TRUE, trace = TRUE) plot(sample1) sample2 <- GenerateRV(approx2, 50, MH = TRUE) plot(sample2)
cop <- NewBEVAsyMixedModelCopula(theta=1, phi=-0.25) approx1 <- GetApprox(cop) approx2 <- GetApprox(cop, type = 1) sample1 <- GenerateRV(approx1, 100) plot(sample1) sample2 <- GenerateRV(approx2, 100) plot(sample2) sample1 <- GenerateRV(approx1, 50, MH = TRUE, trace = TRUE) plot(sample1) sample2 <- GenerateRV(approx2, 50, MH = TRUE) plot(sample2)
Approximates the “density” of a copula by a piece-wise constant function.
GetApprox(Cop, dim = 2, depth = ifelse(type == 1, 10, 32), type = 1, TOL = 1000 * .Machine$double.eps)
GetApprox(Cop, dim = 2, depth = ifelse(type == 1, 10, 32), type = 1, TOL = 1000 * .Machine$double.eps)
Cop |
A function defining the copula. |
dim |
The approximation should be calculated on the dim-dimensional unit cube, defaults to 2. |
depth |
The number of hyperrectangles to be used to devide the unit cube, defaults to 10 for Approximation I and to 32 for Approximation II. |
type |
Whether Approximation I or Approximation II should be used, defaults to one. |
TOL |
A numerical tolerance used when calculating Approximation I. |
This function provides two methods for subdividing the -dimensional unit cube into hyper-rectangles, with
being passed to the parameter
dim
. As most of the functions in this package which create a new copula return a function that can be evaluated at points in arbitrary dimensions, it is necessary to specify for which dimension one wishes to calculate the approximation to the copula's “density”.
The first method (Approximation I) determines hyper-rectangles (where
is the parameter
depth
), each containing the same probability mass with respect to the copula. The second method (Approximation II) dividies the unit cube into hyper-squares.
These approximations can be interpreted as piecewise constant approximations of the copula's probability density function if the copula is absolutely continuous. For futher details see ‘References’.
GetApprox
returns an object of class
‘CopApprox’ according to its inputs. The returned object is a list containing a matrix that holds the information of the approximation, the argument Cop
, which approximation was determined, and other auxiliary information.
The only method for objects of class ‘CopApprox’ implemented so far are for the generic function plot
, and then only for the case if dim
was 2.
Berwin A. Turlach <[email protected]>
Tajvidi, N. and Turlach, B.A. (2017). A general approach to generate random variates for multivariate copulae, Australian & New Zealand Journal of Statistics. Doi:10.1111/anzs.12209.
Cop <- NewMEVGumbelCopula(3) CopApprox <- GetApprox(Cop, dim=2) plot(CopApprox)
Cop <- NewMEVGumbelCopula(3) CopApprox <- GetApprox(Cop, dim=2) plot(CopApprox)
A dataset on maximum annual values of average daily temperature measurements at two meteorological stations—Leonora (latitude 28.53S, longitude 121.19E) and Menzies (latitude 29.42S, longitude 121.02E)— in Western Australia, for the period 1898–1993.
MaxTemp
MaxTemp
A data frame with 96 rows and 2 variables:
annual maximal temperature at Leonora, in degrees Celsius
annual maximal temperature at Menzies, in degrees Celsius
Hall, P. and Tajvidi, N. (2004). Prediction regions for bivariate extreme events. Australian & New Zealand Journal of Statistics 46(1), 99–112. Doi:10.1111/j.1467-842X.2004.00316.x.
plot(Menzies ~ Leonora, MaxTemp, xlab = expression("Temperature at Leonora ("*degree*"C)"), ylab = expression("Temperature at Menzies ("*degree*"C)"))
plot(Menzies ~ Leonora, MaxTemp, xlab = expression("Temperature at Leonora ("*degree*"C)"), ylab = expression("Temperature at Menzies ("*degree*"C)"))
Creates an instance of the bivariate asymmetric logistic model extreme value copula with parameters ,
and
.
NewBEVAsyLogisticCopula(r, theta, phi)
NewBEVAsyLogisticCopula(r, theta, phi)
r |
real. |
theta |
real. |
phi |
real. |
The dependence function for this bivariate EV copula is
Necessary and sufficient conditions for the dependence function to be valid are
For this model reduces to the symmetric logistic model.
A function that evaluates the bivariate asymmetric logistic model EV copula (with parameters ,
and
) at a given
-dimensional vector in the unit square. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the bivariate asymmetric mixed model EV copula via automatic differentation.
Berwin A. Turlach <[email protected]>
NewBEVLogisticCopula
, NewMEVAsyLogisticCopula
Creates an instance of the bivariate asymmetric mixed model extreme value copula with parameters and
.
NewBEVAsyMixedModelCopula(theta, phi)
NewBEVAsyMixedModelCopula(theta, phi)
theta |
real. |
phi |
real. |
The dependence function for this bivariate EV copula is
Necessary and sufficient conditions for the dependence function to be valid are
If we obtain the symmetric mixed model.
A function that evaluates the bivariate asymmetric mixed model EV copula (with parameters and
) at a given
-dimensional vector in the unit square. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the bivariate asymmetric mixed model EV copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Creates an instance of the bivariate logistic model extreme value copula with parameter .
NewBEVLogisticCopula(r)
NewBEVLogisticCopula(r)
r |
real. |
The dependence function for this bivariate EV copula is
Necessary and sufficient conditions for the dependence function to be valid are
A function that evaluates the bivariate logistic model EV copula (with parameter ) at a given
-dimensional vector in the unit square. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the bivariate asymmetric mixed model EV copula via automatic differentation.
Berwin A. Turlach <[email protected]>
NewBEVAsyLogisticCopula
, NewMEVGumbelCopula
Creates an instance of the bivariate asymmetric mixed model extreme value copula with parameter .
NewBEVMixedModelCopula(theta)
NewBEVMixedModelCopula(theta)
theta |
real. |
The dependence function for this bivariate EV copula is
Necessary and sufficient conditions for the dependence function to be valid are
A function that evaluates the bivariate asymmetric mixed model EV copula (with parameter ) at a given
-dimensional vector in the unit square. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the bivariate asymmetric mixed model EV copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Creates a bivariate extreme value copula from a spline estimate of its dependence function.
NewBEVSplineCopula(spl)
NewBEVSplineCopula(spl)
spl |
a spline function. |
A function that evaluates the bivariate EV copula (whose dependence function is given by the spline) at a given -dimensional vector in the unit square. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the bivariate asymmetric mixed model EV copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Creates an instance of the multivariate asymmetric copula with parameters and r.
NewMEVAsyLogisticCopula(theta, r)
NewMEVAsyLogisticCopula(theta, r)
theta |
a |
r |
a vector of |
If theta
has entries and
r
has entries (
and
), then the following parameterisation of the copula is used:
where ,
.
Necessary and sufficient conditions for the parameters are
all entries in theta
have to be non-negative.
each column of theta
has to add to one.
each row of theta
must have a unique pattern of non-zero values, including the pattern that has no zeros in a row.
if a row of theta
has only one non-zero value, then the corresponding entry in r
has to be one.
if a row of theta
has more than one non-zero value, then the corresponding entry of r
must be greater than one.
A function that evaluates the multivariate asymmetric logistic copula (with parameters and r) at a given
-dimensional vector in the unit square. Note that for this function the dimension of vectors at which the copula can be evaluated is determined by the input parameters. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the multivariate asymmetric logistic copula via automatic differentation.
Berwin A. Turlach <[email protected]>
NewBEVAsyLogisticCopula
, NewMEVGumbelCopula
theta <- rbind(c(0, 0.2, 0.8), c(1,0.8,0.2)) r <- c(2,3) cop <- NewMEVAsyLogisticCopula(theta, r) ## Creates the same copula theta <- 0.2 phi <- 0.4 r <- 2 cop1 <- NewBEVAsyLogisticCopula(r, theta, phi) theta <- cbind(c(phi, 1-phi, 0), c(theta, 0, 1-theta)) r <- c(r, 1, 1) cop2 <- NewMEVAsyLogisticCopula(theta, r)
theta <- rbind(c(0, 0.2, 0.8), c(1,0.8,0.2)) r <- c(2,3) cop <- NewMEVAsyLogisticCopula(theta, r) ## Creates the same copula theta <- 0.2 phi <- 0.4 r <- 2 cop1 <- NewBEVAsyLogisticCopula(r, theta, phi) theta <- cbind(c(phi, 1-phi, 0), c(theta, 0, 1-theta)) r <- c(r, 1, 1) cop2 <- NewMEVAsyLogisticCopula(theta, r)
Creates an instance of the Gumbel copula with parameter r. This family is also known as the Gumbel–Hougaard copula or the logistic model.
NewMEVGumbelCopula(r = 2)
NewMEVGumbelCopula(r = 2)
r |
real, the parameter of the Gumbel copula, defaults to 2, must be larger or equal to one. |
The following parameterisation of the copula is used:
where ,
.
A function that evaluates the Gumbel copula (with parameter r) at a given -dimensional vector in the unit cube. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the Gumbel copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Creates an instance of the Clayton copula with parameter .
NewMVClaytonCopula(theta = 1)
NewMVClaytonCopula(theta = 1)
theta |
real, the parameter of the Clayton copula, defaults to 1; must be positive. |
The following parameterisation of the copula is used:
A function that evaluates the Clayton copula (with parameter ) at a given
-dimensional vector in the unit cube. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the Clayton copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Creates an instance of the Frank copula with parameter .
NewMVFrankCopula(alpha = 1)
NewMVFrankCopula(alpha = 1)
alpha |
real, the parameter of the Frank copula, defaults to 2; must be positive. |
The following parameterisation of the copula is used:
where and
.
A function that evaluates the Frank copula (with parameter ) at a given
-dimensional vector in the unit cube. The environment of the function also contains a function called
pdfCopula
that evaluates the probability density function of the Frank copula via automatic differentation.
Berwin A. Turlach <[email protected]>
Function to calculate nonparametric estimates of the dependence functions of bivariate extreme value copula.
NonparEstDepFct(x, y = NULL, w.length = 101, transf.to.frechet = TRUE, convex.hull = TRUE, verbose = FALSE)
NonparEstDepFct(x, y = NULL, w.length = 101, transf.to.frechet = TRUE, convex.hull = TRUE, verbose = FALSE)
x , y
|
vectors giving the observations of the extreme values. Alternatively a single plotting structure can be specified: see |
w.length |
number of grid points (using an equidistant grid from 0 to 1) on which the dependence function is estimated. |
transf.to.frechet |
logical, controls whether |
convex.hull |
logical, controls whether the convex hull of the modified Pickands estimator is returned; defaults to |
verbose |
logical, controls whether progress messages are given; defaults to |
If transf.to.frechet
is TRUE
, the default, then a generalised extreme value (GEV) distribution is fitted to each margin and the fitted parameters are used to transform the data to have standard Fréchet margins. The parameterisation of the cumulative distribution of the GEV that is used is, if :
and for :
If , then the support of the GEV is the interval
, while it is
if
. For
, the support is the real line.
If verbose
is TRUE
, not the default, and transf.to.frechet
is TRUE
, the estimates for the fitted GEV distribution are printed out using cat
.
A list with two named components. The component x
contains a vector with the grid points at which the dependence function was estimated. The component y
contains the estimated dependence functions.
Nader Tajvidi <[email protected]>
Hall, P. and Tajvidi, N. (2000). Distribution and dependence-function estimation for bivariate extreme-value distributions. Bernoulli 6(5), 835–844. Doi:10.2307/3318758.
Hall, P. and Tajvidi, N. (2004). Prediction regions for bivariate extreme events. Australian & New Zealand Journal of Statistics 46(1), 99–112. Doi:10.1111/j.1467-842X.2004.00316.x.
## Data from Hall and Tajvidi (2004, ANZJS) EstDF1 <- NonparEstDepFct(MaxTemp) ## Plot modified Pickands Function and area in which ## dependence function must lie plot(EstDF1, ylim = c(0.5,1), xlab = "w", ylab = "A(w)", type="l", lty="longdash") polygon(c(0, 0.5, 1, 0), c(1, 0.5, 1, 1))
## Data from Hall and Tajvidi (2004, ANZJS) EstDF1 <- NonparEstDepFct(MaxTemp) ## Plot modified Pickands Function and area in which ## dependence function must lie plot(EstDF1, ylim = c(0.5,1), xlab = "w", ylab = "A(w)", type="l", lty="longdash") polygon(c(0, 0.5, 1, 0), c(1, 0.5, 1, 1))
Plots the histogram density approximation to a copula as determined by GetApprox
. Currently works only for bivariate copulae.
## S3 method for class 'CopApprox' plot(x, ...)
## S3 method for class 'CopApprox' plot(x, ...)
x |
an object of |
... |
not used. |
Berwin A. Turlach <[email protected]>
Tajvidi, N. and Turlach, B.A. (2017). A general approach to generate random variates for multivariate copulae, Australian & New Zealand Journal of Statistics. Doi:10.1111/anzs.12209.
Cop <- NewMEVGumbelCopula(4) CopApprox1 <- GetApprox(Cop, dim=2) plot(CopApprox1) CopApprox2 <- GetApprox(Cop, dim=2, type=2) plot(CopApprox2)
Cop <- NewMEVGumbelCopula(4) CopApprox1 <- GetApprox(Cop, dim=2) plot(CopApprox1) CopApprox2 <- GetApprox(Cop, dim=2, type=2) plot(CopApprox2)
Prints basic information on a copula created with the methods in this package.
## S3 method for class 'SimCop' print(x, ...)
## S3 method for class 'SimCop' print(x, ...)
x |
an object of |
... |
not used. |
Berwin A. Turlach <[email protected]>
R code to support Tajvidi and Turlach (2017). The main functions implemented for the SimCop package are:
New*Copula
, various functions that create objects of class
‘SimCop’. These functions return a copula function with various helpful information stored in the environment of the function.
Details of the implementation are subject to change and should not be relied on.
Only a print
method is implemented for this class so far.
GetApprox
, a function that calculates approximations to a copula and returns an object of class
‘CopApprox’.
For bivariate copulae a method for plot
is implemented for this class.
GenerateRV
, a generic function that generates random variates from an object, together with a method for objects of class ‘CopApprox’.
Tajvidi, N. and Turlach, B.A. (2017). A general approach to generate random variates for multivariate copulae, Australian & New Zealand Journal of Statistics. Doi:10.1111/anzs.12209.
Given estimates for the dependence function of a bivariate extreme value copula at specified points, this function fits a natural cubic smoothing spline, that is constrained to fulfill all the conditions of a dependence function, to the given estimates via quadratic programming.
SplineFitDepFct(x, y = NULL, alpha = 0.01, integ.value)
SplineFitDepFct(x, y = NULL, alpha = 0.01, integ.value)
x , y
|
vectors giving the coordinates of the points to be approximated. Alternatively a single plotting structure can be specified: see |
alpha |
real, the smoothing parameter for the smoothing splines. |
integ.value |
real, non-negative value that should be less than two; see ‘Details’ |
integ.value
should be between 0 and 2. If a value is specified, then an additional constraint is added to the quadratic program to ensure that the integeral (over 0 to 1) of the second derivative of the spline is larger or equal to integ.value
. Choosing values close to 2 may lead to quadratic programms on which solve.QP
reports inconsistent constraints.
A function, created by splinefun
, that evaluates the natural cubic spline that was fitted to the data.
Nader Tajvidi <[email protected]>
Berwin A Turlach <[email protected]>
Hall, P. and Tajvidi, N. (2000). Distribution and dependence-function estimation for bivariate extreme-value distributions. Bernoulli 6(5), 835–844. Doi:10.2307/3318758.
Hall, P. and Tajvidi, N. (2004). Prediction regions for bivariate extreme events. Australian & New Zealand Journal of Statistics 46(1), 99–112. Doi:10.1111/j.1467-842X.2004.00316.x.
NonparEstDepFct
, NewBEVSplineCopula
## Data from Hall and Tajvidi (2004, ANZJS) EstDF2 <- NonparEstDepFct(MaxTemp, convex = FALSE) ## Plot modified Pickands Function and area in which ## dependence function must lie plot(EstDF2, ylim = c(0.5,1), xlab = "w", ylab = "A(w)", type="l", lty="longdash") polygon(c(0, 0.5, 1, 0), c(1, 0.5, 1, 1)) ## Fit spline to Pickands function and add to plot splfit <- SplineFitDepFct(EstDF2) curve(splfit, n = 301, add = TRUE, lty = "dashed")
## Data from Hall and Tajvidi (2004, ANZJS) EstDF2 <- NonparEstDepFct(MaxTemp, convex = FALSE) ## Plot modified Pickands Function and area in which ## dependence function must lie plot(EstDF2, ylim = c(0.5,1), xlab = "w", ylab = "A(w)", type="l", lty="longdash") polygon(c(0, 0.5, 1, 0), c(1, 0.5, 1, 1)) ## Fit spline to Pickands function and add to plot splfit <- SplineFitDepFct(EstDF2) curve(splfit, n = 301, add = TRUE, lty = "dashed")