compare_predictors: Fit linear models for a set of predictors to compare their...

compare_predictorsR Documentation

Fit linear models for a set of predictors to compare their effects alone and together

Description

This function fits a set of models to the data, where each model includes only one predictor. It then fits a full model with all predictors. The function returns a data frame with the coefficients for each model, as well as the full model. Thus, if given p predictors, it will return p+1 model results and 2 betas for each predictor.

Usage

compare_predictors(
  data,
  outcome,
  predictors,
  additional_models = NULL,
  conf.level = 0.95,
  family = gaussian
)

Arguments

data

The data frame to use

outcome

The name of the outcome variable. Must be numeric.

predictors

A character vector of predictors to use.

additional_models

A list of additional models to fit. Each element of the list should be a character vector of predictors to use. The names of the list will be used as the model names in the output.

conf.level

The confidence level to use. Default is .95.

family

The family to use. Default is "gaussian" (OLS), see ?glm for more information.

Value

A data frame with the coefficients for each model

Examples

compare_predictors(iris, names(iris)[1], names(iris)[-1])
compare_predictors(mpg, names(mpg)[3], names(mpg)[-3])
#with additional models
compare_predictors(iris, names(iris)[1], names(iris)[-1], additional_models = list(petal = c("Petal.Length", "Petal.Width")))

Deleetdk/kirkegaard documentation built on Feb. 28, 2025, 5:04 p.m.