tau <- 0.5
(theta <- copGumbel@tauInv(tau)) # 2
d <- 5
(copG <- onacopulaL("Gumbel", list(theta,1:d)))
set.seed(1)
n <- 1000
x <- rnacopula(n, copG)
x <- qnorm(x) # x now follows a meta-Gumbel model with N(0,1) marginals
u <- pobs(x) # build pseudo-observations
## check if the data comes from a meta-Gumbel model (choose larger n.bootstrap
## in a realistic setup)
res.H0.G <- gnacopula(u, cop=copG, n.bootstrap=10,
estimation.method="mle")
## => uses the transformation of Hering and Hofert (2011), including
## the Kendall distribution function K and the mapping to a univariate
## setting via the chi-square distribution. The final test carried out
## is the Anderson-Darling test.
res.H0.G$p.value # non-rejection according to 5\% level
## plot of the transformed data (Rosenblatt (1952))
u.prime <- rtrafo(u, cop=copG) # exact
pairs(u.prime, cex=0.2) # looks good
## plot of the transformed data (Hering and Hofert (2011))
u.prime. <- htrafo(u, cop=copG)
pairs(u.prime., cex=0.2) # looks good
## what about a meta-Clayton model? (choose larger n.bootstrap in a
## realistic setup)
## note: the parameter of the Clayton copula is only a dummy,
## it will be estimated anyway
copC <- onacopulaL("Clayton", list(1, 1:d))
res.H0.C <- gnacopula(u, cop=copC, n.bootstrap=10,
estimation.method="mle")
res.H0.C$p.value # rejection according to 5\% level
## plot of the transformed data (Hering and Hofert (2011)) to see the deviations
## from uniformity
u.prime <- htrafo(u, cop=copC) # transform the data
pairs(u.prime, cex=0.2) # clearly visible
## plot of the transformed data (Rosenblatt (1952)) to see the deviations from
## uniformity
u.prime. <- rtrafo(u, cop=copC) # transform the data
pairs(u.prime., cex=0.2) # clearly visible
## plot the supposedly U[0,1] distributed variates
z <- gtrafouni(u.prime)
plot(1:length(z), z)
## a bit harder to see, but not perfectly uniform (as expected)
Run the code above in your browser using DataLab