Re: [Rd] proposed simulate.glm method

From: Paul Gilbert <>
Date: Fri, 13 Feb 2009 14:06:12 -0500

If you are generalizing this, the saving of the RNG information to reproduce normally distribution random number also needs to save the normal generator information. (This looks like an omission in simulate.lm.) You might want to consider adding the simple functions setRNG and getRNG from my setRNG package. Roughly, the functions make the first ten lines of simulate.lm or Ben's code into a function call, which may not be so important other than the missing normal information, but having a standardized object with all the information seems to be useful.

The package also has documentation and tests, which can be helpful for other package builders that define simulate methods. It has been around for a long time so has been pretty well tested.

Paul Gilbert

Martin Maechler wrote:
> Thanks a lot, Heather,

>>>>>>"HT" == Heather Turner <>
>>>>>>    on Fri, 13 Feb 2009 11:49:06 +0000 writes:

> HT> Dear Martin,
> HT> I think a simulate.glm method ought to be able to work for gnm objects
> HT> too. David Firth and I started to work on this a long time ago, but
> HT> stopped part-way through when simulate.lm was introduced, thinking that
> HT> simulate.glm was probably in the pipeline and we were duplicating
> HT> effort. Obviously we have let this slip when a contribution might have
> HT> been useful. We developed a prototype for poisson, binomial, gaussian,
> HT> gamma and inverse gaussian models which might be usefully merged with
> HT> Ben's proposed simulate.glm. What's the best way to go about this? I
> HT> would also like to test the proposed simulate.glm to check whether it
> HT> will work with gnm objects or whether a simulate.gnm will be necessary.
> In the mean time, private e-mail communications have started on
> the subject, and yes, we are very insterested in finding
> ``the best'' possible way, probably making use of
> Heather+David's code together with Ben's.
> One alternative (not mentioned yet on R-devel), we've been
> considering is to use simulate.lm() to also deal with "glm" (and
> possibly "gnm") objects ``in one place''.
> Martin
> HT> Martin Maechler wrote:
> >>>>>>> "BB" == Ben Bolker <>
> >>>>>>> on Thu, 12 Feb 2009 11:29:14 -0500 writes:
> >>
> BB> I have found the "simulate" method (incorporated
> BB> in some packages) very handy. As far as I can tell the
> BB> only class for which simulate is actually implemented
> BB> in base R is lm ... this is actually a little dangerous
> BB> for a naive user who might be tempted to try
> BB> simulate(X) where X is a glm fit instead, because
> BB> it defaults to simulate.lm (since glm inherits from
> BB> the lm class), and the answers make no sense ...
> >>
> BB> Here is my simulate.glm(), which is modeled on
> BB> simulate.lm . It implements simulation for poisson
> BB> and binomial (binary or non-binary) models, should
> BB> be easy to implement others if that seems necessary.
> >>
> BB> I hereby request comments and suggest that it wouldn't
> BB> hurt to incorporate it into base R ... (I will write
> BB> docs for it if necessary, perhaps by modifying ?simulate --
> BB> there is no specific documentation for simulate.lm)
> >>
> BB> cheers
> BB> Ben Bolker
> >>
> >> [...............]
> >>
> >> Hi Ben,
> >> thank you for your proposals.
> >>
> >> I agree that simulate.glm() has been in missing in some way,
> >> till now, in particular, as, as you note, "glm" objects extend
> >> "lm" ones and hence simulate(<glm>, ...) currently dispatches to
> >> calling simulate.lm(....) which is only correct in the case of
> >> the gaussian family.
> >>
> >> I have looked at your proposal a bit, already "improved" the
> >> code slightly (e.g. re-include the comment you lost when you
> >> ``copied'' simulate.lm(): In such cases, please work from the
> >> source, not from what you get by print()ing
> >> stats:::simulate.lm --- the source is either a recent tarball,
> >> or the SVN repository, in this case, file
> >> ]
> >> and am planning to look at your and some own examples;
> >> all with the goal to indeed include this in the R standard
> >> 'stats' package in R-devel [to become R 2.9.0 in the future].
> >>
> >> About the help page: At the moment, I think that only a few
> >> words would need to be added to the simulate help page,
> >> i.e.,
> >> and will be happy to receive a patch against this file.
> >>
> >> Thank you again, and best regards,
> >> Martin Maechler, ETH Zurich
> ______________________________________________
> mailing list

La version française suit le texte anglais.

This email may contain privileged and/or confidential information, and the Bank of Canada does not waive any related rights. Any distribution, use, or copying of this email or the information it contains by other than the intended recipient is unauthorized. If you received this email in error please delete it immediately from your system and notify the sender promptly by email that you have done so.

Le présent courriel peut contenir de l'information privilégiée ou confidentielle. La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion, utilisation ou copie de ce courriel ou des renseignements qu'il contient par une personne autre que le ou les destinataires désignés est interdite. Si vous recevez ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans délai à l'expéditeur un message électronique pour l'aviser que vous avez éliminé de votre ordinateur toute copie du courriel reçu. mailing list Received on Fri 13 Feb 2009 - 18:09:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 Feb 2009 - 18:30:23 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive