Learn R Programming

volker (version 3.3.0)

add_model: Add a column with predicted values from a regression model

Description

You can either provide variables in dedicated parameters or use a formula.

The regression output comes from stats::lm. The effect sizes are calculated by heplots::etasq. The variance inflation is calculated by car::vif.

[Experimental]

Usage

add_model(
  data,
  col,
  categorical = NULL,
  metric = NULL,
  interactions = NULL,
  newcol = NULL,
  labels = TRUE,
  clean = TRUE,
  ...
)

Value

The input tibble with one additional column. The new column will have an attribute "lm.fit" with the fit model.

Arguments

data

A tibble.

col

The target column holding metric values or a model formula. If you provide a formula, skip the parameters for independent variables.

categorical

A tidy column selection holding categorical variables.

metric

A tidy column selection holding metric variables.

interactions

A vector of interaction effects to calculate. Each interaction effect should be provided as multiplication of the variables. The interaction effect can be provided as character value (e.g. c("sd_gender * adopter")) or as unquoted column names (e.g. c(sd_gender * adopter)).

newcol

Name of the new column with predicted values. Set to NULL (default) to use the outcome variable name, prefixed with "prd_".

labels

If TRUE (default) extracts labels from the attributes, see codebook.

clean

Prepare data by data_clean.

...

Placeholder to allow calling the method with unused parameters from effect_metrics.

Examples

Run this code
library(volker)
data <- filter(volker::chatgpt, sd_gender != "diverse")

data <- data |>
  add_model(use_work, categorical = c(sd_gender, adopter), metric = sd_age)

Run the code above in your browser using DataLab