[R] trying to use standard notation
Douglas Bates
bates at stat.wisc.edu
Tue May 9 21:17:01 CEST 2006
On 5/9/06, Andrew Gelman <gelman at stat.columbia.edu> wrote:
> Hi, all. In setting up my package for post-processing regression
> models, I am trying to use standard notation as much as possible: thus,
> I use coef() to access estimated coefficients. I wrote a function
> called se.coef() to grab standard errors, and se.fixef() and se.ranef()
> to grab se's from coefficients estimated from lmer().
I too have difficulty in coming up with reasonable names for generics,
especially for lmer objects. I'm not particularly pleased with the
value of the coef method for that class in that it is well-defined for
models with nested grouping factors but not for models with crossed or
partially crossed grouping factors for the random effects. One
suggestion (I believe due to Harold Doran) is to check on whether the
grouping factors are nested and throw an error if they are not.
Regarding the se.fixef I would use the vcov extractor instead in the form
sqrt(diag(vcov(lmerModel)))
That's enough of a self-explanatory "one liner" that I wouldn't create
a special generic. Another approach that should work but currently
doesn't is to use
coef(summary(lmerModel))
In general we should have that return the table of coefficients and
their standard errors, etc. and I could modify the package to create
this behavior. Alternatively, I could create methods for the
summary.lmer class so that
fixef(summary(lmerModel))
returns the summary table of the fixed effects and
ranef(summary(lmerModel))
returns the summary table for the random effects.
In general I would prefer to compose extractors to get the desired
effect instead of creating new generics and associated methods. There
are far too many function names in R to remember already.
> I also need a function to access sigma-hat (the residual sd of the
> regression). I've called this function sigma.hat(), but I'm open to
> using a better name if there's something more standard.
About the best I can think of is to make 'sd' a generic and create
methods for that.
> I also have a function called sim() that makes simulations using lm() or
> glm() output (based on the curvature of the likelihood function or, to
> put it another way, approximate Bayesian inference assuming a flat prior
> distribution). sim() returns a list: with two components: (1) beta, a
> matrix of simulated coefficients (with dimension n.sims by k), and (2)
> sigma, a vector of simulated sigma's (with length n.sims).
There is already a "simulate" generic. One approach would be to
extend the argument list for that generic.
> I'll be doing more, but these are the basics for now. I need to be able
> to pull these objects out as necessary. And I just was wondering if
> anyone had suggested names for the functions that are more consistent
> with R naming conventions.
More information about the R-help
mailing list