[R] Saving fits (glm, nls) without data

Johann Hibschman jhibschman at gmail.com
Tue Sep 7 22:59:50 CEST 2010


Duncan Murdoch <murdoch.duncan at gmail.com> writes:
>  On 07/09/2010 4:18 PM, Johann Hibschman wrote:
>> Going through that code, I settled on the following function to remove
>> all but the most needed components:
>>
>>     ## Strip down a glm object, until it can only be used for prediction,
>>     ## but is nice and small.
>>     strip.glm<- function (f) {
>>       f.str<- list(coefficients=f$coefficients,
>>                     family=f$family,
>>                     terms=f$terms,
>>                     qr=list(pivot=f$qr$pivot),
>>                     rank=f$rank,
>>                     na.action=f$na.action)

For posterity: including the na.action here was a mistake, an untested
experiment that I accidentally copied when posting.  It's relatively
big, and I don't think I need it.

>>       attr(f.str$terms, ".Environment")<- globalenv()
>>       class(f.str)<- class(f)
>>       f.str
>>     }
>
> I think a safer modification would be to set the environment to
> emptyenv().  That won't take any space, but it means if you
> miscalculated and some variables in that environment really were being
> used, you'll get an error instead of a wrong answer.

Thanks, that's helpful.

Cheers,

Johann



More information about the R-help mailing list