[Superseded]
An integrated function for fitting a linear regression model. This function will no longer be updated. Please use the these functions separately instead: model_summary, interaction_plot,and simple_slope.

lm_model_summary(
  data,
  response_variable = NULL,
  predictor_variable = NULL,
  two_way_interaction_factor = NULL,
  three_way_interaction_factor = NULL,
  family = NULL,
  cateogrical_var = NULL,
  graph_label_name = NULL,
  model_summary = TRUE,
  interaction_plot = TRUE,
  y_lim = NULL,
  plot_color = FALSE,
  digits = 3,
  simple_slope = FALSE,
  assumption_plot = FALSE,
  quite = FALSE,
  streamline = FALSE,
  return_result = FALSE
)

Arguments

data

data.frame

response_variable

DV (i.e., outcome variable / response variable). Length of 1. Support dplyr::select() syntax.

predictor_variable

IV. Support dplyr::select() syntax.

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.

family

a GLM family. It will passed to the family argument in glm. See ?glm for possible options. [Experimental]

cateogrical_var

list. Specify the upper bound and lower bound directly instead of using ± 1 SD from the mean. Passed in the form of list(var_name1 = c(upper_bound1, lower_bound1),var_name2 = c(upper_bound2, lower_bound2))

graph_label_name

optional vector or function. vector of length 2 for two-way interaction graph. vector of length 3 for three-way interaction graph. Vector should be passed in the form of c(response_var, predict_var1, predict_var2, ...). Function should be passed as a switch function (see ?two_way_interaction_plot for an example)

model_summary

print model summary. Required to be TRUE if you want assumption_plot.

interaction_plot

generate the interaction plot. Default is TRUE

y_lim

the plot's upper and lower limit for the y-axis. Length of 2. Example: c(lower_limit, upper_limit)

plot_color

If it is set to TRUE (default is FALSE), the interaction plot will plot with color.

digits

number of digits to round to

simple_slope

Slope estimate at +1/-1 SD and the mean of the moderator. Uses interactions::sim_slope() in the background.

assumption_plot

Generate an panel of plots that check major assumptions. It is usually recommended to inspect model assumption violation visually. In the background, it calls performance::check_model()

quite

suppress printing output

streamline

print streamlined output

return_result

If it is set to TRUE (default is FALSE), it will return the model, model_summary, and plot (if the interaction term is included)

Value

a list of all requested items in the order of model, model_summary, interaction_plot, simple_slope

Examples

fit <- lm_model_summary(
  data = iris,
  response_variable = "Sepal.Length",
  predictor_variable = dplyr::everything(),
  two_way_interaction_factor = c(Sepal.Width, Species),
  interaction_plot = FALSE, # you can also request the interaction plot
  simple_slope = FALSE, # you can also request simple slope estimate 
  assumption_plot = FALSE, # you can also request assumption plot
  streamline = FALSE #you can change this to get the least amount of info
)
#> 
#>  
#> Model Summary
#> Model Type = Linear regression
#> Outcome = Sepal.Length
#> Predictors = Sepal.Width, Petal.Length, Petal.Width, Species
#> 
#> Model Estimates
#> ─────────────────────────────────────────────────────────────────────────────────────────────
#>                       Parameter  Coefficient     SE       t   df          p            95% CI
#> ─────────────────────────────────────────────────────────────────────────────────────────────
#>                     (Intercept)        1.633  0.404   4.041  142  0.000 ***  [ 0.834,  2.431]
#>                     Sepal.Width        0.637  0.115   5.527  142  0.000 ***  [ 0.409,  0.864]
#>                    Petal.Length        0.856  0.069  12.353  142  0.000 ***  [ 0.719,  0.993]
#>                     Petal.Width       -0.246  0.156  -1.574  142  0.118      [-0.554,  0.063]
#>               Speciesversicolor        0.292  0.555   0.526  142  0.600      [-0.806,  1.390]
#>                Speciesvirginica       -0.567  0.588  -0.965  142  0.336      [-1.729,  0.595]
#>   Sepal.Width:Speciesversicolor       -0.387  0.191  -2.029  142  0.044 *    [-0.764, -0.010]
#>    Sepal.Width:Speciesvirginica       -0.210  0.188  -1.118  142  0.265      [-0.581,  0.161]
#> ─────────────────────────────────────────────────────────────────────────────────────────────
#> *** p < 0.001, ** p < 0.01, * p < 0.05, + p < 0.1
#> You can drag and resize the R console to view the entire table
#> 
#> Goodness of Fit
#> ───────────────────────────────────────────────────────────
#>      AIC    AICc      BIC     R²  R²_adjusted   RMSE      σ
#> ───────────────────────────────────────────────────────────
#>   78.797  80.082  105.892  0.871        0.865  0.296  0.305
#> ───────────────────────────────────────────────────────────
#> 
#> Model Assumption Check
#> OK: Residuals appear to be independent and not autocorrelated (p = 0.680).
#> OK: residuals appear as normally distributed (p = 0.855).
#> OK: No outliers detected.
#> - Based on the following method and threshold: cook (0.843).
#> - For variable: (Whole model)
#> 
#> OK: Error variance appears to be homoscedastic (p = 0.098).
#> Multicollinearity is not checked for models with interaction terms. You may check multicollinearity among predictors of a model without interaction terms
#>