[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.017 (0.085) +     -1.644 (0.088) +     -0.045 (0.139)        8.642 (0.014) *    993.000  0.006
#>         y1    x1             m2          x1*m2   -0.004 (0.847)        0.114 (0.954)        0.012 (0.771)        3.459 (0.433)      993.000  0.005
#>         y1    x1             m3          x1*m3   -0.068 (0.463)        7.077 (0.446)        0.619 (0.460)      -60.230 (0.472)      993.000  0.004
#>         y1    x2             m1          x2*m1   -0.029 (0.766)        0.301 (0.756)       -0.052 (0.865)        4.493 (0.186)      993.000  0.005
#>         y1    x2             m2          x2*m2    0.250 (0.183)       -2.741 (0.143)       -0.643 (0.102)       11.070 (0.010) *    993.000  0.008
#>         y1    x2             m3          x2*m3    1.387 (0.188)      -13.514 (0.201)      -12.617 (0.183)      127.044 (0.182)      993.000  0.007
#>         y1    x3             m1          x3*m1    0.103 (0.042) *     -0.635 (0.054) +     -0.380 (0.020) *      6.551 (0.001) **   993.000  0.009
#>         y1    x3             m2          x3*m2   -0.059 (0.546)        0.090 (0.885)        0.055 (0.788)        4.395 (0.041) *    993.000  0.007
#>         y1    x3             m3          x3*m3    0.608 (0.221)       -3.382 (0.279)       -5.531 (0.216)       34.892 (0.215)      993.000  0.006
#>         y2    x1             m1          x1*m1   -0.002 (0.767)        0.271 (0.677)        0.012 (0.556)        9.273 (0.000) ***  993.000  0.003
#>         y2    x1             m2          x1*m2   -0.004 (0.741)        0.269 (0.840)        0.015 (0.591)        9.729 (0.001) **   993.000  0.004
#>         y2    x1             m3          x1*m3   -0.076 (0.225)        8.070 (0.199)        0.694 (0.220)      -62.546 (0.270)      993.000  0.004
#>         y2    x2             m1          x2*m1    0.104 (0.114)       -0.948 (0.147)       -0.363 (0.079) +     13.940 (0.000) ***  993.000  0.005
#>         y2    x2             m2          x2*m2    0.013 (0.917)       -0.304 (0.811)       -0.073 (0.783)       11.898 (0.000) ***  993.000  0.003
#>         y2    x2             m3          x2*m3   -1.092 (0.125)       11.407 (0.111)        9.780 (0.127)      -91.428 (0.156)      993.000  0.004
#>         y2    x3             m1          x3*m1    0.005 (0.874)        0.045 (0.839)       -0.007 (0.952)       10.474 (0.000) ***  993.000  0.002
#>         y2    x3             m2          x3*m2    0.045 (0.500)       -0.444 (0.293)       -0.081 (0.554)       11.666 (0.000) ***  993.000  0.003
#>         y2    x3             m3          x3*m3   -0.142 (0.673)        1.331 (0.530)        1.286 (0.671)       -1.272 (0.947)      993.000  0.002
#>         y3    x1             m1          x1*m1   -0.005 (0.696)        0.417 (0.752)        0.018 (0.670)       -0.228 (0.962)      993.000  0.002
#>         y3    x1             m2          x1*m2    0.009 (0.744)       -1.095 (0.685)       -0.016 (0.777)        3.297 (0.586)      993.000  0.002
#>         y3    x1             m3          x1*m3    0.161 (0.207)      -15.716 (0.218)       -1.450 (0.207)      142.647 (0.215)      993.000  0.003
#>         y3    x2             m1          x2*m1   -0.461 (0.001) ***    4.438 (0.001) ***    1.596 (0.000) ***  -13.781 (0.003) **   993.000  0.016
#>         y3    x2             m2          x2*m2   -0.143 (0.578)        1.196 (0.642)        0.513 (0.342)       -3.433 (0.562)      993.000  0.005
#>         y3    x2             m3          x2*m3    0.523 (0.718)       -4.988 (0.731)       -4.486 (0.730)       43.911 (0.737)      993.000  0.004
#>         y3    x3             m1          x3*m1    0.056 (0.424)       -0.447 (0.323)       -0.259 (0.246)        3.422 (0.216)      993.000  0.004
#>         y3    x3             m2          x3*m2    0.176 (0.192)       -1.284 (0.133)       -0.441 (0.114)        4.649 (0.115)      993.000  0.005
#>         y3    x3             m3          x3*m3    0.712 (0.297)       -4.003 (0.351)       -6.487 (0.290)       37.845 (0.327)      993.000  0.004
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> 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