Created
March 30, 2016 10:16
-
-
Save DexGroves/0ab74856ecfc8e8abc66e3d792abb0f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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