##-*- org -*-->  Emacs .. [Tab] key + [Org] menu; C-c C-o to follow links
* Very Short Term
** TODO ~/R/MM/Pkg-ex/maryamS-ex.R : negative correlation data has BAD error message
 now see FIXME in   tests/fitting-ex.R  'msg <- tryCatch(fitCopula(gumbelCopula(), ....'
** DONE fitCopula() for 2-dim tCopula() *AND* 2-dim tevCopula(); latter clearly fails
** DONE mvdc() -- fitMvdc() and generate data from fit:
 - fitMvdc()@mvdc  must contain the *fitted* parameters, the same as
   fitCopula()@copula does already.
** DONE rPosStable() is "wrong", actually just rstable1() *scaled* unusually
   --> use rstable1() [unless options(..) for back compatibility]
** DONE no longer try() in loglikCopula()
  - "hideWarnings" seems "wrong by design", there.
  - *However* fitCopula() now uses 'hideWarnings' (again): should *not*
    report warnings by default: They are too disturbing for 'Joe Average'
    fitCopula() user.
** DONE tryCatch() in loglikMvdc(), but not longer hideWarnings there.
   OTOH, hideWarnins now in fitMvdc().
** DONE timings() function name -- changed to nacFrail.time()
** DONE setTheta() bug: see tests/fitting-ex.R ..seed(17)
** DONE stopifnot(ncol(u) == (d <- copula@dimension))  *not* ok:
stopifnot(NULL == 1) is not stopping
** DONE matrix(x, ncol=.) is really slower than rbind(x, deparse.level=0L)
** DONE implement uscore for MMMH's A, C, F, G, J (note MH: haven't done any testing)
** DONE MH: in man/empcop.Rd, document 'method' "C"/"R"
* Short Term: Before 1.0.0
** TODO introduce "empiricalCopula" (or "empCopula") as new subclass of "Copula" (not "copula")
   and maybe *additionally* "empiricalDist" / "empMvdc", inheriting from
   new "Mvdc" which would contain "mvdc" and "empMvdc".
*** -> nice persp() {and maybe contour()} method via perspCopula(*, fun=C.n, ....) and
   perspMvdc(*, fun=F.n, ....). ---> man/Mvdc.Rd and R/graphics.R
** TODO print(summary(<fitCop>)) prints *less* than print(.): not R like; -> R/fitCopula.R summary.fitCopula
** TODO pCopula(u,..) and dCopula(u,..) should work for u outside [0,1]^d  & NA/NaN
*** DONE for pCopula(): using  u[] <- pmax(0, pmin(1, u))  {subtlety!}
*** DONE dCopula() = 0 {log = -Inf} for u "outside"
*** TODO both should keep NA & NaN. Maybe keep them different, as  pnorm(c(2,NA,NaN));
however relax, as  NA+NaN or NaN+NA  differ, too.
** DONE frankCopula(0) and similar should create indepCopula(), and hence work in all cases.
 We have new argument 'use.indepC'
 E-mail From Benedikt Gräler, Subject: frankCopula(0), Fri, 26 Apr 2013:
 dCopula(c(0.3,0.7), frankCopula(0))  gives NaN   but should not
** TODO why does onacopulaL("Clayton", *) work, but onacopulaL("clayton",*) does not?
Specifically,
   onacopulaL("Clayton", list(th=iTau(archmCopula("clayton"), tau=0.5), seq_len(3)))
works but
   onacopulaL("clayton", list(th=iTau(archmCopula("clayton"), tau=0.5), seq_len(3)))
doesn't.  Note the 2nd  "clayton", i.e. as arg to archmCopula(.) it _does_ work.
 => essentially, we always want to use the capitalized versions, but it might
    still be a bug that it doesn't work otherwise
** DONE largely improve on gofTests.R: should be made more modular, so that users can provide functions for the parametric bootstrap (gofPB) and the multiplier boostrap (gofMB). Furthermore, checking and documentation have to be improved (see already improved gofPB());
** DONE deprecate gnacopula() [see 'Note' there!!!]
 MH: already 'prepared' a lot; only difficulty: many calls of gnacopula()
 => ideally, the checks should be done with gofCopula() instead of gnacopula()!!!!
** DONE persp(), contour() should work with pCopula / dCopula.
** DONE getAcop(gumbelCopula()) should work
 => we could then write general methods for all Archimedean objects.
Possible problem (for now): negative concordance case for AMH, Clayton, and Frank
** DONE (MH) LICENCE etc
CLOSED: [2012-07-17 Tue 11:25]
MM: Einstein's rule: Keep it as simple as possible (but not simpler)
All the Copyright headers in R/*.R  src/*.c etc need to be streamlined;
typically containing all 4 names.
MH: I can do that (once Ivan and Jun agree)
JY: I agree
IK: Me too
=> MH: done on 2012-03-25 (for simplicity, I used "2012" everywhere)
** TODO Renaming of current "base" functions see [[file:feature-table.org][Feature table]] and [[file:do-now.org][do-now table]]
    remaining: lambdaL/U and inverse ("iLambda").
** TODO fitCopula("itau") for "tCopula(df.fixed=FALSE)": (and tevCopula?):
 use itau for P matrix, then ML for df. {see also ggraph.Rnw}
** DONE show(<mvdc>) method needed; otherwise printing mvdc(.) looks ugly.
** TODO Deprecation of Old Stuff / towards more consistency / Cleanup
- with warning
- on help pages
*** TODO NAC Archimedean families <--> archmCopula  unification
**** TODO The NAC Archimedean families are partly 'better' and partly "worse" than
  archmCop: need 'uscore'
**** TODO JY: For score & uscore (see [[file:feature-table.org][Feature table]]); write testing code
 based on IJ-"papers" that compares the two classes numerically.
**** DONE MM: pCopula(<archm>) and dCopula(<archm>)
 use the the numerically good formulae rather than the "exprDist".
**** TODO d=2 is special: allows negative tau, MH-code now does partly.
 done for Clayton, Frank, AMH.  BUT not for the R/cop_objects.R slots
*** DONE "copula" class:  slot re-definitions
**** DONE 'message' --> 'fullname'
**** no longer TODO: 'param.lowbnd' / 'param.upbnd' --- use "interval" as in nacopula
*** TODO nparam() "wrapper" for  length(.@parameters)
*** no longer TODO: dTau() = tau'(), rho() and dRho() = rho'() -- to get std.err. for  "itau" and "irho"
**** these are *one* of the things where IJ-archmCopula' are better
** DONE MM: former nacopula  c_longNames etc  --> rename to .ac_longNames *and* export
  (ac = Archimedean copula)
** TODO Exporting/Documenting of "internal" functions:
*** DONE => C.n(). JY: Ivan, I think we should export an empCopula function. I always
thought it was unnecessary because it can be obtained with R package mecdf.
But people have asked for it.
*** Also, look at ./man/copula-internal.Rd :
*** no longer TODO: schlatherCopula:  JY: The implementation of schlatherCopula is not ready for release.
 More ev copulas will come from max-stable processes.
*** TODO JY: asymCopula (-class) -- *.Rd document properly (incl some examples!)
** DONE New (Super)classes for "merging the class structure"
- new class "Copula" := {copula, nacopula}
** DONE C code
*** DONE [src/init.c] enable registration for the old 'copula' part
*** DONE JY: gsl - Debye ===> Should use them and then *not* carry gsl-source code anymore.
*** DONE IK: in all *.c files from former copula: use Doxygen
instead of hand made function header documentation.

** TODO New Wrapper functions or rather extending one or the other function names
*** TODO distribution/density/ ... functions
**** DONE dcopula(), pcopula(), rcopula()  (for "nacopula")
**** DONE dCopula(x, cop), pCopula(x, cop), rCopula(n, cop)  {swapping args for "standard R" usage}
**** DONE d*():  allow  log=TRUE and use that in loglikCopula()
**** TODO fitCopula() should encompass all methods of enacopula()
*** DONE MMMH: Use new rCopula() in ggraph *instead* of wrappers
** TODO rCopula() for archmCopula's should allow to use MH's racopula()
*but* for back compatibility allow *global* options(....) to still get old
random numbers.
** TODO MM: data(rdj) should have a "Date" in column 1, not a factor !
** DONE tests/pdf.R should use "all" copulas, similar to tests/moments.R.
*** DONE Then, test that  exp(dCopula(*, log=TRUE)) "==" dCopula(*)
{to test the bug, fixed in r954, reported by Benedikt}
** DONE ~/R/Pkgs/copula : need a version with much shorter tests on CRAN?
*** can we "not rebuild the PDFs" for the vignettes? to save a bit?

* Mid Term
** TODO Ulf Schepsmeier's email to Marius on 2014-04-23: VineCopulas now has wrappers for 'copula' => Ulf suggested to refer to them / their copulas which are not in our package:
library(copula)
persp(BB1Copula(c(1,1.5)),dCopula, zlim=c(0,10))
persp(surBB1Copula(c(1,1.5)),dCopula, zlim=c(0,10))
persp(r90BB1Copula(c(-1,-1.5)),dCopula, zlim=c(0,10))
persp(r270BB1Copula(c(-1,-1.5)),dCopula, zlim=c(0,10))
** TODO Daniel Alai's email from 2013-10-24 (to MH): implement a new correlation structure "min" (row-wise the same rho)
MH: doesn't seem complicated, but wouldn't feel comfortable to do this since
this is old+stable code from Ivan/Jun
** TODO add *transformations* (for each copula): survival copula, convex combis (see Martin's nor1mix), Liebscher
** TODO implement Joe's BB copulas!
** DONE R/sysdata.rda:
CLOSED: [2012-07-17 Tue 11:10]
MM, MH: Please tell us more about this,
notably about how it is computed {so it can be recomputed, in case
pspline changes ...}.
JY: Sorry for having to use this. The objects stored here are used to
return Kendall's tau and Spearman's rho and their inverse functions
for copulas for which explicit formulas are not available. We used
simulation over a grid of (possibly transformed) parameter values
and smoothed the results with pspline. Some details can be found
in the appendix of Kojadinovic and Yan (2010, IME). The R scripts
that generated sysdata.rda were moved out of the package source.
We can put them back. The best place is under inst?
=> JY: done on 2012-07-12. The R scripts are under inst/docs/tauRho/.
***  R code for inspection:
 attach("~/R/Pkgs/copula/R/sysdata.rda")
 ls.str(pos=2, all=TRUE)
 ## or even
 print(ls.str(pos=2, all=TRUE), max.level = 3)

** TODO Extend polynEval() with the methods of polyJ();
 this can be called from polyJ() and uscore of Joe.
** TODO MH: something more sophisticated than persp(): lattice's wireframe() is the best I know w.r.t to many things
** TODO Deprecation of Old Stuff / more consistency / Cleanup
*** TODO loglikCopula() --- try(), hidemessages should "go" eventually
*** TODO varPL(): TODO's there
*** TODO dTau() = tau'() and dRho() = rho'() -- to get S.Err. for  "itau" and "irho"
these are *one* of the things where IJ-archmCopula' are better
*** TODO dAduGalambos() and similar: Use  list() instead of data.frame() as return value  (?)
*** TODO dCdthetaEvCopula() cannot work (as dAdtheta() has no methods) and is used nowhere
** TODO need a "getTheta" analogously to "setTheta"
which extracts the parameter (vector) from any copula object
** TODO Write a function "checkTheta" or "thetaConstr"(param_vector, Copula):
 checks if the parameters are all admissible.
** TODO Rebuild R-forge structure nacopula -> copula
** TODO Miscellaneous Functions (& bugs: all DONE)
*** DONE (MH) rtrafo() {and probably htrafo()} --- "fail" (are *wrong*!) for n = 1
*** DONE (MH) copFrank@psi(1/1e20, theta=200) == Inf instead of 1
*** TODO see TODO in R/tCopula.R : npar.ellip() function;-> nparam(); test pos.def.
*** TODO tCopula() / normalCopula() allow alternative specification of cor.matrix at least for the "un" dispersion structure
*** TODO opower() and GIG --> either produce acopula with parameter *vector*, or
--- maybe in any case ---
produce an object of class 'opacopula' ("outer power Archimedean copula")
which is just 'acopula' with a new show method ("thetabase" at least!),
possibly a new slot ...
Longer term: want to *estimate* those correctly [MLE at least].
*** TODO rtrafo() is now "available" for "t" and "normal" thanks to the Master thesis of Yongsheng Wang.  (--> ...../function-gof.R )
**** DONE implement it,
**** TODO Extend  rtrafo() to other (d > 2)-copula families
** TODO evTestA(), evTestC(), evTestK()  have basically no tests {but improvable code}
 [[file:man/evTestA.Rd][evTestA.Rd]], [[file:man/evTestC.Rd][evTestC.Rd]], [[file:man/evTestK.Rd][evTestK.Rd]]
** TODO C code
*** DONE [src/init.c] enable registration for the old 'copula' part
*** TODO use 'static' "everywhere" +  attribute_hidden "otherwise"/sometimes
** TODO Documentation etc
*** DONE inst/doc/nacopula-pkg.Rnw  -- keep file name, maybe rewrite including
 *Title*  (s/nacopula package/Nested Archimedean Copulas in the copula package/)
*** TODO \link{} between  old-copula and old-nacopula  functionality
*** TODO small vignette with table of function names providing the same functionality (nacopula / old_copula)
*** DONE (MH) fixed long lines in all .Rd
** TODO pCopula() should also accept a  'log.p = FALSE' argument
 and provide more accurate results in the lower tail for log.p=TRUE.
** TODO Miscellaneous functions
*** TODO MM, MH: indepTest()  takes a while {ok}, *BUT* cannot be interrupted (quickly enough)
    - shouldn't it {and all other tests} return a (valid) object of class
    "htest" (maybe "htest" in addition to the specific S3 class)?
    --> we would probably not need extra print() methods, and just use print.htest()
*** DONE MH: @ Jun, Ivan: file R/E.R  only defines E <- exp(1). Reason(MM): work around silly 'CMD check' warnings.
But we should move that to another R/*.R

*** TODO iTau(): must use tau.checker() [R/estimation.R]
*** TODO makePosDef() -- think of using a version of sfsmisc::posdefify() or nearPD()
*** TODO R/fitCopula.R : method="itau" & "irho": parallelize double for-loop in
 fitKendall() & fitSpearman() :  tests/moments.R must
 check that vectorized iTau() and iRho() work for all families
*** TODO t / normal : allow  "block" dispersion structure {including  fitCopula() working}

**** --> e-mail and example: /u/maechler/R/MM/Pkg-ex/copula/mvdc-ex.R

*** TODO function(outer_nacopula) -> matrix of 'comp' (in {1:d})
which corresponds to the different sectors.
This can be used, e.g., for building a [default] color-matrix for splom2 or
for estimation purposes etc. Note: look at nacPairthetas
*** TODO nice little function that provides confidence intervals for tau and lambda's (from \theta_{MLE})
*** TODO IK: d-dimensional versions of rank-based estimators of the Pickands dependence function
*** DONE setTheta(): write methods for "copula"s !
** TODO Testing: ./tests/  must grow, notably for "Jun-Ivan functions"
maybe take  ./tests/copula-play.R  as sophisticated role model.
** TODO Programming Style (unification)
*** TODO *naming* function arguments after 2nd or 3rd:
- call functions like f(x, foo=1, bar=2) instead of f(x, 1, 2).
  This makes the code more readable and more error-prone (naming all
  arguments except the first one).

** TODO Use  paste0()  where possible in IJ-code
** DONE Replace ccop in ggraph by cCopula

** DONE cacopula(): generalize to elliptical ("and more") -> cCopula(), (<==> rtrafo())

** TODO Once we require R >= 3.1.0, use cospi(), tanpi(), etc instead of our tanpi(), cospi2()
* Long Term
** TODO ChiPlot(), KPlot() [in R/graphics.R]: Export and document ?
** TODO copula code which is not used --- moved to ./misc/
MM: the previous file (+directory) names were:
    - R/mult.R
    - src/mult.c
    - src/mygsl_util.c
** TODO C code
*** DONE [src/init.c] enable registration for the old 'copula' part
*** TODO Move  from .C() towards .Call() -- only very long term
JY: Agree. Quite a few them. Can it wait?  MM: Definitely; Actually, I
think it's not worth the effort; particularly now that I've spent all the
effort writing src/init.c for registration of all of the .C(..) routines.

** TODO Miscellaneous functions.
*** TODO include pairwise estimators for nACs
*** TODO add an ASCII-plot for the hierarchical structure;
Actually, define setAs("nacopula", "dendrogram", ....) and then use
dendrogram print()ing.
*** TODO Khoudraji d + p + r (see asymCopula.R)
*** TODO IK: add d-dimensional EV copulas corresponding to max-stable processes and corresponding "composite densities"
