fit_to_dt: Format (specific) linear fit output as a data.table

Description Usage Arguments Value Examples

View source: R/fit_to_dt.R

Description

fit_to_dt() is a function that converts the results of a linear model with one continuous regressor of interest (e.g. first_mo) that is interacted with factor variable (e.g. risk_cut) to a data.table with easily manipulable columns of interaction labels. This is useful for plotting the results of the elasticty by risk models.

Usage

1
fit_to_dt(fit, primary, interacts = NULL)

Arguments

fit

the linear fit (usually lm, lm_robust, or iv_robust). The fit must be specified to estimate the coefficient on the continuous variable for all levels of interactions (e.g. atc4_C10AA ~ first_mo:factor(pred_cut) + factor(pred_cut))

primary

character, the vaiable name of the continuous regressor of interest (usually first_mo)

interacts

character vector, names of the interaction variables (factors)

Value

data.table with the estiated coefficients of the primary variable for each interction combination (along with SEs and CIs).

Examples

1
2
3
DT <- as.data.table(mtcars)
fit <- lm(mpg ~ wt:factor(cyl) + factor(cyl), data = DT)
dt_fit <- fit_to_dt(fit, primary = "wt", interacts = "cyl")

evanjflack/cfo.behavioral documentation built on Oct. 10, 2020, 11:52 p.m.