cCopula | R Documentation |
Compute the conditional distribution function
C(u_d\,|\,u_1,\dots, u_{d-1})
of u_d
given u_1,\dots,u_{d-1}
.
cCopula(u, copula, indices = 1:dim(copula), inverse = FALSE,
log = FALSE, drop = FALSE, ...)
## Deprecated (use cCopula() instead):
rtrafo(u, copula, indices = 1:dim(copula), inverse = FALSE, log = FALSE)
cacopula(u, cop, n.MC = 0, log = FALSE)
u |
data |
copula , cop |
copula, i.e., an object of class
|
indices |
vector of indices |
inverse |
|
n.MC |
integer Monte Carlo sample size; for Archimedean copulas only, used if positive. |
log |
a |
drop |
a |
... |
additional arguments (currently only used if
|
By default and if fed with a sample of the corresponding copula,
cCopula()
computes the Rosenblatt
transform; see Rosenblatt (1952). The involved high-order derivatives
for Archimedean copulas were derived in Hofert et al. (2012).
Sampling, that is, random number generation,
can be achieved by using inverse=TRUE
. In this case,
the inverse Rosenblatt transformation is used, which, for sampling
purposes, is also known as conditional distribution method.
Note that, for Archimedean copulas not being Clayton, this can be slow
as it involves numerical root finding in each (but the first) component.
An (n, k)
-matrix
(unless n == 1
and
drop
is true, where a k
-vector is returned) where k
is the length of indices
. This matrix contains the conditional
copula function values
C_{j|1,\dots,j-1}(u_j\,|\,u_1,\dots,u_{j-1})
or, if inverse = TRUE
, their inverses
C^-_{j|1,\dots,j-1}(u_j\,|\,u_1,\dots,u_{j-1})
for all j
in indices
.
For some (but not all) families, this function also makes sense on the boundaries (if the corresponding limits can be computed).
Genest, C., Rémillard, B., and Beaudoin, D. (2009). Goodness-of-fit tests for copulas: A review and a power study. Insurance: Mathematics and Economics 44, 199–213.
Rosenblatt, M. (1952). Remarks on a Multivariate Transformation, The Annals of Mathematical Statistics 23, 3, 470–472.
Hofert, M., Mächler, M., and McNeil, A. J. (2012). Likelihood inference for Archimedean copulas in high dimensions under known margins. Journal of Multivariate Analysis 110, 133–150.
htrafo
; acopula-families
.
## 1) Sampling from a conditional distribution of a Clayton copula given u_1
## Define the copula
tau <- 0.5
theta <- iTau(claytonCopula(), tau = tau)
d <- 2
cc <- claytonCopula(theta, dim = d)
n <- 1000
set.seed(271)
## A small u_1
u1 <- 0.05
U <- cCopula(cbind(u1, runif(n)), copula = cc, inverse = TRUE)
plot(U[,2], ylab = quote(U[2]))
## A large u_1
u1 <- 0.95
U <- cCopula(cbind(u1, runif(n)), copula = cc, inverse = TRUE)
plot(U[,2], ylab = quote(U[2]))
## 2) Sample via conditional distribution method and then apply the
## Rosenblatt transform
## Note: We choose the numerically more involved (and thus slower)
## Gumbel case here
## Define the copula
tau <- 0.5
theta <- iTau(gumbelCopula(), tau = tau)
d <- 5
gc <- gumbelCopula(theta, dim = d)
n <- 200
set.seed(271)
U. <- matrix(runif(n*d), ncol = d) # U(0,1)^d
## Transform to Gumbel sample via conditional distribution method
U <- cCopula(U., copula = gc, inverse = TRUE) # slow for ACs except Clayton
splom2(U) # scatter-plot matrix copula sample
## Rosenblatt transform back to U(0,1)^d (as a check)
U. <- cCopula(U, copula = gc)
splom2(U.) # U(0,1)^d again
## 3) cCopula() for elliptical copulas
tau <- 0.5
theta <- iTau(claytonCopula(), tau = tau)
d <- 5
cc <- claytonCopula(theta, dim = d)
set.seed(271)
n <- 1000
U <- rCopula(n, copula = cc)
X <- qnorm(U) # X now follows a meta-Clayton model with N(0,1) marginals
U <- pobs(X) # build pseudo-observations
fN <- fitCopula(normalCopula(dim = d), data = U) # fit a Gauss copula
U.RN <- cCopula(U, copula = fN@copula)
splom2(U.RN, cex = 0.2) # visible but not so clearly
f.t <- fitCopula(tCopula(dim = d), U)
U.Rt <- cCopula(U, copula = f.t@copula) # transform with a fitted t copula
splom2(U.Rt, cex = 0.2) # still visible but not so clear
## Inverse (and check consistency)
U.N <- cCopula(U.RN, copula = fN @copula, inverse = TRUE)
U.t <- cCopula(U.Rt, copula = f.t@copula, inverse = TRUE)
tol <- 1e-14
stopifnot(
all.equal(U, U.N),
all.equal(U, U.t),
all.equal(log(U.RN),
cCopula(U, copula = fN @copula, log = TRUE), tolerance = tol),
all.equal(log(U.Rt),
cCopula(U, copula = f.t@copula, log = TRUE), tolerance = tol)
)
## 4) cCopula() for a more sophisticated mixture copula (bivariate case only!)
tau <- 0.5
cc <- claytonCopula(iTau(claytonCopula(), tau = tau)) # first mixture component
tc <- tCopula(iTau(tCopula(), tau = tau), df = 3) # t_3 copula
tc90 <- rotCopula(tc, flip = c(TRUE, FALSE)) # t copula rotated by 90 degrees
wts <- c(1/2, 1/2) # mixture weights
mc <- mixCopula(list(cc, tc90), w = wts) # mixture copula with one copula rotated
set.seed(271)
U <- rCopula(n, copula = mc)
U. <- cCopula(U, copula = mc) # Rosenblatt transform back to U(0,1)^2 (as a check)
plot(U., xlab = quote(U*"'"[1]), ylab = quote(U*"'"[2])) # check for uniformity
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.