[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.006 (0.370)        -0.640 (0.318)        -0.020 (0.325)         3.300 (0.173)      993.000  0.008
#>         y1    x1             m2          x1*m2    -0.015 (0.253)         1.601 (0.231)         0.028 (0.312)        -2.020 (0.508)      993.000  0.007
#>         y1    x1             m3          x1*m3     0.001 (0.988)        -0.851 (0.902)        -0.012 (0.984)         8.867 (0.886)      993.000  0.007
#>         y1    x2             m1          x2*m1    -0.051 (0.426)         0.447 (0.490)         0.078 (0.690)         0.383 (0.867)      993.000  0.008
#>         y1    x2             m2          x2*m2    -0.149 (0.245)         1.565 (0.226)         0.231 (0.384)        -1.584 (0.593)      993.000  0.008
#>         y1    x2             m3          x2*m3     0.457 (0.507)        -5.310 (0.443)        -4.179 (0.500)        49.356 (0.427)      993.000  0.008
#>         y1    x3             m1          x3*m1     0.038 (0.215)        -0.294 (0.130)        -0.133 (0.167)         1.968 (0.123)      993.000  0.009
#>         y1    x3             m2          x3*m2     0.062 (0.328)        -0.298 (0.460)        -0.144 (0.271)         1.691 (0.234)      993.000  0.007
#>         y1    x3             m3          x3*m3    -0.029 (0.928)        -0.554 (0.782)         0.245 (0.933)         6.008 (0.738)      993.000  0.007
#>         y2    x1             m1          x1*m1    -0.009 (0.165)         0.801 (0.213)         0.030 (0.144)        -2.160 (0.372)      993.000  0.005
#>         y2    x1             m2          x1*m2    -0.009 (0.500)         0.777 (0.559)         0.022 (0.439)        -1.228 (0.686)      993.000  0.003
#>         y2    x1             m3          x1*m3     0.070 (0.307)        -6.125 (0.375)        -0.625 (0.309)        55.636 (0.371)      993.000  0.004
#>         y2    x2             m1          x2*m1     0.013 (0.843)        -0.214 (0.740)        -0.124 (0.527)         2.179 (0.339)      993.000  0.005
#>         y2    x2             m2          x2*m2     0.128 (0.315)        -1.413 (0.273)        -0.352 (0.186)         4.550 (0.126)      993.000  0.005
#>         y2    x2             m3          x2*m3    -1.452 (0.038) *      15.418 (0.028) *      12.971 (0.039) *    -136.941 (0.030) *    993.000  0.009
#>         y2    x3             m1          x3*m1     0.001 (0.970)        -0.095 (0.621)        -0.014 (0.883)         1.033 (0.416)      993.000  0.003
#>         y2    x3             m2          x3*m2     0.020 (0.748)        -0.236 (0.557)        -0.051 (0.692)         1.262 (0.372)      993.000  0.002
#>         y2    x3             m3          x3*m3    -0.446 (0.170)         3.526 (0.080) +       3.989 (0.171)       -30.809 (0.089) +    993.000  0.005
#>         y3    x1             m1          x1*m1    -0.004 (0.495)         0.338 (0.598)         0.006 (0.774)        -0.855 (0.723)      993.000  0.005
#>         y3    x1             m2          x1*m2     0.022 (0.097) +      -2.104 (0.117)        -0.053 (0.061) +       4.535 (0.140)      993.000  0.006
#>         y3    x1             m3          x1*m3     0.011 (0.875)        -0.571 (0.934)        -0.104 (0.865)         5.399 (0.930)      993.000  0.003
#>         y3    x2             m1          x2*m1    -0.050 (0.437)         0.407 (0.533)         0.206 (0.299)        -2.323 (0.312)      993.000  0.005
#>         y3    x2             m2          x2*m2     0.153 (0.231)        -1.418 (0.271)        -0.246 (0.354)         1.731 (0.559)      993.000  0.004
#>         y3    x2             m3          x2*m3    -1.136 (0.101)        11.850 (0.088) +      10.278 (0.099) +    -107.628 (0.085) +    993.000  0.005
#>         y3    x3             m1          x3*m1     0.007 (0.828)        -0.136 (0.480)        -0.004 (0.965)        -0.231 (0.855)      993.000  0.004
#>         y3    x3             m2          x3*m2    -0.003 (0.958)         0.132 (0.743)         0.023 (0.862)        -0.940 (0.506)      993.000  0.002
#>         y3    x3             m3          x3*m3     0.317 (0.325)        -1.368 (0.493)        -2.834 (0.327)        11.666 (0.514)      993.000  0.003
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
#> 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