[Experimental]
Exploratory analyses for linear regression models with multiple response, predictor, and two-way interaction variables. (lm models). At the moment, multi-categorical variables are not supported as predictors or interactions (but control is fine). Binary variable should be numeric instead of factor

lm_model_explore(
  data,
  response_variable,
  predictor_variable,
  two_way_interaction_variable = NULL,
  three_way_interaction_variable = NULL,
  control_variable = NULL,
  marginal_alpha = 0.1,
  verbose = TRUE,
  show_p = TRUE,
  return_result = FALSE,
  print_control = FALSE,
  plot_interaction = FALSE,
  file_dir = NULL,
  device = "jpeg",
  width = 8.5,
  height = 5,
  units = "in",
  y_lim = NULL
)

Arguments

data

data.frame

response_variable

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

predictor_variable

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

two_way_interaction_variable

Two-way interaction variable. Each two-way interaction variable will interact with each pred variable. Support dplyr::select() syntax.

three_way_interaction_variable

Three-way interaction variable. Each three-way interaction variable will interact with each pred and two-way interaction variables. Support dplyr::select() syntax.

control_variable

Control variables. Support dplyr::select() syntax.

marginal_alpha

Set marginal_alpha level for marginally significant (denoted by .). Set to 0.05 if do not want marginally significant denotation.

verbose

Default is TRUE. Set to FALSE to suppress outputs

show_p

Default is TRUE. When TRUE, show the p-value in parenthesis.

return_result

Default is FALSE. If TRUE, it returns the model estimates as a data frame.

print_control

Default is FALSE. If TRUE, print coefficients of control variables.

plot_interaction

Default is FALSE. If TRUE, interactions will be plotted and saved on your laptop.

file_dir

Path of the directory to save plot to

device

Default is "jpeg". See ggplot2::ggsave() for all options.

width

Default is 8.5 (i.e., letter size width).

height

Default is 5.

units

Default is inches. Options are "in", "cm", "mm" or "px".

y_lim

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

Value

data.frame

Examples


test = data.frame(y1 = rnorm(1000,2,3),
y2 = rnorm(1000,10,2),
y3 = rnorm(1000,1,4),
x1 = rnorm(1000,100,10),
x2 = rnorm(1000,10,1),
x3 = rnorm(1000,6,2),
m1 = rnorm(1000,3,1),
m2 = rnorm(1000,2,0.5),
m3 = rnorm(1000,9,0.1),
c1 = rnorm(1000,5,0.4),
c2 = rnorm(1000,2,0.2),
c3 = rnorm(1000,7,0.9)
)


lm_model_explore(data = test, 
                 response_variable = c(y1,y2,y3),
                 predictor_variable = c(x1,x2,x3),
                 two_way_interaction_variable = c(m1,m2,m3),
                 control_variable = c(c1,c2,c3))
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>   Response  Pred  Interact_pred  Interact_term    Interact_term_coef    Interact_pred_coef             Pred_coef           (Intercept)       df     r2
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#>         y1    x1             m1          x1*m1     0.001 (0.935)        -0.216 (0.819)        -0.008 (0.787)         5.840 (0.105)      993.000  0.007
#>         y1    x1             m2          x1*m2    -0.028 (0.190)         2.856 (0.176)         0.048 (0.258)        -0.559 (0.904)      993.000  0.007
#>         y1    x1             m3          x1*m3    -0.027 (0.769)         2.818 (0.761)         0.238 (0.774)       -20.259 (0.808)      993.000  0.005
#>         y1    x2             m1          x2*m1     0.017 (0.869)        -0.314 (0.766)        -0.002 (0.995)         4.985 (0.186)      993.000  0.007
#>         y1    x2             m2          x2*m2    -0.062 (0.760)         0.720 (0.724)         0.172 (0.675)         2.539 (0.565)      993.000  0.005
#>         y1    x2             m3          x2*m3     0.543 (0.552)        -5.352 (0.564)        -4.837 (0.557)        52.082 (0.533)      993.000  0.005
#>         y1    x3             m1          x3*m1    -0.124 (0.019) *       0.602 (0.069) +       0.440 (0.010) **      2.295 (0.262)      993.000  0.013
#>         y1    x3             m2          x3*m2     0.079 (0.412)        -0.387 (0.532)        -0.097 (0.620)         4.819 (0.027) *    993.000  0.007
#>         y1    x3             m3          x3*m3    -0.338 (0.478)         2.209 (0.464)         3.103 (0.470)       -15.835 (0.560)      993.000  0.006
#>         y2    x1             m1          x1*m1    -0.002 (0.712)         0.211 (0.743)         0.017 (0.408)         7.851 (0.001) **   993.000  0.003
#>         y2    x1             m2          x1*m2     0.008 (0.569)        -0.839 (0.561)        -0.006 (0.833)        10.161 (0.001) **   993.000  0.003
#>         y2    x1             m3          x1*m3     0.099 (0.118)       -10.149 (0.108)        -0.878 (0.122)        99.793 (0.079) +    993.000  0.006
#>         y2    x2             m1          x2*m1     0.068 (0.339)        -0.710 (0.324)        -0.290 (0.198)        12.604 (0.000) ***  993.000  0.003
#>         y2    x2             m2          x2*m2     0.147 (0.290)        -1.488 (0.287)        -0.373 (0.183)        13.299 (0.000) ***  993.000  0.003
#>         y2    x2             m3          x2*m3     0.645 (0.302)        -6.860 (0.279)        -5.890 (0.295)        72.145 (0.206)      993.000  0.003
#>         y2    x3             m1          x3*m1    -0.071 (0.050) +       0.399 (0.079) +       0.177 (0.128)         8.673 (0.000) ***  993.000  0.006
#>         y2    x3             m2          x3*m2    -0.056 (0.395)         0.330 (0.436)         0.069 (0.606)         9.194 (0.000) ***  993.000  0.003
#>         y2    x3             m3          x3*m3    -0.512 (0.117)         2.729 (0.186)         4.564 (0.120)       -14.688 (0.429)      993.000  0.005
#>         y3    x1             m1          x1*m1    -0.004 (0.743)         0.253 (0.839)         0.013 (0.740)        -2.040 (0.667)      993.000  0.004
#>         y3    x1             m2          x1*m2    -0.011 (0.679)         0.964 (0.729)         0.024 (0.674)        -3.283 (0.592)      993.000  0.003
#>         y3    x1             m3          x1*m3    -0.049 (0.690)         6.678 (0.583)         0.437 (0.690)       -61.206 (0.576)      993.000  0.005
#>         y3    x2             m1          x2*m1    -0.032 (0.815)         0.169 (0.903)         0.179 (0.680)        -2.484 (0.617)      993.000  0.004
#>         y3    x2             m2          x2*m2    -0.069 (0.796)         0.511 (0.849)         0.216 (0.690)        -3.054 (0.599)      993.000  0.003
#>         y3    x2             m3          x2*m3    -1.223 (0.310)        14.250 (0.243)        11.097 (0.306)      -130.255 (0.236)      993.000  0.006
#>         y3    x3             m1          x3*m1    -0.012 (0.865)        -0.083 (0.849)         0.022 (0.923)        -0.784 (0.772)      993.000  0.004
#>         y3    x3             m2          x3*m2    -0.038 (0.766)         0.048 (0.953)         0.061 (0.813)        -1.280 (0.655)      993.000  0.003
#>         y3    x3             m3          x3*m3     0.301 (0.632)         0.029 (0.994)        -2.713 (0.631)        -1.321 (0.971)      993.000  0.005
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> You can drag and resize the R console to view the entire table
#> Note: Coefficient (p-value): + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001