R Under development (unstable) (2024-08-15 r87022 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## 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 . > > require(copula) Loading required package: copula > source(system.file("Rsource", "utils.R", package="copula", mustWork=TRUE)) Loading required package: tools > ##-> assertError(), assert.EQ(), ... showProc.time() + comparederiv() > showProc.time() Time (user system elapsed): 0.01 0 0.02 > > (doExtras <- copula:::doExtras()) [1] FALSE > > > tC2.F <- tCopula(df=2, df.fixed=TRUE) > (cm <- setTheta(tC2.F, value=-0.5, freeOnly=TRUE)) ## setTheta() had failed t-copula, dim. d = 2 Dimension: 2 Parameters (partly fixed, see ':='): rho.1 = -0.5 df := 2.0 > (cp <- setTheta(tC2.F, value= 0.5, freeOnly=TRUE)) t-copula, dim. d = 2 Dimension: 2 Parameters (partly fixed, see ':='): rho.1 = 0.5 df := 2.0 > (c2 <- setTheta(tC2.F, value=c(0.5,3), freeOnly=FALSE)) ## had failed t-copula, dim. d = 2 Dimension: 2 Parameters (partly fixed, see ':='): rho.1 = 0.5 df := 3.0 > stopifnot(all.equal(getTheta(cm), -0.5), all.equal(getTheta(cp), +0.5), + all.equal(getTheta(cm, freeOnly=FALSE, named=TRUE), + c(rho.1 = -0.5, df = 2)), + all.equal(getTheta(cp, freeOnly=FALSE), c(0.5, 2)), + all.equal(getTheta(c2, freeOnly=FALSE, named=TRUE), + c(rho.1 = 0.5, df = 3))) > > (N3 <- normalCopula(c(0.5,0.3,0.2), dim=3, dispstr = "un")) Normal copula, dim. d = 3 Dimension: 3 Parameters: rho.1 = 0.5 rho.2 = 0.3 rho.3 = 0.2 dispstr: un > fixedParam(N3) <- c(TRUE, FALSE, FALSE); N3 Normal copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.3 rho.3 = 0.2 dispstr: un > (N3.2 <- setTheta(N3, c( 0.4, 0.2) -> t2)) # partially fixed: works since 2017-02-11 Normal copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.4 rho.3 = 0.2 dispstr: un > (N3.3 <- setTheta(N3, c(0.6, 0.4, 0.2) -> t3, freeOnly=FALSE)) Normal copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.6 rho.2 = 0.4 rho.3 = 0.2 dispstr: un > stopifnot(all.equal(getTheta(N3.2), t2), + all.equal(getTheta(N3.3), t3[-1]), + all.equal(getTheta(N3.2, freeOnly=FALSE), c(0.5, t2)), + all.equal(getTheta(N3.3, freeOnly=FALSE), t3)) > > (tC3 <- tCopula(c(0.5,0.3,0.2), dim=3, dispstr = "un")) # df = 4 is not fixed t-copula, dim. d = 3 Dimension: 3 Parameters: rho.1 = 0.5 rho.2 = 0.3 rho.3 = 0.2 df = 4.0 dispstr: un > fixedParam(tC3) <- c(TRUE, FALSE, FALSE, TRUE); tC3 #-> df fixed, too t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.3 rho.3 = 0.2 df := 4.0 dispstr: un > (tC3.2 <- setTheta(tC3, c( 0.4, 0.1) -> t2)) # partially fixed: works since 2017-02-11 t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.4 rho.3 = 0.1 df := 4.0 dispstr: un > (tC3.3 <- setTheta(tC3, c(0.6, 0.4, 0.1, 3) -> t3, freeOnly=FALSE)) t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.6 rho.2 = 0.4 rho.3 = 0.1 df := 3.0 dispstr: un > stopifnot(all.equal(getTheta(tC3.2), t2), + all.equal(getTheta(tC3.3), t3[-c(1,4)]), + all.equal(getTheta(tC3.2, freeOnly=FALSE), c(0.5, t2, 4)), + all.equal(getTheta(tC3.3, freeOnly=FALSE), t3)) > > fixedParam(tC3) <- c(TRUE, FALSE, FALSE, FALSE); tC3 # df remains free t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.3 rho.3 = 0.2 df = 4.0 dispstr: un > (tC3u.2 <- setTheta(tC3, c( 0.4, 0.2, 5) -> t2)) # partially fixed: works since 2017-02-11 t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.5 rho.2 = 0.4 rho.3 = 0.2 df = 5.0 dispstr: un > (tC3u.3 <- setTheta(tC3, c(0.6, 0.4, 0.2, 3) -> t3, freeOnly=FALSE)) t-copula, dim. d = 3 Dimension: 3 Parameters (partly fixed, see ':='): rho.1 := 0.6 rho.2 = 0.4 rho.3 = 0.2 df = 3.0 dispstr: un > stopifnot(all.equal(getTheta(tC3u.2), t2), + all.equal(getTheta(tC3u.3), t3[-1]), + all.equal(getTheta(tC3u.2, freeOnly=FALSE), c(0.5, t2)), + all.equal(getTheta(tC3u.3, freeOnly=FALSE), t3)) > > > > ### TEST FITTING ########################################################## > > n <- 100 > ## with normal copulas > nc3 <- normalCopula(dim = 3, c(.6,.3,.2), dispstr = "un") > nc3@parameters [1] 0.6 0.3 0.2 > set.seed(4521) > x <- rCopula(n, nc3) > u <- pobs(x) > > fitCopula(nc3, data = u) Call: fitCopula(nc3, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5715 0.3498 0.2391 The maximized loglikelihood is 23.6 Optimization converged > fitCopula(nc3, data = u, estimate.variance = FALSE) Call: fitCopula(nc3, data = u, ... = pairlist(estimate.variance = FALSE)) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5715 0.3498 0.2391 The maximized loglikelihood is 23.6 Optimization converged > fitCopula(nc3, data = x, method = "ml") Call: fitCopula(nc3, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5793 0.3277 0.2552 The maximized loglikelihood is 24.08 Optimization converged > fitCopula(nc3, data = x, method = "ml", estimate.variance = FALSE) Call: fitCopula(nc3, data = x, ... = pairlist(method = "ml", estimate.variance = FALSE)) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5793 0.3277 0.2552 The maximized loglikelihood is 24.08 Optimization converged > fitCopula(nc3, data = u, method = "itau") Call: fitCopula(nc3, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5697 0.3805 0.2308 > fitCopula(nc3, data = u, method = "itau", estimate.variance = FALSE) Call: fitCopula(nc3, data = u, ... = pairlist(method = "itau", estimate.variance = FALSE)) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5697 0.3805 0.2308 > fitCopula(nc3, data = u, method = "irho") Call: fitCopula(nc3, data = u, ... = pairlist(method = "irho")) Fit based on "inversion of Spearman's rho" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5780 0.3878 0.2395 > fitCopula(nc3, data = u, method = "irho", estimate.variance = FALSE) Call: fitCopula(nc3, data = u, ... = pairlist(method = "irho", estimate.variance = FALSE)) Fit based on "inversion of Spearman's rho" and 100 3-dimensional observations. Copula: normalCopula rho.1 rho.2 rho.3 0.5780 0.3878 0.2395 > > showProc.time() Time (user system elapsed): 0.36 0.03 0.39 > > nc2 <- normalCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, FALSE, FALSE)), + dispstr = "un") > nc2@parameters [1] 0.6 0.3 0.2 attr(,"fixed") [1] TRUE FALSE FALSE > > fitCopula(nc2, data = u) Call: fitCopula(nc2, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3512 0.2484 The maximized loglikelihood is 23.47 Optimization converged > fitCopula(nc2, data = u, estimate.variance = FALSE) Call: fitCopula(nc2, data = u, ... = pairlist(estimate.variance = FALSE)) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3512 0.2484 The maximized loglikelihood is 23.47 Optimization converged > fitCopula(nc2, data = x, method = "ml") Call: fitCopula(nc2, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3294 0.2607 The maximized loglikelihood is 24.01 Optimization converged > fitCopula(nc2, data = x, method = "ml", estimate.variance = FALSE) Call: fitCopula(nc2, data = x, ... = pairlist(method = "ml", estimate.variance = FALSE)) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3294 0.2607 The maximized loglikelihood is 24.01 Optimization converged > fitCopula(nc2, data = u, method = "itau") Call: fitCopula(nc2, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3805 0.2308 > fitCopula(nc2, data = u, method = "itau", estimate.variance = FALSE) Call: fitCopula(nc2, data = u, ... = pairlist(method = "itau", estimate.variance = FALSE)) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3805 0.2308 > fitCopula(nc2, data = u, method = "irho") Call: fitCopula(nc2, data = u, ... = pairlist(method = "irho")) Fit based on "inversion of Spearman's rho" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3878 0.2395 > fitCopula(nc2, data = u, method = "irho", estimate.variance = FALSE) Call: fitCopula(nc2, data = u, ... = pairlist(method = "irho", estimate.variance = FALSE)) Fit based on "inversion of Spearman's rho" and 100 3-dimensional observations. Copula: normalCopula rho.2 rho.3 0.3878 0.2395 > > showProc.time() Time (user system elapsed): 0.16 0 0.16 > > > nc1 <- normalCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, TRUE, FALSE)), + dispstr = "un") > nc1@parameters [1] 0.6 0.3 0.2 attr(,"fixed") [1] TRUE TRUE FALSE > > fitCopula(nc1, data = u) Call: fitCopula(nc1, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.3 0.2164 The maximized loglikelihood is 23.31 Optimization converged > fitCopula(nc1, data = x, method = "ml") Call: fitCopula(nc1, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: normalCopula rho.3 0.2437 The maximized loglikelihood is 23.96 Optimization converged > fitCopula(nc1, data = u, method = "itau") Call: fitCopula(nc1, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: normalCopula rho.3 0.2308 > fitCopula(nc1, data = u, method = "irho") Call: fitCopula(nc1, data = u, ... = pairlist(method = "irho")) Fit based on "inversion of Spearman's rho" and 100 3-dimensional observations. Copula: normalCopula rho.3 0.2395 > > showProc.time() Time (user system elapsed): 0.06 0 0.06 > > > ## with t copulas (df.fixed = FALSE) > tc3df <- tCopula(dim = 3, c(.6,.3,.2), dispstr = "un") > tc3df@parameters [1] 0.6 0.3 0.2 4.0 attr(,"fixed") [1] FALSE FALSE FALSE FALSE > set.seed(4521) > x <- rCopula(n, tc3df) > u <- pobs(x) > fitCopula(tc3df, data = u) Call: fitCopula(tc3df, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 df 0.5878 0.4266 0.2695 6.3232 The maximized loglikelihood is 31.68 Optimization converged Warning message: In var.mpl(copula, u) : the covariance matrix of the parameter estimates is computed as if 'df.fixed = TRUE' with df = 6.32321437509388 > fitCopula(tc3df, data = x, method = "ml") Call: fitCopula(tc3df, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 df 0.6080 0.4443 0.2896 5.7102 The maximized loglikelihood is 35.56 Optimization converged > fitCopula(tc3df, data = u, method = "itau") Call: fitCopula(tc3df, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 0.5960 0.4241 0.2370 Warning message: In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, : "itau" fitting ==> copula coerced to 'df.fixed=TRUE' > fitCopula(tc3df, data = u, estimate.variance = FALSE) Call: fitCopula(tc3df, data = u, ... = pairlist(estimate.variance = FALSE)) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 df 0.5878 0.4266 0.2695 6.3232 The maximized loglikelihood is 31.68 Optimization converged > fitCopula(tc3df, data = x, method = "ml", estimate.variance = FALSE) Call: fitCopula(tc3df, data = x, ... = pairlist(method = "ml", estimate.variance = FALSE)) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 df 0.6080 0.4443 0.2896 5.7102 The maximized loglikelihood is 35.56 Optimization converged > fitCopula(tc3df, data = u, method = "itau", estimate.variance = FALSE) Call: fitCopula(tc3df, data = u, ... = pairlist(method = "itau", estimate.variance = FALSE)) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 0.5960 0.4241 0.2370 Warning message: In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, : "itau" fitting ==> copula coerced to 'df.fixed=TRUE' > fitCopula(tc3df, data = u, method = "itau.mpl") Call: fitCopula(tc3df, data = u, ... = pairlist(method = "itau.mpl")) Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 100 3-dimensional observations. Copula: tCopula rho.1 rho.2 rho.3 df 0.5960 0.4241 0.2370 6.6540 The maximized loglikelihood is 31.59 Optimization converged > > showProc.time() Time (user system elapsed): 0.86 0.01 0.87 > > > tc2df <- tCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, FALSE, FALSE)), + dispstr = "un") > tc2df@parameters [1] 0.6 0.3 0.2 4.0 attr(,"fixed") [1] TRUE FALSE FALSE FALSE > > fitCopula(tc2df, data = u) Call: fitCopula(tc2df, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 df 0.4279 0.2752 6.5069 The maximized loglikelihood is 31.66 Optimization converged Warning message: In var.mpl(copula, u) : the covariance matrix of the parameter estimates is computed as if 'df.fixed = TRUE' with df = 6.50688878741488 > fitCopula(tc2df, data = x, method = "ml") Call: fitCopula(tc2df, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 df 0.4432 0.2854 5.6182 The maximized loglikelihood is 35.55 Optimization converged > fitCopula(tc2df, data = u, method = "itau") Call: fitCopula(tc2df, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 0.4241 0.2370 Warning message: In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, : "itau" fitting ==> copula coerced to 'df.fixed=TRUE' > fitCopula(tc2df, data = u, estimate.variance = FALSE) Call: fitCopula(tc2df, data = u, ... = pairlist(estimate.variance = FALSE)) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 df 0.4279 0.2752 6.5069 The maximized loglikelihood is 31.66 Optimization converged > fitCopula(tc2df, data = x, method = "ml", estimate.variance = FALSE) Call: fitCopula(tc2df, data = x, ... = pairlist(method = "ml", estimate.variance = FALSE)) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 df 0.4432 0.2854 5.6182 The maximized loglikelihood is 35.55 Optimization converged > fitCopula(tc2df, data = u, method = "itau", estimate.variance = FALSE) Call: fitCopula(tc2df, data = u, ... = pairlist(method = "itau", estimate.variance = FALSE)) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 0.4241 0.2370 Warning message: In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, : "itau" fitting ==> copula coerced to 'df.fixed=TRUE' > fitCopula(tc2df, data = u, method = "itau.mpl") Call: fitCopula(tc2df, data = u, ... = pairlist(method = "itau.mpl")) Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 df 0.4241 0.2370 6.7515 The maximized loglikelihood is 31.57 Optimization converged > ## fitCopula(tc2df, data = u, method = "irho") > showProc.time() Time (user system elapsed): 0.56 0 0.57 > > > tc1df <- tCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, TRUE, FALSE)), + dispstr = "un") > tc1df@parameters [1] 0.6 0.3 0.2 4.0 attr(,"fixed") [1] TRUE TRUE FALSE FALSE > > fitCopula(tc1df, data = u) Call: fitCopula(tc1df, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.3 df 0.1947 5.9244 The maximized loglikelihood is 30.76 Optimization converged Warning message: In var.mpl(copula, u) : the covariance matrix of the parameter estimates is computed as if 'df.fixed = TRUE' with df = 5.924446341239 > fitCopula(tc1df, data = x, method = "ml") Call: fitCopula(tc1df, data = x, ... = pairlist(method = "ml")) Fit based on "maximum likelihood" and 100 3-dimensional observations. Copula: tCopula rho.3 df 0.2015 4.9538 The maximized loglikelihood is 34.51 Optimization converged > fitCopula(tc1df, data = u, method = "itau") Call: fitCopula(tc1df, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.3 0.237 Warning message: In fitCopula.icor(copula, x = data, method = method, estimate.variance = estimate.variance, : "itau" fitting ==> copula coerced to 'df.fixed=TRUE' > fitCopula(tc1df, data = u, method = "itau.mpl") Call: fitCopula(tc1df, data = u, ... = pairlist(method = "itau.mpl")) Fit based on "itau for dispersion matrix P and maximum likelihood for df" and 100 3-dimensional observations. Copula: tCopula rho.3 df 0.237 5.812 The maximized loglikelihood is 30.64 Optimization converged > ## fitCopula(tc1df, data = u, method = "irho") > showProc.time() Time (user system elapsed): 0.28 0.02 0.29 > > > ## with t copulas (df.fixed = TRUE) > tc2 <- tCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, FALSE, FALSE)), + dispstr = "un", df.fixed = TRUE) > tc2@parameters [1] 0.6 0.3 0.2 4.0 attr(,"fixed") [1] TRUE FALSE FALSE TRUE > > fitCopula(tc2, data = u) Call: fitCopula(tc2, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 0.4161 0.2731 The maximized loglikelihood is 31.14 Optimization converged > fitCopula(tc2, data = u, method = "itau") Call: fitCopula(tc2, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.2 rho.3 0.4241 0.2370 > ## fitCopula(tc2, data = u, method = "irho") > showProc.time() Time (user system elapsed): 0.07 0 0.07 > > > tc1 <- tCopula(dim = 3, fixParam(c(.6,.3,.2), c(TRUE, TRUE, FALSE)), + dispstr = "un", df.fixed = TRUE) > tc1@parameters [1] 0.6 0.3 0.2 4.0 attr(,"fixed") [1] TRUE TRUE FALSE TRUE > > fitCopula(tc1, data = u) Call: fitCopula(tc1, data = u) Fit based on "maximum pseudo-likelihood" and 100 3-dimensional observations. Copula: tCopula rho.3 0.199 The maximized loglikelihood is 30.4 Optimization converged > fitCopula(tc1, data = u, method = "itau") Call: fitCopula(tc1, data = u, ... = pairlist(method = "itau")) Fit based on "inversion of Kendall's tau" and 100 3-dimensional observations. Copula: tCopula rho.3 0.237 > ##fitCopula(tc1, data = u, method = "irho") > showProc.time() Time (user system elapsed): 0.04 0 0.04 > > ### TEST dC-dc functions ##################################################### > > ## d*du functions should return the same result as when unfixed > ## d*dtheta functions should return "columns" corresponding to free params > testdCdc <- function(cop, v, cop.unfixed) { + fixed <- attr(cop@parameters, "fixed") + if (.hasSlot(cop, "df.fixed")) fixed <- fixed[-length(fixed)] + stopifnot(all.equal(copula:::dCdu(cop, v), copula:::dCdu(cop.unfixed, v)), + all.equal(copula:::dCdtheta(cop, v), + copula:::dCdtheta(cop.unfixed, v)[, !fixed, drop = FALSE]), + all.equal(copula:::dlogcdu(cop, v), copula:::dlogcdu(cop.unfixed, v)), + all.equal(copula:::dlogcdtheta(cop, v), + copula:::dlogcdtheta(cop.unfixed, v)[, !fixed, drop = FALSE])) + } > > ## random points in unit cube > set.seed(7615) > v <- matrix(runif(15), 5, 3) > > ## normal > testdCdc(nc2, v, nc3) > testdCdc(nc1, v, nc3) > > ## t with df.fixed = TRUE > tc3 <- tCopula(dim = 3, c(.6,.3,.2), dispstr = "un", df.fixed = TRUE) > testdCdc(tc2, v, tc3) > testdCdc(tc1, v, tc3) > > showProc.time() Time (user system elapsed): 0.08 0 0.08 > > cD <- rbind(## comparederiv() <<-- ../inst/Rsource/utils.R + Nc2 = comparederiv(nc2, v), + Nc1 = comparederiv(nc1, v), + tc2 = comparederiv(tc2, v), + tc1 = comparederiv(tc1, v)) > cD dCdu dCdtheta dlogcdu dlogcdtheta Nc2 0.001703269 3.291936e-14 3.886333e-08 7.434494e-09 Nc1 0.001703269 3.291936e-14 3.886333e-08 6.431659e-09 tc2 0.001605088 4.199505e-14 3.426593e-08 1.102597e-08 tc1 0.001605088 4.199505e-14 3.426593e-08 1.102597e-08 > stopifnot( + cD[,"dCdu" ] < 0.3, # max: 0.2357 for 'tc2' + cD[,"dCdtheta"] < 0.2, # max: 0.1529 for 'tc2' + ## bug the dlog* are "good": + cD[,"dlogcdu" ] < 7e-8, # see 3.886e-8 for both 'Nc' + cD[,"dlogcdtheta"] < 4e-8) # max: 1.54e-8 for 'tc2' > showProc.time() Time (user system elapsed): 0.73 0.01 0.75 > > if (doExtras) {## ~ 7 secs + + ### Multiplier GOF ##################################################### + + ## check size of mult GOF test briefly + do1 <- function(n, cop) { + u <- pobs(rCopula(n, cop)) + gofCopula(cop, pobs(u), sim = "mult")$p.value + } + n <- 100 + M <- 10 #1000 + mM <- sapply(list(nc2=nc2, nc1=nc1, tc2=tc2, tc1=tc1 + ## , tc2df, tc1df + ), function(COP) mean(replicate(M, do1(n, COP)))) + print(mM) + print(mM < 0.05) + + showProc.time() + } > > > proc.time() user system elapsed 4.35 0.32 4.62