Title: | Combine Statistical Models into a Tibble for Comparison |
---|---|
Description: | Statisticians often want to compare the fit of different models on the same data set. However, this usually involves a lot of manual code to fish items out of summary() or plain model objects. 'modelfactory' offers the capability to pass multiple models in and get out metrics or coefficients for quick comparison with easy-to-remember syntax. |
Authors: | Will Tirone [aut, cre, cph] |
Maintainer: | Will Tirone <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0.9000 |
Built: | 2025-02-23 05:17:17 UTC |
Source: | https://github.com/willtirone/modelfactory |
stack_coeff()
takes several lm or glm models, pulls out their coefficients,
standard errors, and confidence intervals, and stacks everything into a
tibble()
for easy comparison across models.
stack_coeff(..., ci = 0.95)
stack_coeff(..., ci = 0.95)
... |
lm or glm models to summarize and combine. |
ci |
width of confidence, default = 0.95. |
A tibble()
with coefficients, confidence intervals, and standard
errors.
# multiple lm example ---------------------------------- lm_1 = lm(mpg ~ cyl + disp + hp, data = mtcars) lm_2 = lm(mpg ~ hp + drat + wt, data = mtcars) lm_3 = lm(mpg ~ ., data = mtcars) lm_combined = stack_coeff(lm_1, lm_2, lm_3) lm_combined # sometimes you might just want 1 model's summary ------ single_lm = stack_coeff(lm_1) single_lm # glm example ------------------------------------------ glm_1 = glm(vs ~ drat + hp, data = mtcars) glm_2 = glm(vs ~ wt + qsec, data = mtcars) glm_3 = glm(vs ~ ., data = mtcars) glm_combined = stack_coeff(glm_1, glm_2, glm_3) glm_combined
# multiple lm example ---------------------------------- lm_1 = lm(mpg ~ cyl + disp + hp, data = mtcars) lm_2 = lm(mpg ~ hp + drat + wt, data = mtcars) lm_3 = lm(mpg ~ ., data = mtcars) lm_combined = stack_coeff(lm_1, lm_2, lm_3) lm_combined # sometimes you might just want 1 model's summary ------ single_lm = stack_coeff(lm_1) single_lm # glm example ------------------------------------------ glm_1 = glm(vs ~ drat + hp, data = mtcars) glm_2 = glm(vs ~ wt + qsec, data = mtcars) glm_3 = glm(vs ~ ., data = mtcars) glm_combined = stack_coeff(glm_1, glm_2, glm_3) glm_combined
stack_metrics()
calculates basic model metrics like MSE for the models
passed in, then stacks them in a dataframe for comparison. This supports
lm, glm, and lmer models, and different metrics are calculated for each.
This does not perform model selection based on a given criteria, but it
makes the tedious task of, say, comparing R-squared across several models
very easy.
stack_metrics(...)
stack_metrics(...)
... |
lm, glm, or lmer models to summarize and combine. |
A tibble()
that includes a variety of evaluation metrics.
# lm example ------------------------------------------- lm_1 = lm(mpg ~ cyl + disp + hp, data = mtcars) lm_2 = lm(mpg ~ hp + drat + wt, data = mtcars) lm_3 = lm(mpg ~ ., data = mtcars) lm_combined = stack_metrics(lm_1, lm_2, lm_3) lm_combined # glm example ------------------------------------------ glm_1 = glm(vs ~ drat + hp, data = mtcars) glm_2 = glm(vs ~ wt + qsec, data = mtcars) glm_3 = glm(vs ~ ., data = mtcars) glm_combined = stack_metrics(glm_1, glm_2, glm_3) glm_combined # lme4 example ----------------------------------------- lmer_1 = lme4::lmer(Sepal.Length ~ (1 | Species), data = iris) lmer_2 = lme4::lmer(Sepal.Length ~ (1 | Species) + Petal.Length, data = iris) lmer_combined = stack_metrics(lmer_1, lmer_2) lmer_combined
# lm example ------------------------------------------- lm_1 = lm(mpg ~ cyl + disp + hp, data = mtcars) lm_2 = lm(mpg ~ hp + drat + wt, data = mtcars) lm_3 = lm(mpg ~ ., data = mtcars) lm_combined = stack_metrics(lm_1, lm_2, lm_3) lm_combined # glm example ------------------------------------------ glm_1 = glm(vs ~ drat + hp, data = mtcars) glm_2 = glm(vs ~ wt + qsec, data = mtcars) glm_3 = glm(vs ~ ., data = mtcars) glm_combined = stack_metrics(glm_1, glm_2, glm_3) glm_combined # lme4 example ----------------------------------------- lmer_1 = lme4::lmer(Sepal.Length ~ (1 | Species), data = iris) lmer_2 = lme4::lmer(Sepal.Length ~ (1 | Species) + Petal.Length, data = iris) lmer_combined = stack_metrics(lmer_1, lmer_2) lmer_combined