Skip to content

Instantly share code, notes, and snippets.

@DexGroves
Created March 30, 2016 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexGroves/0ab74856ecfc8e8abc66e3d792abb0f4 to your computer and use it in GitHub Desktop.
Save DexGroves/0ab74856ecfc8e8abc66e3d792abb0f4 to your computer and use it in GitHub Desktop.
strip_glm <- function(cm) {
cm$y = c()
cm$model = c()
cm$residuals = c()
cm$fitted.values = c()
cm$effects = c()
cm$qr$qr = c()
cm$linear.predictors = c()
cm$weights = c()
cm$prior.weights = c()
cm$data = c()
cm$family$variance = c()
cm$family$dev.resids = c()
cm$family$aic = c()
cm$family$validmu = c()
cm$family$simulate = c()
attr(cm$terms,".Environment") = c()
attr(cm$formula,".Environment") = c()
cm
}
gen_fake_data <- function(N) {
data.frame(col1 = runif(N),
col2 = runif(N),
col3 = runif(N),
resp = rnorm(N))
}
test_df <- gen_fake_data(1e5)
g <- glm(resp ~ col1 + col2 + col3, data = test_df)
object.size(g)
# 55255600 bytes
object.size(strip_glm(g))
# 22104 bytes
g <- lm(resp ~ col1 + col2 + col3, data = test_df)
object.size(g)
# 26417288 bytes
object.size(strip_glm(g))
# 8832 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment