[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

glm_model_explore(
  data,
  response_variable,
  predictor_variable,
  family,
  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 = c(0, 1)
)

Arguments

data

data.frame

response_variable

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

predictor_variable

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

family

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

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 = sample(c(0, 1), size = 1000, replace = TRUE),
y2 = sample(c(0, 1), size = 1000, replace = TRUE),
y3 = sample(c(0, 1), size = 1000, replace = TRUE),
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)
)

glm_model_explore(data = test, 
                 response_variable = c(y1,y2,y3),
                 predictor_variable = c(x1,x2,x3),
                 two_way_interaction_variable = c(m1,m2,m3),
                 family = binomial(link = 'logit'),
                 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.007 (0.245)       -0.739 (0.257)       -0.022 (0.286)        2.938 (0.206)      993.000  0.004
#>         y1    x1             m2          x1*m2   -0.018 (0.190)        1.862 (0.179)        0.036 (0.194)       -2.917 (0.331)      993.000  0.004
#>         y1    x1             m3          x1*m3   -0.004 (0.946)       -0.277 (0.966)        0.040 (0.945)        3.232 (0.955)      993.000  0.004
#>         y1    x2             m1          x2*m1   -0.103 (0.112)        1.041 (0.109)        0.355 (0.079) +     -2.889 (0.221)      993.000  0.006
#>         y1    x2             m2          x2*m2    0.242 (0.063) +     -2.344 (0.070) +     -0.417 (0.107)        4.866 (0.081) +    993.000  0.007
#>         y1    x2             m3          x2*m3    1.335 (0.042) *    -14.121 (0.033) *    -11.964 (0.043) *    127.413 (0.033) *    993.000  0.009
#>         y1    x3             m1          x3*m1    0.002 (0.959)        0.003 (0.988)        0.023 (0.827)        0.622 (0.628)      993.000  0.003
#>         y1    x3             m2          x3*m2   -0.044 (0.521)        0.314 (0.468)        0.113 (0.412)        0.030 (0.982)      993.000  0.004
#>         y1    x3             m3          x3*m3    0.435 (0.163)       -3.334 (0.094) +     -3.884 (0.166)       30.603 (0.088) +    993.000  0.006
#>         y2    x1             m1          x1*m1    0.000 (0.967)        0.042 (0.948)       -0.001 (0.962)        0.020 (0.993)      993.000  0.002
#>         y2    x1             m2          x1*m2   -0.016 (0.250)        1.852 (0.184)        0.031 (0.269)       -3.398 (0.259)      993.000  0.006
#>         y2    x1             m3          x1*m3    0.029 (0.652)       -2.840 (0.658)       -0.260 (0.651)       25.798 (0.655)      993.000  0.001
#>         y2    x2             m1          x2*m1    0.201 (0.003) **    -1.938 (0.004) **    -0.651 (0.002) **     6.634 (0.007) **   993.000  0.012
#>         y2    x2             m2          x2*m2    0.009 (0.947)        0.179 (0.889)       -0.077 (0.764)        0.422 (0.879)      993.000  0.006
#>         y2    x2             m3          x2*m3   -0.790 (0.223)        7.978 (0.223)        7.062 (0.227)      -71.113 (0.227)      993.000  0.003
#>         y2    x3             m1          x3*m1   -0.029 (0.375)        0.246 (0.243)        0.112 (0.277)       -0.786 (0.541)      993.000  0.004
#>         y2    x3             m2          x3*m2    0.021 (0.757)        0.126 (0.772)       -0.019 (0.890)       -0.182 (0.896)      993.000  0.005
#>         y2    x3             m3          x3*m3   -0.285 (0.355)        1.766 (0.369)        2.590 (0.350)      -15.841 (0.371)      993.000  0.002
#>         y3    x1             m1          x1*m1    0.001 (0.904)       -0.069 (0.915)        0.009 (0.659)       -1.915 (0.409)      993.000  0.006
#>         y3    x1             m2          x1*m2    0.008 (0.585)       -0.558 (0.687)       -0.003 (0.902)       -1.012 (0.736)      993.000  0.008
#>         y3    x1             m3          x1*m3   -0.095 (0.143)        8.947 (0.169)        0.866 (0.138)      -82.659 (0.158)      993.000  0.008
#>         y3    x2             m1          x2*m1    0.036 (0.572)       -0.357 (0.576)       -0.106 (0.593)        0.086 (0.971)      993.000  0.003
#>         y3    x2             m2          x2*m2   -0.010 (0.937)        0.292 (0.819)        0.016 (0.950)       -1.530 (0.579)      993.000  0.005
#>         y3    x2             m3          x2*m3   -0.998 (0.125)        9.500 (0.147)        8.990 (0.125)      -86.554 (0.143)      993.000  0.006
#>         y3    x3             m1          x3*m1    0.028 (0.389)       -0.170 (0.416)       -0.059 (0.566)       -0.633 (0.622)      993.000  0.004
#>         y3    x3             m2          x3*m2    0.073 (0.284)       -0.255 (0.556)       -0.121 (0.381)       -0.634 (0.648)      993.000  0.006
#>         y3    x3             m3          x3*m3    0.375 (0.226)       -2.767 (0.162)       -3.351 (0.229)       23.697 (0.183)      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