[Rd] possible tweaking of family()$simulate?

Ben Bolker bbolker at gmail.com
Tue Aug 27 19:32:12 CEST 2013

   This should probably be submitted eventually as a wishlist to R-core,
as it requires (minor) changes to base R, but I thought I would float it
here first ...

  In a package, I construct glm()-like model objects that have 'family'
components based on the GLM family objects (binomial(), poisson(),
Gamma(), etc.).  I have written a 'simulate' method for these objects
that has basically had to re-code much of what's already contained in
the family()$simulate methods, because they are just a little bit too
hardcoded.  I can't just add list elements to my object, because it's
represented by an S4 class .......

  For example, poisson()$simulate contains references to

* object$prior.weights  -- could be replaced by weights(object) ?
* fitted(object) -- I would like to be able to substitute my own "mu"
value here, but I can hack around it (in a perfect world I would add a
third optional argument:

 $simulate <- function(object,nsim,ftd=fitted(object)) {

  binomial()$simulate contains references to the above two components,
as well as a reference to object$model (which could be replaced by

  inverse.gaussian()$simulate has a reference to
summary(object)$dispersion (this wouldn't be too hard)

  The required changes would be fairly minor, and as far as I can tell
completely backward compatible.  Of course I don't know if there's much
demand for it ... it would certainly be helpful for me, I don't know if
there is latent demand out there ...

    Ben Bolker

More information about the R-devel mailing list