Search code examples
rpredictionglm

How to save glm result without data or only with coeffients for prediction?


When I use the following R code,

model_glm=glm(V1~. , data=xx,family="binomial");
save(file="modelfile",model_glm);

The size of modelfile will be as much as the data, which will be 1gig in my case. How can I remove the data part in the result of model_glm, so I can only save a small file.


Solution

  • Setting model = FALSE in your call to glm should prevent the model.frame from being returned. Also setting y = FALSE will prevent the response vector from being returned. x = FALSE is the default setting and prevents the model.matrix from being returned.

    This combination should shrink the size of your glm object.

    Of course, you can also extract the coefficients with coef(model_glm) or, with standard errors,

    summary(model_glm)$coef