CRAN Package Check Results for Package copula

Last updated on 2019-03-19 16:51:23 CET.

Flavor Version Tinstall Tcheck Ttotal Status Flags
r-devel-linux-x86_64-debian-clang 0.999-19 44.74 1023.98 1068.72 ERROR
r-devel-linux-x86_64-debian-gcc 0.999-19 37.23 719.57 756.80 ERROR
r-devel-linux-x86_64-fedora-clang 0.999-19 1243.94 ERROR
r-devel-linux-x86_64-fedora-gcc 0.999-19 1198.74 ERROR
r-devel-windows-ix86+x86_64 0.999-19 112.00 820.00 932.00 ERROR --no-vignettes
r-patched-linux-x86_64 0.999-19 36.20 981.62 1017.82 OK
r-patched-solaris-x86 0.999-19 1564.30 NOTE
r-release-linux-x86_64 0.999-19 37.42 965.13 1002.55 OK
r-release-windows-ix86+x86_64 0.999-19 95.00 846.00 941.00 NOTE --no-vignettes
r-release-osx-x86_64 0.999-19 NOTE
r-oldrel-windows-ix86+x86_64 0.999-19 87.00 777.00 864.00 WARN --no-vignettes
r-oldrel-osx-x86_64 0.999-19 WARN

Check Details

Version: 0.999-19
Check: tests
Result: ERROR
     Running 'Stirling-etc.R' [12s/13s]
     Running 'copula-play.R' [27s/29s]
     Running 'dC-dc-ex.R' [4s/5s]
     Running 'estim-ex.R' [8s/9s]
     Running 'explicitCop-ex.R' [23s/24s]
     Running 'fitting-ex.R' [12s/14s]
     Running 'fixedPar-ex.R' [11s/12s]
     Running 'ggraph-tst.R' [11s/13s]
     Running 'khoudraji-ex.R' [24s/26s]
     Running 'misc.R' [2s/3s]
     Running 'mixCop-tst.R' [3s/4s]
     Running 'moments.R' [4s/4s]
     Running 'nac-experi.R' [16s/17s]
     Running 'retstable-ex.R' [4s/4s]
     Running 'rstable-ex.R' [6s/7s]
     Running 'tail-pcopula.R' [3s/3s]
     Comparing 'tail-pcopula.Rout' to 'tail-pcopula.Rout.save' ... OK
    Running the tests in 'tests/fitting-ex.R' failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.515 0.004 0.82
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.026 0 0.027
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200562901) : NaNs produced
     4: In dexp(x, rate = -0.813186200562901) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 4.142 0.242 4.876
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Error in optim(fit$par, logL, lower = lower, upper = upper, method = optim.method, :
     non-finite finite-difference value [1]
     In addition: Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.37 0.027 0.422
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0.002 0 0.003
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
    Running the tests in 'tests/mixCop-tst.R' failed.
    Complete output:
     > ## Copyright (C) 2016 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     > ### Finite Mixtures of Copulas: mixCopula()
     > ### ========================================
     >
     > library(copula)
     > isExplicit <- copula:::isExplicit
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     > is32 <- .Machine$sizeof.pointer == 4 ## <- should work for Linux/MacOS/Windows
     > isMac <- Sys.info()[["sysname"]] == "Darwin"
     > isSun <- Sys.info()[["sysname"]] == "SunOS"
     >
     > mC <- mixCopula(list(gumbelCopula(2.5, dim=3),
     + claytonCopula(pi, dim=3),
     + tCopula(0.7, dim=3)),
     + c(2,2,4)/8)
     > mC
     mixCopula from 3 components
     (Gmbc, Clyc, t-cp) with weights:
     (0.25, 0.25, 0.50)
     Dimension: 3
     Parameters:
     m1.alpha = 2.500000
     m2.alpha = 3.141593
     m3.rho.1 = 0.700000
     m3.df = 4.000000
     w1 = 0.250000
     w2 = 0.250000
     w3 = 0.500000
     > stopifnot(dim(mC) == 3, inherits(mC, "mixCopula"))
     >
     > ## mix a Gumbel with a rotated Gumbel (with equal weights 1/2):
     > mGG <- mixCopula(list(gumbelCopula(2), rotCopula(gumbelCopula(1.5))))
     > stopifnot(dim(mGG) == 2, inherits(mGG, "mixCopula"),
     + all.equal( rho(mGG), 0.57886340158, tol=1e-10) ,
     + all.equal(lambda(mGG), c(lower = 0.206299474016,
     + upper = 0.292893218813), tol = 1e-10)
     + )
     > mGG # 4 parameters
     mixCopula from 2 components
     (Gmbc , RccfGc) with weights:
     (0.5, 0.5)
     Dimension: 2
     Parameters:
     m1.alpha = 2.0
     m2.alpha = 1.5
     w1 = 0.5
     w2 = 0.5
     >
     > set.seed(17)
     > uM <- rCopula( 600, mC)
     > uGG <- rCopula(1000, mGG)
     > ## Check dCopula(*, log= TRUE) ## --- this was __wrong__ for many days (not on CRAN)
     > stopifnot(
     + length(dCopula(uM[1,,drop=FALSE], mC, log=TRUE)) == 1,# was wrong
     + all.equal(log(dCopula(uM, mC)),
     + dCopula(uM, mC, log=TRUE), tol = 1e-12),
     + all.equal(log(dCopula(uGG, mGG)),
     + dCopula(uGG, mGG, log=TRUE), tol = 1e-12)
     + )
     > (llGG1 <- loglikCopula(c(2.5, 1., w = c(2,4)/6), u=uGG, copula = mGG))
     [1] 165.1878
     > (llMC <- loglikCopula(c(2.5, pi, rho.1=0.7, df = 4, w = c(2,2,4)/8), u = uM, copula = mC))
     [1] 532.8758
     > ## discrepancy 32 bit <-> 64 bit --- still (after dMixCopula() bug fix):
     > stopifnot(
     + all.equal(llGG1, 177.452426, ## 32 bit (Windows, Linux(FC 24)): 188.0358
     + tol = if(isSun || isMac || is32) 0.08 else 7e-7),
     + all.equal(llMC, 532.8757887, ## 32 bit: 551.8439
     + tol = if(isSun || isMac || is32) 0.05 else 7e-7)
     + )
     Error: llGG1 and 177.452426 are not equal:
     Mean relative difference: 0.0742465
     Execution halted
Flavor: r-devel-linux-x86_64-debian-clang

Version: 0.999-19
Check: tests
Result: ERROR
     Running ‘Stirling-etc.R’ [10s/13s]
     Running ‘copula-play.R’ [23s/32s]
     Running ‘dC-dc-ex.R’ [3s/5s]
     Running ‘estim-ex.R’ [6s/9s]
     Running ‘explicitCop-ex.R’ [17s/25s]
     Running ‘fitting-ex.R’ [9s/11s]
     Running ‘fixedPar-ex.R’ [8s/11s]
     Running ‘ggraph-tst.R’ [8s/13s]
     Running ‘khoudraji-ex.R’ [20s/31s]
     Running ‘misc.R’ [2s/3s]
     Running ‘mixCop-tst.R’ [2s/3s]
     Running ‘moments.R’ [3s/5s]
     Running ‘nac-experi.R’ [12s/16s]
     Running ‘retstable-ex.R’ [3s/4s]
     Running ‘rstable-ex.R’ [5s/6s]
     Running ‘tail-pcopula.R’ [2s/3s]
     Comparing ‘tail-pcopula.Rout’ to ‘tail-pcopula.Rout.save’ ... OK
    Running the tests in ‘tests/fitting-ex.R’ failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.312 0.008 0.332
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.016 0 0.017
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200562901) : NaNs produced
     4: In dexp(x, rate = -0.813186200562901) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 2.515 0.029 2.989
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Error in optim(fit$par, logL, lower = lower, upper = upper, method = optim.method, :
     non-finite finite-difference value [1]
     In addition: Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.282 0.004 0.302
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0.002 0 0.001
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
    Running the tests in ‘tests/mixCop-tst.R’ failed.
    Complete output:
     > ## Copyright (C) 2016 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     > ### Finite Mixtures of Copulas: mixCopula()
     > ### ========================================
     >
     > library(copula)
     > isExplicit <- copula:::isExplicit
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     > is32 <- .Machine$sizeof.pointer == 4 ## <- should work for Linux/MacOS/Windows
     > isMac <- Sys.info()[["sysname"]] == "Darwin"
     > isSun <- Sys.info()[["sysname"]] == "SunOS"
     >
     > mC <- mixCopula(list(gumbelCopula(2.5, dim=3),
     + claytonCopula(pi, dim=3),
     + tCopula(0.7, dim=3)),
     + c(2,2,4)/8)
     > mC
     mixCopula from 3 components
     (Gmbc, Clyc, t-cp) with weights:
     (0.25, 0.25, 0.50)
     Dimension: 3
     Parameters:
     m1.alpha = 2.500000
     m2.alpha = 3.141593
     m3.rho.1 = 0.700000
     m3.df = 4.000000
     w1 = 0.250000
     w2 = 0.250000
     w3 = 0.500000
     > stopifnot(dim(mC) == 3, inherits(mC, "mixCopula"))
     >
     > ## mix a Gumbel with a rotated Gumbel (with equal weights 1/2):
     > mGG <- mixCopula(list(gumbelCopula(2), rotCopula(gumbelCopula(1.5))))
     > stopifnot(dim(mGG) == 2, inherits(mGG, "mixCopula"),
     + all.equal( rho(mGG), 0.57886340158, tol=1e-10) ,
     + all.equal(lambda(mGG), c(lower = 0.206299474016,
     + upper = 0.292893218813), tol = 1e-10)
     + )
     > mGG # 4 parameters
     mixCopula from 2 components
     (Gmbc , RccfGc) with weights:
     (0.5, 0.5)
     Dimension: 2
     Parameters:
     m1.alpha = 2.0
     m2.alpha = 1.5
     w1 = 0.5
     w2 = 0.5
     >
     > set.seed(17)
     > uM <- rCopula( 600, mC)
     > uGG <- rCopula(1000, mGG)
     > ## Check dCopula(*, log= TRUE) ## --- this was __wrong__ for many days (not on CRAN)
     > stopifnot(
     + length(dCopula(uM[1,,drop=FALSE], mC, log=TRUE)) == 1,# was wrong
     + all.equal(log(dCopula(uM, mC)),
     + dCopula(uM, mC, log=TRUE), tol = 1e-12),
     + all.equal(log(dCopula(uGG, mGG)),
     + dCopula(uGG, mGG, log=TRUE), tol = 1e-12)
     + )
     > (llGG1 <- loglikCopula(c(2.5, 1., w = c(2,4)/6), u=uGG, copula = mGG))
     [1] 165.1878
     > (llMC <- loglikCopula(c(2.5, pi, rho.1=0.7, df = 4, w = c(2,2,4)/8), u = uM, copula = mC))
     [1] 532.8758
     > ## discrepancy 32 bit <-> 64 bit --- still (after dMixCopula() bug fix):
     > stopifnot(
     + all.equal(llGG1, 177.452426, ## 32 bit (Windows, Linux(FC 24)): 188.0358
     + tol = if(isSun || isMac || is32) 0.08 else 7e-7),
     + all.equal(llMC, 532.8757887, ## 32 bit: 551.8439
     + tol = if(isSun || isMac || is32) 0.05 else 7e-7)
     + )
     Error: llGG1 and 177.452426 are not equal:
     Mean relative difference: 0.0742465
     Execution halted
Flavor: r-devel-linux-x86_64-debian-gcc

Version: 0.999-19
Check: installed package size
Result: NOTE
     installed size is 9.4Mb
     sub-directories of 1Mb or more:
     R 2.1Mb
     doc 5.0Mb
Flavors: r-devel-linux-x86_64-fedora-clang, r-patched-solaris-x86, r-release-osx-x86_64, r-oldrel-osx-x86_64

Version: 0.999-19
Check: tests
Result: ERROR
     Running ‘Stirling-etc.R’ [7s/12s]
     Running ‘copula-play.R’ [33s/37s]
     Running ‘dC-dc-ex.R’
     Running ‘estim-ex.R’ [10s/17s]
     Running ‘explicitCop-ex.R’ [25s/41s]
     Running ‘fitting-ex.R’ [14s/21s]
     Running ‘fixedPar-ex.R’ [14s/22s]
     Running ‘ggraph-tst.R’ [14s/26s]
     Running ‘khoudraji-ex.R’ [31s/58s]
     Running ‘misc.R’
     Running ‘mixCop-tst.R’ [4s/11s]
     Running ‘moments.R’ [5s/12s]
     Running ‘nac-experi.R’ [20s/50s]
     Running ‘retstable-ex.R’ [5s/12s]
     Running ‘rstable-ex.R’ [8s/19s]
     Running ‘tail-pcopula.R’
     Comparing ‘tail-pcopula.Rout’ to ‘tail-pcopula.Rout.save’ ... OK
    Running the tests in ‘tests/fitting-ex.R’ failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.502 0.006 1.141
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.027 0 0.053
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200562901) : NaNs produced
     4: In dexp(x, rate = -0.813186200562901) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 4.744 0.041 6.449
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Error in optim(fit$par, logL, lower = lower, upper = upper, method = optim.method, :
     non-finite finite-difference value [1]
     In addition: Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.407 0.004 0.459
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0.002 0 0.002
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
    Running the tests in ‘tests/mixCop-tst.R’ failed.
    Complete output:
     > ## Copyright (C) 2016 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     > ### Finite Mixtures of Copulas: mixCopula()
     > ### ========================================
     >
     > library(copula)
     > isExplicit <- copula:::isExplicit
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     > is32 <- .Machine$sizeof.pointer == 4 ## <- should work for Linux/MacOS/Windows
     > isMac <- Sys.info()[["sysname"]] == "Darwin"
     > isSun <- Sys.info()[["sysname"]] == "SunOS"
     >
     > mC <- mixCopula(list(gumbelCopula(2.5, dim=3),
     + claytonCopula(pi, dim=3),
     + tCopula(0.7, dim=3)),
     + c(2,2,4)/8)
     > mC
     mixCopula from 3 components
     (Gmbc, Clyc, t-cp) with weights:
     (0.25, 0.25, 0.50)
     Dimension: 3
     Parameters:
     m1.alpha = 2.500000
     m2.alpha = 3.141593
     m3.rho.1 = 0.700000
     m3.df = 4.000000
     w1 = 0.250000
     w2 = 0.250000
     w3 = 0.500000
     > stopifnot(dim(mC) == 3, inherits(mC, "mixCopula"))
     >
     > ## mix a Gumbel with a rotated Gumbel (with equal weights 1/2):
     > mGG <- mixCopula(list(gumbelCopula(2), rotCopula(gumbelCopula(1.5))))
     > stopifnot(dim(mGG) == 2, inherits(mGG, "mixCopula"),
     + all.equal( rho(mGG), 0.57886340158, tol=1e-10) ,
     + all.equal(lambda(mGG), c(lower = 0.206299474016,
     + upper = 0.292893218813), tol = 1e-10)
     + )
     > mGG # 4 parameters
     mixCopula from 2 components
     (Gmbc , RccfGc) with weights:
     (0.5, 0.5)
     Dimension: 2
     Parameters:
     m1.alpha = 2.0
     m2.alpha = 1.5
     w1 = 0.5
     w2 = 0.5
     >
     > set.seed(17)
     > uM <- rCopula( 600, mC)
     > uGG <- rCopula(1000, mGG)
     > ## Check dCopula(*, log= TRUE) ## --- this was __wrong__ for many days (not on CRAN)
     > stopifnot(
     + length(dCopula(uM[1,,drop=FALSE], mC, log=TRUE)) == 1,# was wrong
     + all.equal(log(dCopula(uM, mC)),
     + dCopula(uM, mC, log=TRUE), tol = 1e-12),
     + all.equal(log(dCopula(uGG, mGG)),
     + dCopula(uGG, mGG, log=TRUE), tol = 1e-12)
     + )
     > (llGG1 <- loglikCopula(c(2.5, 1., w = c(2,4)/6), u=uGG, copula = mGG))
     [1] 165.1878
     > (llMC <- loglikCopula(c(2.5, pi, rho.1=0.7, df = 4, w = c(2,2,4)/8), u = uM, copula = mC))
     [1] 532.8758
     > ## discrepancy 32 bit <-> 64 bit --- still (after dMixCopula() bug fix):
     > stopifnot(
     + all.equal(llGG1, 177.452426, ## 32 bit (Windows, Linux(FC 24)): 188.0358
     + tol = if(isSun || isMac || is32) 0.08 else 7e-7),
     + all.equal(llMC, 532.8757887, ## 32 bit: 551.8439
     + tol = if(isSun || isMac || is32) 0.05 else 7e-7)
     + )
     Error: llGG1 and 177.452426 are not equal:
     Mean relative difference: 0.0742465
     Execution halted
Flavor: r-devel-linux-x86_64-fedora-clang

Version: 0.999-19
Check: tests
Result: ERROR
     Running ‘Stirling-etc.R’ [7s/18s]
     Running ‘copula-play.R’ [31s/73s]
     Running ‘dC-dc-ex.R’ [5s/10s]
     Running ‘estim-ex.R’ [10s/25s]
     Running ‘explicitCop-ex.R’ [26s/59s]
     Running ‘fitting-ex.R’ [14s/34s]
     Running ‘fixedPar-ex.R’ [13s/31s]
     Running ‘ggraph-tst.R’ [13s/32s]
     Running ‘khoudraji-ex.R’ [32s/82s]
     Running ‘misc.R’
     Running ‘mixCop-tst.R’
     Running ‘moments.R’ [4s/12s]
     Running ‘nac-experi.R’ [19s/46s]
     Running ‘retstable-ex.R’ [5s/12s]
     Running ‘rstable-ex.R’ [7s/15s]
     Running ‘tail-pcopula.R’
     Comparing ‘tail-pcopula.Rout’ to ‘tail-pcopula.Rout.save’ ... OK
    Running the tests in ‘tests/fitting-ex.R’ failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.521 0.007 1.214
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.023 0.001 0.055
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581371, sd = -1.26949880218296) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200562901) : NaNs produced
     4: In dexp(x, rate = -0.813186200562901) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 4.519 0.035 10.687
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Error in optim(fit$par, logL, lower = lower, upper = upper, method = optim.method, :
     non-finite finite-difference value [1]
     In addition: Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.425 0.006 1.166
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0.002 0 0.003
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
    Running the tests in ‘tests/mixCop-tst.R’ failed.
    Complete output:
     > ## Copyright (C) 2016 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     > ### Finite Mixtures of Copulas: mixCopula()
     > ### ========================================
     >
     > library(copula)
     > isExplicit <- copula:::isExplicit
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     > is32 <- .Machine$sizeof.pointer == 4 ## <- should work for Linux/MacOS/Windows
     > isMac <- Sys.info()[["sysname"]] == "Darwin"
     > isSun <- Sys.info()[["sysname"]] == "SunOS"
     >
     > mC <- mixCopula(list(gumbelCopula(2.5, dim=3),
     + claytonCopula(pi, dim=3),
     + tCopula(0.7, dim=3)),
     + c(2,2,4)/8)
     > mC
     mixCopula from 3 components
     (Gmbc, Clyc, t-cp) with weights:
     (0.25, 0.25, 0.50)
     Dimension: 3
     Parameters:
     m1.alpha = 2.500000
     m2.alpha = 3.141593
     m3.rho.1 = 0.700000
     m3.df = 4.000000
     w1 = 0.250000
     w2 = 0.250000
     w3 = 0.500000
     > stopifnot(dim(mC) == 3, inherits(mC, "mixCopula"))
     >
     > ## mix a Gumbel with a rotated Gumbel (with equal weights 1/2):
     > mGG <- mixCopula(list(gumbelCopula(2), rotCopula(gumbelCopula(1.5))))
     > stopifnot(dim(mGG) == 2, inherits(mGG, "mixCopula"),
     + all.equal( rho(mGG), 0.57886340158, tol=1e-10) ,
     + all.equal(lambda(mGG), c(lower = 0.206299474016,
     + upper = 0.292893218813), tol = 1e-10)
     + )
     > mGG # 4 parameters
     mixCopula from 2 components
     (Gmbc , RccfGc) with weights:
     (0.5, 0.5)
     Dimension: 2
     Parameters:
     m1.alpha = 2.0
     m2.alpha = 1.5
     w1 = 0.5
     w2 = 0.5
     >
     > set.seed(17)
     > uM <- rCopula( 600, mC)
     > uGG <- rCopula(1000, mGG)
     > ## Check dCopula(*, log= TRUE) ## --- this was __wrong__ for many days (not on CRAN)
     > stopifnot(
     + length(dCopula(uM[1,,drop=FALSE], mC, log=TRUE)) == 1,# was wrong
     + all.equal(log(dCopula(uM, mC)),
     + dCopula(uM, mC, log=TRUE), tol = 1e-12),
     + all.equal(log(dCopula(uGG, mGG)),
     + dCopula(uGG, mGG, log=TRUE), tol = 1e-12)
     + )
     > (llGG1 <- loglikCopula(c(2.5, 1., w = c(2,4)/6), u=uGG, copula = mGG))
     [1] 165.1878
     > (llMC <- loglikCopula(c(2.5, pi, rho.1=0.7, df = 4, w = c(2,2,4)/8), u = uM, copula = mC))
     [1] 532.8758
     > ## discrepancy 32 bit <-> 64 bit --- still (after dMixCopula() bug fix):
     > stopifnot(
     + all.equal(llGG1, 177.452426, ## 32 bit (Windows, Linux(FC 24)): 188.0358
     + tol = if(isSun || isMac || is32) 0.08 else 7e-7),
     + all.equal(llMC, 532.8757887, ## 32 bit: 551.8439
     + tol = if(isSun || isMac || is32) 0.05 else 7e-7)
     + )
     Error: llGG1 and 177.452426 are not equal:
     Mean relative difference: 0.0742465
     Execution halted
Flavor: r-devel-linux-x86_64-fedora-gcc

Version: 0.999-19
Flags: --no-vignettes
Check: installed package size
Result: NOTE
     installed size is 9.2Mb
     sub-directories of 1Mb or more:
     R 2.1Mb
     doc 5.0Mb
Flavors: r-devel-windows-ix86+x86_64, r-release-windows-ix86+x86_64, r-oldrel-windows-ix86+x86_64

Version: 0.999-19
Flags: --no-vignettes
Check: running tests for arch ‘i386’
Result: ERROR
     Running 'Stirling-etc.R' [6s]
     Running 'copula-play.R' [27s]
     Running 'dC-dc-ex.R' [4s]
     Running 'estim-ex.R' [8s]
     Running 'explicitCop-ex.R' [20s]
     Running 'fitting-ex.R' [12s]
     Running 'fixedPar-ex.R' [11s]
     Running 'ggraph-tst.R' [11s]
     Running 'khoudraji-ex.R' [22s]
     Running 'misc.R' [3s]
     Running 'mixCop-tst.R' [3s]
     Running 'moments.R' [3s]
     Running 'nac-experi.R' [20s]
     Running 'retstable-ex.R' [4s]
     Running 'rstable-ex.R' [7s]
     Running 'tail-pcopula.R' [3s]
     Comparing 'tail-pcopula.Rout' to 'tail-pcopula.Rout.save' ... OK
    Running the tests in 'tests/fitting-ex.R' failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.31 0 0.31
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.02 0 0.02
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581863, sd = -1.26949880218925) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581863, sd = -1.26949880218925) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200550716) : NaNs produced
     4: In dexp(x, rate = -0.813186200550716) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 4.65 0.01 4.68
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Warning messages:
     1: In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     2: In fitCopula.ml(copula, u = data, method = method, start = start, :
     Hessian matrix not invertible: system is computationally singular: reciprocal condition number = 0
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.26 0.06 0.32
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0 0 0
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
Flavor: r-devel-windows-ix86+x86_64

Version: 0.999-19
Flags: --no-vignettes
Check: running tests for arch ‘x64’
Result: ERROR
     Running 'Stirling-etc.R' [7s]
     Running 'copula-play.R' [28s]
     Running 'dC-dc-ex.R' [5s]
     Running 'estim-ex.R' [8s]
     Running 'explicitCop-ex.R' [22s]
     Running 'fitting-ex.R' [10s]
     Running 'fixedPar-ex.R' [10s]
     Running 'ggraph-tst.R' [11s]
     Running 'khoudraji-ex.R' [20s]
     Running 'misc.R' [2s]
     Running 'mixCop-tst.R' [2s]
     Running 'moments.R' [3s]
     Running 'nac-experi.R' [16s]
     Running 'retstable-ex.R' [4s]
     Running 'rstable-ex.R' [5s]
     Running 'tail-pcopula.R' [2s]
     Comparing 'tail-pcopula.Rout' to 'tail-pcopula.Rout.save' ... OK
    Running the tests in 'tests/fitting-ex.R' failed.
    Complete output:
     > ## Copyright (C) 2012 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     >
     > require(copula)
     Loading required package: copula
     > source(system.file("Rsource", "tstFit-fn.R", package="copula", mustWork=TRUE))
     > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE))
     Loading required package: tools
     > ##-> assertError(), assert.EQ(), ... showProc.time()
     >
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     >
     > uu <- array(c(9, 7, 8, 3, 2, 4, 1, 5, 6, 10,
     + 6, 9, 1, 7, 3, 2, 5, 8, 4, 10), dim = c(10L, 2L)) / 11
     > set.seed(7)
     > u3 <- cbind(uu, round(runif(10),2))
     >
     > ### t-copula instead of normal -- minimal set for testing here:
     > ## d = 2
     > ## fit1() here catches the error: "irho" not available for "tCopula":
     > (f1 <- fit1(tCopula(df.fixed=TRUE), x = uu))
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     est se
     itau 0.3746066 0.3867052
     irho NA NA
     mpl 0.4551169 0.4190495
     ml 0.4551169 0.3094090
     > stopifnot(identical(f1, fit1(tCopula(df.fixed=TRUE),
     + x = data.frame(uu))))# *WITH* a warning
     Caught fitCopula() error: 'unable to find an inherited method for function 'iRho' for signature '"tCopula"''
     *-*-*
     Warning message:
     In .local(copula, data, ...) : coercing 'data' to a matrix.
     > ## did not work with data.frame before 2012-08-12
     >
     > ## for df.fixed=FALSE, have 2 parameters ==> cannot use "fit1":
     > (f2.t <- fitCopula(tCopula(), uu, method="itau"))# (+ warning: ... 'df.fixed=TRUE' )
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 2-dimensional observations.
     Copula: tCopula
     rho.1
     0.3746
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > tools::assertError( ## 14.Jan.2016: irho(<tCopula>) has been "non-sense" -> now erronous:
     + fitCopula(tCopula(), uu, method="irho"))
     > showProc.time()
     Time elapsed: 0.33 0 0.32
     > if(doExtras) {
     + print(f2.m <- fitCopula(tCopula(), uu, method= "ml"))
     + print(f2.M <- fitCopula(tCopula(), uu, method= "mpl"))
     + print(summary(f2.m)) # gives SE for 'df' {from optim()}
     + print(summary(f2.M)) # no SE for 'df' (for now ..)
     + stopifnot(all.equal(coef(f2.m), coef(f2.M)))
     + showProc.time()
     + }
     >
     > ## d = 3 : -------------
     > ## ok with df.fixed
     > tC3f <- tCopula(dim=3, dispstr="un", df.fixed=TRUE)
     > tC3 <- tCopula(dim=3, dispstr="un")
     > f3 <- fitCopula(tC3f, u3, method="itau")
     > f3.t <- fitCopula(tC3 , u3, method="itau") # warning: coercing to df.fixed=TRUE
     Warning message:
     In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, :
     "itau" fitting ==> copula coerced to 'df.fixed=TRUE'
     > summary(f3.t)
     Call: fitCopula(copula, data = data, method = "itau")
     Fit based on "inversion of Kendall's tau" and 10 3-dimensional observations.
     t-copula, dim. d = 3
     Estimate Std. Error
     rho.1 0.3746 0.387
     rho.2 0.3090 0.326
     rho.3 0.3746 0.405
     > cf3 <- coef(f3, SE = TRUE)
     > stopifnot(all.equal(unname(cf3), cbind(c(0.374607, 0.309017, 0.374607),
     + c(0.386705, 0.325995, 0.405493)),
     + tol = 5e-5), # seen 6e-7
     + all.equal(coef(f3), coef(f3.t)))
     > if(FALSE) ## Error: iRho() method for class "tCopula" not yet implemented
     + (f3.r <- fitCopula(tC3, u3, method="irho"))
     > showProc.time()
     Time elapsed: 0.02 0 0.02
     >
     > if(doExtras) {
     + print(f3.m <- fitCopula(tC3, u3, method= "ml")); c.m <- coef(f3.m, SE=TRUE)
     + print(f3.M <- fitCopula(tC3, u3, method= "mpl")); c.M <- coef(f3.M, SE=TRUE)
     + showProc.time()
     + stopifnot(all.equal(c.m[,1], c.M[,1])) # the estimates don't differ; the SE's do
     + }
     >
     > set.seed(17)
     > d <- 5 # dimension
     > nu <- 4 # degrees of freedom
     > ## define and sample the copula, build pseudo-observations
     > ec4 <- tCopula(dim=d, df=nu, df.fixed=TRUE) # <- copula with param NA
     > (r <- iTau(ec4, tau <- c(0.2, 0.4, 0.6)))
     [1] 0.3090170 0.5877853 0.8090170
     > P <- c(r[2], r[1], r[1], r[1], # upper triangle (w/o diagonal) of corr.matrix
     + r[1], r[1], r[1],
     + r[3], r[3],
     + r[3])
     > assertError( setTheta(ec4, value = P) )
     > validObject(ex4. <- setTheta(ec4, value = 0.8)) # set the only (non-fixed) parameter
     [1] TRUE
     > ## TODO "check" getTheta(ex4., ...)
     > ## rather need "un" dispersion: Now with smarter tCopula():
     > (uc4 <- tCopula(dim=d, df=nu, disp = "un", df.fixed=FALSE))
     t-copula, dim. d = 5
     Dimension: 5
     Parameters:
     rho.1 = NA
     rho.2 = NA
     rho.3 = NA
     rho.4 = NA
     rho.5 = NA
     rho.6 = NA
     rho.7 = NA
     rho.8 = NA
     rho.9 = NA
     rho.10 = NA
     df = 4
     dispstr: un
     > validObject(uc4p <- setTheta(uc4, value = c(P, df=nu)))
     [1] TRUE
     > U. <- pobs(rCopula(n=1000, copula=uc4p))
     > splom2(U.) # => now correct dependency
     > (cU <- cor(U., method="kendall")) # => correct:
     [,1] [,2] [,3] [,4] [,5]
     [1,] 1.0000000 0.4271471 0.2095616 0.2245806 0.1969489
     [2,] 0.4271471 1.0000000 0.2114194 0.2064505 0.2156076
     [3,] 0.2095616 0.2114194 1.0000000 0.6196877 0.6062623
     [4,] 0.2245806 0.2064505 0.6196877 1.0000000 0.6062422
     [5,] 0.1969489 0.2156076 0.6062623 0.6062422 1.0000000
     > stopifnot(cor(P, cU[lower.tri(cU)]) > 0.99)
     >
     > ## Fitting a t-copula with "itau.mpl" with disp="un"
     > (fm4u <- fitCopula(uc4, U., method="itau.mpl", traceOpt = TRUE))
     1/nu= 12.2229124 => nu= 0.0818; logL= -35081.013
     1/nu= 19.7770876 => nu= 0.0506; logL= -62822.427
     1/nu= 7.55417528 => nu= 0.1324; logL= -18580.952
     1/nu= 4.66873708 => nu= 0.2142; logL= -8976.378
     1/nu= 2.8854382 => nu= 0.3466; logL= -3558.4793
     1/nu= 1.78329888 => nu= 0.5608; logL= -640.42313
     1/nu= 1.10213932 => nu= 0.9073; logL= 819.01527
     1/nu= 0.68115956 => nu= 1.4681; logL= 1462.6807
     1/nu= 0.42097976 => nu= 2.3754; logL= 1689.1506
     1/nu= 0.100898586 => nu= 9.9109; logL= 1677.214
     1/nu= 0.29871963 => nu= 3.3476; logL= 1730.6775
     1/nu= 0.270724479 => nu= 3.6938; logL= 1733.1412
     1/nu= 0.258450766 => nu= 3.8692; logL= 1733.3212
     1/nu= 0.260560314 => nu= 3.8379; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     1/nu= 0.260610172 => nu= 3.8371; logL= 1733.3302
     1/nu= 0.26069156 => nu= 3.8360; logL= 1733.3302
     1/nu= 0.260650866 => nu= 3.8365; logL= 1733.3302
     Call: fitCopula(copula, data = data, method = "itau.mpl", traceOpt = TRUE)
     Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 1000 5-dimensional observations.
     Copula: tCopula
     rho.1 rho.2 rho.3 rho.4 rho.5 rho.6 rho.7 rho.8 rho.9 rho.10 df
     0.6217 0.3233 0.3455 0.3045 0.3260 0.3186 0.3322 0.8268 0.8148 0.8147 3.8365
     The maximized loglikelihood is 1733
     Optimization converged
     > ## Fitting t-copulas ............. with disp = "ex" and "ar" :
     > uc4.ex <- tCopula(dim=d, df=nu, disp = "ex", df.fixed=FALSE)
     > uc4.ar <- tCopula(dim=d, df=nu, disp = "ar1", df.fixed=FALSE)
     > validObject(uc4p.ex <- setTheta(uc4.ex, value = c(0.75, df=nu)))
     [1] TRUE
     > validObject(uc4p.ar <- setTheta(uc4.ar, value = c(0.75, df=nu)))
     [1] TRUE
     > U.ex <- pobs(rCopula(n=1000, copula=uc4p.ex))
     > U.ar <- pobs(rCopula(n=1000, copula=uc4p.ar))
     > if(FALSE) { # The following are not available (yet); see ~/R/fitCopula.R
     + ## Fitting a t-copula with "itau.mpl" with disp="ex"
     + (fm4e <- fitCopula(uc4.ex, U.ex, method="itau.mpl"))
     + ## Fitting a t-copula with "itau.mpl" with disp="ar"
     + (fm4e <- fitCopula(uc4.ar, U.ar, method="itau.mpl"))
     + }
     >
     > ## Extra checks --------------------------------------------------------
     > if(doExtras) { ## Typically not run on R CMD check
     + tCop <- tCopula(c(0.2,0.4,0.6), dim=3, dispstr="un", df=5)
     + set.seed(101)
     + x <- rCopula(n=200, tCop) # "true" observations (simulated)
     + ## Maximum likelihood (start = (rho[1:3], df))
     + print(summary(tc.ml <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml",
     + start=c(0,0,0, 10))))
     + print(summary(tc.ml. <-
     + fitCopula(tCopula(dim=3, dispstr="un"), x, method="ml")))# w/o 'start'
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + u <- pobs(x)
     + print(tc.mpl <- fitCopula(tCopula(dim=3, dispstr="un"),
     + u, method="mpl", estimate.variance=FALSE,
     + start= c(0,0,0,10)))
     + ## Without 'start'
     + tc.mp. <- fitCopula(tCopula(dim=3, dispstr="un"), x, estimate.variance=FALSE)
     + print(tc.mp.)
     + noC <- function(x) { x@fitting.stats$counts <- NULL; x@call <- quote(dummy()); x }
     +
     + assert.EQ(noC(tc.ml) , noC(tc.ml.), tol= .005) # nothing
     + assert.EQ(noC(tc.mpl), noC(tc.mp.), tol= .100, giveRE=TRUE) # shows diff
     +
     + ## The same t copula but with df.fixed=TRUE (=> use the same data!)
     + tC3u5 <- tCopula(dim=3, dispstr="un", df=5, df.fixed=TRUE)
     + ## Maximum likelihood (start = rho[1:3])
     + print(tcF.ml <- fitCopula(tC3u5, x, method="ml", start=c(0,0,0)))
     + print(tcF.ml. <- fitCopula(tC3u5, x, method="ml")) # without 'start'
     + assert.EQ(noC(tcF.ml), noC(tcF.ml.), tol= 4e-4)
     + print(vcov(tcF.ml)) # the (estimated, asymptotic) var-cov matrix
     +
     + ## Maximum pseudo-likelihood (the asymptotic variance cannot be estimated)
     + print(tcF.mpl <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE,
     + start=c(0,0,0)))
     + print(tcF.mp. <- fitCopula(tC3u5, u, method="mpl", estimate.variance=FALSE))
     + assert.EQ(noC(tcF.mpl), noC(tcF.mp.), tol = 1e-5)
     + } # end Xtras
     >
     > ## fitMvdc() -- first 2 D -- from Yiyun Shou's bug report: ---------------------
     >
     > ct.2 <- tCopula(param=0.2, dim=2, dispstr = "ex", df.fixed=TRUE)
     > mvt.2.ne <- mvdc(copula = ct.2, margins = c("norm", "exp"),
     + paramMargins = list(list(mean = 0, sd = 2), list(rate = 2)))
     > mvt.2.ne ## --> four free parameters in total: rho, mean, sd, and rate:
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     t-copula, dim. d = 2
     Dimension: 2
     Parameters (partly fixed, see ':='):
     rho.1 = 0.2
     df := 4.0
     @ margins:
     [1] "norm" "exp"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ mean: num 0
     ..$ sd : num 2
     $ :List of 1
     ..$ rate: num 2
     >
     > copula:::getTheta(mvt.2.ne, attr = TRUE) # - shows only the copula parameter -- FIXME !
     rho.1
     0.2
     attr(,"param.lowbnd")
     [1] -1
     attr(,"param.upbnd")
     [1] 1
     >
     > ## simulate data and fit:
     > set.seed(17); x.samp <- rMvdc(250, mvt.2.ne)
     > fit2ne <- fitMvdc(x.samp, mvt.2.ne, start= c(1,1,1, rho = 0.5),
     + optim.control = list(trace = TRUE, maxit = 2000), hideWarnings=FALSE)
     initial value 1126.329900
     iter 10 value 600.190021
     final value 599.478902
     converged
     initial value 599.478902
     final value 599.478902
     stopped after 1 iterations
     Warning messages:
     1: In pnorm(x, mean = -15.6081823581344, sd = -1.26949880219363) :
     NaNs produced
     2: In dnorm(x, mean = -15.6081823581344, sd = -1.26949880219363) :
     NaNs produced
     3: In pexp(x, rate = -0.813186200556062) : NaNs produced
     4: In dexp(x, rate = -0.813186200556062) : NaNs produced
     > summary(fit2ne)
     Call: fitMvdc(data = x.samp, mvdc = mvt.2.ne, start = c(1, 1, 1, rho = 0.5),
     optim.control = list(trace = TRUE, maxit = 2000), hideWarnings = FALSE)
     Maximum Likelihood estimation based on 250 2-dimensional observations.
     Copula: tCopula
     Margin 1 :
     Estimate Std. Error
     m1.mean 0.06136 0.125
     m1.sd 2.07694 0.087
     Margin 2 :
     Estimate Std. Error
     m2.rate 2.044 0.123
     t-copula, dim. d = 2
     Estimate Std. Error
     rho.1 0.1507 0.071
     The maximized loglikelihood is -599.5
     Optimization converged
     Number of loglikelihood evaluations:
     function gradient
     54 17
     > (confint(fit2ne) -> ci.2ne)
     2.5 % 97.5 %
     m1.mean -0.18308752 0.3058066
     m1.sd 1.90644157 2.2474430
     m2.rate 1.80186646 2.2857210
     rho.1 0.01228649 0.2891935
     > stopifnot(
     + all.equal(coef(fit2ne),
     + c(m1.mean=0.061359521, m1.sd=2.0769423,
     + m2.rate=2.0437937, rho.1 = 0.15074002), tol=1e-7)# seen 1.48e-8
     + ,
     + all.equal(c(ci.2ne),
     + c(-0.18309, 1.9064, 1.8019, 0.012286,
     + 0.30581, 2.2474, 2.2857, 0.28919), tol = 4e-4) # seen 1.65e-5
     + )
     >
     >
     > <0c>
     > ### Fitting multivariate incl margins --- mvdc --------------------------------------
     > ### ===========================================
     >
     > set.seed(121)
     > gumbelC <- gumbelCopula(3, dim=2)
     > gMvGam <- mvdc(gumbelC, c("gamma","gamma"), param = list(list(2,3), list(4,1)))
     > gMvGam # now nicely show()s -- the *AUTO*-constructed parameter names
     Multivariate Distribution Copula based ("mvdc")
     @ copula:
     Gumbel copula, dim. d = 2
     Dimension: 2
     Parameters:
     alpha = 3
     @ margins:
     [1] "gamma" "gamma"
     with 2 (not identical) margins; with parameters (@ paramMargins)
     List of 2
     $ :List of 2
     ..$ shape: num 2
     ..$ rate : num 3
     $ :List of 2
     ..$ shape: num 4
     ..$ rate : num 1
     > stopifnot(identical(gMvGam@paramMargins,
     + list(list(shape = 2, rate = 3),
     + list(shape = 4, rate = 1))))
     > X <- rMvdc(16000, gMvGam)
     > smoothScatter(X, main = "rMvdc(1600, gMvGam)")
     >
     > persp (gMvGam, dMvdc, xlim = c(0,4), ylim=c(0,8)) ## almost discrete ????
     > contour(gMvGam, dMvdc, xlim = c(0,2), ylim=c(0,8))
     > points(X, pch = ".", cex = 2, col=adjustcolor("blue", 0.5))
     >
     > if(doExtras) {
     + st <- system.time(
     + fMv <- fitMvdc(X, gMvGam, start = c(1,1,1,1, 1.3),# method="BFGS",
     + optim.control= list(trace=TRUE)))
     + print(st) # ~ 59 sec. (lynne 2015)
     + print(summary(fMv))
     + }
     >
     > pFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + pnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > dFoo <- function(x, lower.tail=TRUE, log.p=FALSE)
     + 1/20* dnorm((x - 5)/20, lower.tail=lower.tail, log.p=log.p)
     > qFoo <- qunif # must exist; not used for fitting
     >
     > ## 'Foo' distribution has *no* parameters:
     > mv1 <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list()))
     > validObject(mv1)
     [1] TRUE
     > stopifnot(nrow(R <- rMvdc(3, mv1)) == 3, ncol(R) == 2)
     > ## a wrong way:
     > assertError(
     + mvW <- mvdc(gumbelC, c("gamma","Foo"), param= list(list(3,1), list(NULL)))
     + )
     > ## must not valid: stopifnot(!isTRUE(validObject(mvW, test=TRUE)))
     >
     > showProc.time()
     Time elapsed: 3.68 0.05 3.74
     >
     > ## An example which fails (and should)? --
     > ## From: Suzanne Li @...queensu.ca, Date: Fri, 9 Aug 2013
     > gumbel <- archmCopula(family = "gumbel",dim = 2)
     >
     > set.seed(47)# MM {not important, but still want sure reproducibility}
     > u <- cbind(runif(10),runif(10))
     > cor(u[,1], u[,2], method="kendall")
     [1] -0.02222222
     > ## [1] -0.02222222 -- slightly negative
     > ## this now gives an error:
     > try(fgu <- fitCopula(gumbel, u, method = "ml"))
     Error in optim(fit$par, logL, lower = lower, upper = upper, method = optim.method, :
     non-finite finite-difference value [1]
     In addition: Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## Error in optim(start, loglikCopula, lower = lower, upper = upper, method = method, :
     > ## non-finite finite-difference value [1]
     > ## In addition: Warning message:
     > ## In .local(copula, tau, ...) : tau is out of the range [0, 1]
     > copGumbel@paraInterval # -> [1, Inf) = exp([0, Inf))
     'interval' object [1, Inf)
     > par <- 2^c((0:32)/16, 2+(1:10)/8)
     > llg <- sapply(par, function(p) loglikCopula(param=p, u=u, copula=gumbel))
     > if(dev.interactive()) plot(par, llg, type="b", col=2)
     > stopifnot(diff(llg) < 0) # so the maximum is for par = 2^0 = 1 --> at *boundary* of interval
     > ## FIXME -- "ml" should return the boundary case, or a much better error message
     > ## These work (with a warning {which is interesting, but maybe should not be a warning}
     > ## "perfectly": They give the correct boundary case:
     > fg.itau <- fitCopula(gumbel, u, method = "itau")
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > fg.irho <- fitCopula(gumbel, u, method = "irho")
     Warning message:
     In .local(copula, rho, ...) :
     For the Gumbel copula, rho must be >= 0. Replacing negative values by 0.
     >
     > ## Is it just this problem?
     > ## well, the likelihood was not ok for large param=theta; now is:
     > lrgP <- 100*seq(8, 100, by = 3)
     > llrg <- vapply(lrgP, function(P) loglikCopula(param=P, u=u, copula=gumbel), NA_real_)
     > stopifnot(is.finite(llrg), diff(llrg) < 0, llrg < -11990)## no longer NaN
     > if(FALSE)
     + plot(lrgP, llrg, type="b", col=2) ## all fine
     >
     > ## Now is it because we *really* should use elme() and the "nacopula" families?
     > ## No, this fails too: "outside interval" error {instead of just -Inf !}:
     > (copG <- onacopulaL("Gumbel", list(NaN,1:2)))
     Nested Archimedean copula ("outer_nacopula" of dim. 2), with slot
     'comp' = (1, 2) and root
     'copula' = Archimedean copula ("acopula"), family "Gumbel"
     and *no* child copulas
     > ## Estimation -> error for now -- (FIXME!)
     > try(efm <- emle(u, copG))
     Error in cop@copula@dacopula(u, theta, n.MC = n.MC, log = TRUE) :
     theta is outside its defined interval
     In addition: Warning message:
     In initOpt(cop@copula@name, interval = FALSE, u = u) :
     initOpt: DMLE for Gumbel = 0.729065443212314 < 1; is set to 1
     Warning message:
     In bbmle::mle2(minuslogl = nLL, optimizer = "optimize", lower = interval[1], :
     couldn't invert Hessian
     >
     >
     > ## A simple example with *negative* correlation;
     > ## Want *more helpful* error message here:
     > set.seed(7)
     > u1 <- seq(0,1, by=1/128)[2:127]; u2 <- -u1 + round(rnorm(u1)/4,2); u <- pobs(cbind(u1,u2))
     > plot(u)
     > msg <- tryCatch(fitCopula(gumbelCopula(), data = u), error=function(e)e$message)
     Warning message:
     In .local(copula, tau, ...) :
     For the Gumbel copula, tau must be >= 0. Replacing negative values by 0.
     > ## check error message __FIXME__ want "negative correlation not possible"
     > ## or NO ERROR and a best fit to tau=0 [and the same for other Archimedean families!]
     > msg
     Call: fitCopula(copula, data = data)
     Fit based on "maximum pseudo-likelihood" and 126 2-dimensional observations.
     Copula: gumbelCopula
     alpha
     1
     The maximized loglikelihood is -1.783e-06
     Optimization converged
     > showProc.time()
     Time elapsed: 0.29 0 0.3
     >
     > <0c>
     > ## Date: Sat, 14 Nov 2015 20:21:27 -0500
     > ## Subject: Replace makePosDef() by nearPD()?
     > ## From: Marius Hofert <marius.hofert@uwaterloo.ca>
     > ## To: Ivan Kojadinovic <ivan.kojadinovic@univ-pau.fr>, Jun Yan
     > ## <jun.yan@uconn.edu>, Martin Maechler <maechler@stat.math.ethz.ch>
     >
     > ## I currently face the problem of estimating a t-copula to a (504, 413)
     > ## data matrix. A MWE is:
     >
     > require(copula)
     > set.seed(271)
     > n <- 504
     > d <- 413
     > d <- 50 # more realistic -- should become faster !!
     > U <- matrix(runif(n*d), nrow=n, ncol=d)
     > if(FALSE) ## takes ??? (> one hour)
     + ## try maxiter = / trace = to see what's happening
     + system.time(fit <- fitCopula(ellipCopula("t", dim=d, dispstr="un"),
     + data=U, method="mpl"))
     >
     >
     > ## > Warning in makePosDef(sigma, delta = 0.001) :
     > ## > Estimate is not positive-definite. Correction applied.
     > ## > Process R killed: 9 at Sat Nov 14 19:48:55 2015
     > 1
     [1] 1
     > ## ... so R crashes (this also happens if the data is much 'closer' to a
     > ## t-copula than my data above, so that's not the problem). I'm wondering
     > ## about the following.
     > showProc.time()
     Time elapsed: 0 0 0
     >
     > ## 4) Implement: first estimating (via pairwise inversion of
     > ## Kendall's tau) the dispersion matrix and then estimating the d.o.f.
     > ## via MLE (based on the fitted dispersion matrix). Already in use in
     > ## vignettes --- would be good to have this in the
     > ## package as. What we could do is to extend
     > ## fitCopula.icor(, method="kendall"): if the copula has a d.o.f. parameter, then don't
     > ## treat it as fixed but estimated it via MLE... (or to get this behavior
     > ## via a method argument or so?)
     >
     > ## 6) After 4), lambda() returns a vector of length 2* d(d-1)/2 ... ok
     > ## in the bivariate case but not in higher dimensions => want a list
     >
     > ###----------- xvCopula() [ <--> ../man/xvCopula.Rd ] ---------
     > set.seed(12)
     > x <- rCopula(64, claytonCopula(pi))# "small" n ==> fast
     > fG <- fitCopula(gumbelCopula(), x)
     > (v <- c(logL = logLik(fG),
     + xv.loo = xvCopula(gumbelCopula(), x ), # l.o.o. CV
     + xv.5 = xvCopula(gumbelCopula(), x, k = 5)))# 5-fold CV
     logL xv.loo xv.5
     32.78368 32.83574 31.88961
     > stopifnot(all.equal(unname(v), c(32.783677, 32.835744, 32.247463),
     + tolerance = 1e-7))
     Error: unname(v) and c(32.783677, 32.835744, 32.247463) are not equal:
     Mean relative difference: 0.003669975
     Execution halted
    Running the tests in 'tests/mixCop-tst.R' failed.
    Complete output:
     > ## Copyright (C) 2016 Marius Hofert, Ivan Kojadinovic, Martin Maechler, and Jun Yan
     > ##
     > ## This program is free software; you can redistribute it and/or modify it under
     > ## the terms of the GNU General Public License as published by the Free Software
     > ## Foundation; either version 3 of the License, or (at your option) any later
     > ## version.
     > ##
     > ## This program is distributed in the hope that it will be useful, but WITHOUT
     > ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     > ## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     > ## details.
     > ##
     > ## You should have received a copy of the GNU General Public License along with
     > ## this program; if not, see <http://www.gnu.org/licenses/>.
     >
     > ### Finite Mixtures of Copulas: mixCopula()
     > ### ========================================
     >
     > library(copula)
     > isExplicit <- copula:::isExplicit
     > (doExtras <- copula:::doExtras())
     [1] FALSE
     >
     > is32 <- .Machine$sizeof.pointer == 4 ## <- should work for Linux/MacOS/Windows
     > isMac <- Sys.info()[["sysname"]] == "Darwin"
     > isSun <- Sys.info()[["sysname"]] == "SunOS"
     >
     > mC <- mixCopula(list(gumbelCopula(2.5, dim=3),
     + claytonCopula(pi, dim=3),
     + tCopula(0.7, dim=3)),
     + c(2,2,4)/8)
     > mC
     mixCopula from 3 components
     (Gmbc, Clyc, t-cp) with weights:
     (0.25, 0.25, 0.50)
     Dimension: 3
     Parameters:
     m1.alpha = 2.500000
     m2.alpha = 3.141593
     m3.rho.1 = 0.700000
     m3.df = 4.000000
     w1 = 0.250000
     w2 = 0.250000
     w3 = 0.500000
     > stopifnot(dim(mC) == 3, inherits(mC, "mixCopula"))
     >
     > ## mix a Gumbel with a rotated Gumbel (with equal weights 1/2):
     > mGG <- mixCopula(list(gumbelCopula(2), rotCopula(gumbelCopula(1.5))))
     > stopifnot(dim(mGG) == 2, inherits(mGG, "mixCopula"),
     + all.equal( rho(mGG), 0.57886340158, tol=1e-10) ,
     + all.equal(lambda(mGG), c(lower = 0.206299474016,
     + upper = 0.292893218813), tol = 1e-10)
     + )
     > mGG # 4 parameters
     mixCopula from 2 components
     (Gmbc , RccfGc) with weights:
     (0.5, 0.5)
     Dimension: 2
     Parameters:
     m1.alpha = 2.0
     m2.alpha = 1.5
     w1 = 0.5
     w2 = 0.5
     >
     > set.seed(17)
     > uM <- rCopula( 600, mC)
     > uGG <- rCopula(1000, mGG)
     > ## Check dCopula(*, log= TRUE) ## --- this was __wrong__ for many days (not on CRAN)
     > stopifnot(
     + length(dCopula(uM[1,,drop=FALSE], mC, log=TRUE)) == 1,# was wrong
     + all.equal(log(dCopula(uM, mC)),
     + dCopula(uM, mC, log=TRUE), tol = 1e-12),
     + all.equal(log(dCopula(uGG, mGG)),
     + dCopula(uGG, mGG, log=TRUE), tol = 1e-12)
     + )
     > (llGG1 <- loglikCopula(c(2.5, 1., w = c(2,4)/6), u=uGG, copula = mGG))
     [1] 165.1878
     > (llMC <- loglikCopula(c(2.5, pi, rho.1=0.7, df = 4, w = c(2,2,4)/8), u = uM, copula = mC))
     [1] 532.8758
     > ## discrepancy 32 bit <-> 64 bit --- still (after dMixCopula() bug fix):
     > stopifnot(
     + all.equal(llGG1, 177.452426, ## 32 bit (Windows, Linux(FC 24)): 188.0358
     + tol = if(isSun || isMac || is32) 0.08 else 7e-7),
     + all.equal(llMC, 532.8757887, ## 32 bit: 551.8439
     + tol = if(isSun || isMac || is32) 0.05 else 7e-7)
     + )
     Error: llGG1 and 177.452426 are not equal:
     Mean relative difference: 0.0742465
     Execution halted
Flavor: r-devel-windows-ix86+x86_64

Version: 0.999-19
Flags: --no-vignettes
Check: for code/documentation mismatches
Result: WARN
    Functions or methods with usage in documentation object 'gasoil' but not in code:
     data
    
    Functions or methods with usage in documentation object 'loss' but not in code:
     data
    
    Functions or methods with usage in documentation object 'rdj' but not in code:
     data
    
    Functions or methods with usage in documentation object 'uranium' but not in code:
     data
Flavor: r-oldrel-windows-ix86+x86_64

Version: 0.999-19
Flags: --no-vignettes
Check: Rd \usage sections
Result: WARN
    Undocumented arguments in documentation object 'gasoil'
     'gasoil' 'package'
    Objects in \usage without \alias in documentation object 'gasoil':
     'data'
    
    Undocumented arguments in documentation object 'loss'
     'loss' 'package'
    Objects in \usage without \alias in documentation object 'loss':
     'data'
    
    Undocumented arguments in documentation object 'rdj'
     'rdj' 'package'
    Objects in \usage without \alias in documentation object 'rdj':
     'data'
    
    Undocumented arguments in documentation object 'uranium'
     'uranium' 'package'
    Objects in \usage without \alias in documentation object 'uranium':
     'data'
    
    Functions with \usage entries need to have the appropriate \alias
    entries, and all their arguments documented.
    The \usage entries must correspond to syntactically valid R code.
    See chapter 'Writing R documentation files' in the 'Writing R
    Extensions' manual.
Flavor: r-oldrel-windows-ix86+x86_64

Version: 0.999-19
Check: for code/documentation mismatches
Result: WARN
    Functions or methods with usage in documentation object 'gasoil' but not in code:
     data
    
    Functions or methods with usage in documentation object 'loss' but not in code:
     data
    
    Functions or methods with usage in documentation object 'rdj' but not in code:
     data
    
    Functions or methods with usage in documentation object 'uranium' but not in code:
     data
Flavor: r-oldrel-osx-x86_64

Version: 0.999-19
Check: Rd \usage sections
Result: WARN
    Undocumented arguments in documentation object 'gasoil'
     ‘gasoil’ ‘package’
    Objects in \usage without \alias in documentation object 'gasoil':
     ‘data’
    
    Undocumented arguments in documentation object 'loss'
     ‘loss’ ‘package’
    Objects in \usage without \alias in documentation object 'loss':
     ‘data’
    
    Undocumented arguments in documentation object 'rdj'
     ‘rdj’ ‘package’
    Objects in \usage without \alias in documentation object 'rdj':
     ‘data’
    
    Undocumented arguments in documentation object 'uranium'
     ‘uranium’ ‘package’
    Objects in \usage without \alias in documentation object 'uranium':
     ‘data’
    
    Functions with \usage entries need to have the appropriate \alias
    entries, and all their arguments documented.
    The \usage entries must correspond to syntactically valid R code.
    See chapter ‘Writing R documentation files’ in the ‘Writing R
    Extensions’ manual.
Flavor: r-oldrel-osx-x86_64