From Martin Maechler <maechler@stat.math.ethz.ch>  Thu May 17 14:21:46 2001
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Thu, 17 May 2001 15:21:46 +0200
Subject: [Rd] New generic functions in "R base" {was `truncate'}
In-Reply-To: <3B028D07.2A00CDD6@bank-banque-canada.ca>
References: <Pine.LNX.4.31.0105151757200.7983-100000@gannet.stats>
 <3B028D07.2A00CDD6@bank-banque-canada.ca>
Message-ID: <15107.53354.670649.577003@gargle.gargle.HOWL>

>>>>> "PaulG" == Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:

    PaulG> Brian
    PaulG> I've changed the name of my truncate function. In this case I think
    PaulG> problems of conflicts in code could easily be resolved, but I don't
    PaulG> understand how conflicts in the documentation would be resolved.

    PaulG> However, please do keep in mind that adding things to base is
    PaulG> problematic because of name space conflicts. This case was
    PaulG> relatively easy for me, but some functions would be much more
    PaulG> difficult because of all the implications for documentation and
    PaulG> other code using the packages.

You are right, Paul, adding things to base is somewhat problematic
particularly for package writers.  That's why I now ask for comments:

One thing I *would* like to add to base (in a general sense -- note that
Brian mentioned that namespaces might well come in the not so distant future),
are the generic functions

    AIC
and
    logLik  {both a generic and a class!}

that Bates and Pinheiro use quite extensively in the nlme package
(and I did ask Doug about this two months ago) :

--------
After  library(nlme)

  > ls(pos=2,pat="AIC")
  [1] "AIC"        "AIC.gls"    "AIC.lm"     "AIC.lme"    "AIC.lmList"
  [6] "AIC.logLik" "AIC.nls"   
  > ls(pos=2,pat="^logLik")
   [1] "logLik.corStruct"    "logLik.gls"          "logLik.glsStruct"   
   [4] "logLik.gnls"         "logLik.gnlsStruct"   "logLik.lm"          
   [7] "logLik.lme"          "logLik.lmeStruct"    "logLik.lmeStructInt"
  [10] "logLik.lmList"       "logLik.reStruct"     "logLik.varComb"     
  [13] "logLik.varFunc"     
  > ls(pos=2,pat="logLik$")
  [1] "AIC.logLik"   "BIC.logLik"   "print.logLik"
  > AIC
  function (object, ...) 
  UseMethod("AIC")
  > str(AIC.lm)
  function (object, ...) 

--------

The nlme() also defines BIC(), which one might argue could also be
considered a special case of a more general "*IC" generic.

Package MASS has

  extractAIC.loglm <- function (fit, scale, k = 2, ...) 
  {
      edf <- fit$n - fit$df
      c(edf, fit$deviance + k * edf)
  }

which you can use for the BIC as well 
by replacing "k = 2" by "k = log(fit$n)".

And there are AIC like computations in many R packages.
which may or may not differ.
However it would make sense to have the generic and the lm (and glm?)
methods in standard base.  Similarly for "logLik".

------

Does anyone see problems?
Should the AIC generic {or only some of the methods} include something like
a "k = 2" argument  (why ``k'' , btw) ?

Thanks for constructive feedback!

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] New generic functions in "R base" {was `truncate'}
Martin Maechler