On Sep 7, 2010, at 2:53 PM, Johann Hibschman wrote:

David Winsemius <dwinsem...@comcast.net> writes:

On Sep 7, 2010, at 11:02 AM, Johann Hibschman wrote:
Even so, I would prefer to only save the coefficients

Have you read through the Value section of glm's help page?

...and

?coef

I have; it's easy to get the coefficients. The part I'm struggling with is reconstituting an operational glm object given the coefficient vector
and the formula.

Really, I was hoping that someone had already done this work, so I could
stop trying re-create the right kind of term object, while making sure
it doesn't hold on to a pointer to an environment with a lot of data in
it, etc., etc..

I was assuming you could take all the code work that was already tested and trim out the non essential code and arguments let it work on a new class.

The predict.glm function is visible so you can just type its name to
see the code. It appears that the section of the code that does the
work is fairly short. This is my nomination for what happens in most
cases:

if (!se.fit) {# not generally invoked with se.fit=TRUE
        if (missing(newdata)) {  # forgot this clause in first post
       }
       else {
           pred <- predict.lm(object, newdata, se.fit, scale = 1,
               type = ifelse(type == "link", "response", type),
               terms = terms, na.action = na.action)
           switch(type, response = {
               pred <- family(object)$linkinv(pred)
           }, link = , terms = )
       }

I agree.  That reduces the problem to confecting a working lm object,
given a formula and coefficients. Unfortunately, I haven't yet figured
out how to do that.

And I was thinking one would start with the glm object and just set the unnecessary leaves of the list to NULL.


So maybe you should write a predict function that would work on a
reduced glm object that has a class name of your choosing.

I'm trying to get this to work, but I haven't figured out yet how to
generate the X matrix properly from the formula and the coefficients.
I'm sure I can eventually get it, but it's annoying.

I don't think you need to do anything other than construct a proper newdata argument and feed it and your stripped down object to a modified predict.sml_glm function. And it could very well be that all you need to do is rename the predict.glm code and give it the proper arguments. I do not see a need to recreate an X matrix for the newdata, since the code to do that is already in predict.lm(). I suppose I could be wrong, since I have not done it myself. I just got my employer to buy more memory.


The whole model whereby fit objects keep around their data so you don't
have to provide it on a few calls just seems like a mistake.

-Johann


David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to