Package 'modelfactory'

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

Help Index


Stack coefficents, confidence intervals, and standard errors for n models.

Description

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.

Usage

stack_coeff(..., ci = 0.95)

Arguments

...

lm or glm models to summarize and combine.

ci

width of confidence, default = 0.95.

Value

A tibble() with coefficients, confidence intervals, and standard errors.

Examples

# 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

Combine model metrics for n number of lm, glm, and lmer models

Description

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.

Usage

stack_metrics(...)

Arguments

...

lm, glm, or lmer models to summarize and combine.

Value

A tibble() that includes a variety of evaluation metrics.

Examples

# 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