Computes linear or binomial regressions in two steps : univariate regressions and a multivariate regressions. All the results are nicely displayed side by side with average marginal effects.

regtab(x, y, weights = NULL, continuous = "slopes", 
 show.ci = TRUE, conf.level = 0.95)

Arguments

x

data frame. The explanatory (i.e. independent) variables used in regressions. They can be numerical or factors.

y

vector. The outcome (i.e. dependent) variable. It can be numerical (linear regression) or a factor with 2 levels (binomial regression).

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

continuous

character. The kind of average marginal effects computed for continuous explanatory variables. If "slopes" (defaults), these are average marginal slopes. If "predictions", these are average marginal predictions for a set of values.

show.ci

logical. Whether to display the confidence intervals

conf.level

numerical value. Defaults to 0.95, which corresponds to a 95 percent confidence interval. Must be strictly greater than 0 and less than 1.

Details

This function is basically a wrapper for regression functions in the gtsummary function. It computes a series of univariate regressions (one for each explanatory variable), then a multivariate regression (with all explanatory variables) and displays the results side by side. These results are presented in the form of average marginal effects : average marginal predictions for categorical variables and average marginal slopes (or predictions) for continuous variables.

Besides, the function is compatible with the attribute labels assigned with labelled package : these labels are displayed automatically.

Value

an object of class tbl_merge from gtsummary package

Author

Nicolas Robette

References

Arel-Bundock V, Greifer N, Heiss A (Forthcoming). “How to Interpret Statistical Models Using marginaleffects in R and Python.” Journal of Statistical Software.

Larmarange J., 2024, “Prédictions marginales, contrastes marginaux & effets marginaux”, in Guide-R, Guide pour l’analyse de données d’enquêtes avec R, https://larmarange.github.io/guide-R/analyses/estimations-marginales.html

Examples

# \dontrun{
data(Movies)
regtab(x = Movies[, c("Genre", "Budget", "Festival", "Critics")],
       y = Movies$BoxOffice)
#> Setting theme "language: en"
univariate
multivariate
AME 95% CI AME 95% CI
Genre



    Action 729 283 [576 381 , 882 185] 463 821 [302 646 , 624 997]
    Animation 1 568 543 [1 278 958 , 1 858 129] 862 682 [410 175 , 1 315 189]
    Other 481 551 [96 366 , 866 735] 345 432 [18 657 , 672 207]
    ComDram 216 174 [55 271 , 377 076] 423 073 [353 345 , 492 800]
    Comedy 523 287 [391 468 , 655 107] 660 498 [551 305 , 769 690]
    Documentary 105 639 [-118 187 , 329 465] 385 156 [274 160 , 496 152]
    Drama 199 481 [72 964 , 325 997] 357 383 [294 411 , 420 355]
    Horror 411 130 [18 317 , 803 943] 550 285 [378 688 , 721 883]
    SciFi 1 935 583 [1 655 002 , 2 216 164] 1 026 707 [444 827 , 1 608 587]
Budget 0.02 [0.02 , 0.02] 0.02 [0.02 , 0.02]
Festival



    No 512 095 [441 262 , 582 928] 504 232 [449 044 , 559 419]
    Yes 546 129 [300 890 , 791 367] 640 389 [444 214 , 836 563]
Critics 67 581 [-12 528 , 147 690] 162 196 [95 537 , 228 854]
# }