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

后端 未结 4 414
后悔当初
后悔当初 2021-02-05 23:12

When I use the following R code,

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

The size of modelfile w

4条回答
  •  不知归路
    2021-02-05 23:32

    object.size() is misleading because it ignores the environment attributes. If you want to assess the true size, use:

    length(serialize(model_glm, NULL))
    

    Apart from the data stored, if you want to significantly reduce the size of your glm do:

    rm(list=ls(envir = attr(model_glm$terms, ".Environment")),
         envir = attr(model_glm$terms,
                  ".Environment"))
    

    This comes from a well detailed article

提交回复
热议问题