Fit a linear regression using lm(). Linear regression is used to explore the effect of continuous variables / categorical variables in predicting a normally-distributed continuous variables. If you are using a categorical predictor to predict a continuous variable, some may call it a ANOVA / ANCOVA while it is just a special form of linear regression). In this package, I will not build separate function for ANOVA & ANCOVA since they are the same as linear regression

lm_model(
data,
response_variable,
predictor_variable,
two_way_interaction_factor = NULL,
three_way_interaction_factor = NULL,
quite = FALSE
)

## Arguments

data

data frame

response_variable

response variable. Support dplyr::select() syntax.

predictor_variable

predictor variable. Support dplyr::select() syntax. It will automatically remove the response variable from predictor variable, so you can use contains() or start_with() safely.

two_way_interaction_factor

two-way interaction factors. You need to pass 2+ factor. Support dplyr::select() syntax.

three_way_interaction_factor

three-way interaction factor. You need to pass exactly 3 factors. Specifying three-way interaction factors automatically included all two-way interactions, so please do not specify the two_way_interaction_factor argument. Support dplyr::select() syntax.

quite

suppress printing output

## Value

an object class of lm representing the linear regression fit

## Examples

fit <- lm_model(
data = iris,
response_variable = "Sepal.Length",
predictor_variable = tidyselect::everything(),
two_way_interaction_factor = c(Sepal.Width, Species)
)
#> Warning: The following columns are coerced into numeric: Species
#> Fitting Model with lm:
#>  Formula = Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width + Species + Sepal.Width*Species