modular_regressions: Modular regressions

Description Usage Arguments Details Value References Examples

View source: R/modular_regressions.r

Description

The function allows to automatically specify a number of regression models based on an input of a dependent variable, independent variables, control variables, interaction terms, and model structure.

Usage

1
  modular_regressions(type = "glm", fam = "gaussian", dv, cv = NULL, iv, mv, fe = NULL, robust_type = 0, var_cluster = NULL, data, full_model = TRUE, show = TRUE, show_cv = FALSE)

Arguments

type

character variable indicating the model type, takes "glm" or "glmer"

fam

character variable indicating the model familiy, takes: "gaussian" or "binomial"

dv

character variable indicating the name of the dependt variable

cv

character variable or vector thereof indicating the name of the control variables, take NULL as input

iv

character variable indicating the name of the independt variable

mv

character variable or vector thereof indicating the name of the moderator variables

fe

character variable or vector thereof indicating the name of the fixed effect variables

robust_type

Indicator which type of standard errors is to be computed: 0 - no clustering, 1 - clustering using var_cluster, 2 - clustering using var_cluster with bootstraping

var_cluster

Vector, matrix, or data.frame containing the variables that are used for clustering

data

data.frame used to run the regression models - all variables are taken from data

full_model

logical variable whether a full model, including all indicatred interaction terms, should be computed

show

logical variable indicating whether output is printed to consolde or returned as data.frame

show_cv

logical variable indicating whether output should include intercept and control variables

Details

The function runs a series of models of type and familiy. When type == "glmer" is selected, the variables defined in fe are used to compute random intercepts, i.e. "(1 | fe)". First, the function runs a controls only model regressing cv on dv. Next, a base model is computed as dv = f(cv + iv). Then a series of interaction models with all combinations of iv and mv is computed. If full_model is set to TRUE, a full model with all combinations of iv and mv in it is added. For type "glm" the options robust_type == 0, robust_type == 1, and robust_type == 2 control how the variance-covariance matrix for standard error estimation is computed. The options robust_type == 1 and robust_type == 2 require a cluster variable defined in var_cluster. type "glmer" requires one or more variables to compute fixed effects defined in fe.

Value

The output is a list of three elements, named "coefficents", "p.values", and "std.errors". Each of the list elements shows the coeffient estimates, p-values, and standard errors for the computed models, respectively.

When the option show is set to TRUE the output is printed to the console. If the package knitr is available, the output is printed using knitr::kable. When show and show_cv are set to TRUE the output is printed using package stargazer.

References

model_vcov, lmer, glmer

Examples

1
2
3
4
5
6
7
8
9
  data <- supportR::create_data()

  modular_regressions(type = "glm", fam = "gaussian", dv = "firm_value", cv = c("rnd", "competition", "quality"), iv = "profit", mv = c("cogs", "board_size"), robust_type = 0, data = data, full_model = TRUE, show = TRUE, show_cv = FALSE)
  modular_regressions(type = "glm", fam = "gaussian", dv = "firm_value", iv = "profit", mv = c("cogs", "board_size"), robust_type = 2, var_cluster = "industry", data = data, full_model = FALSE, show = TRUE, show_cv = FALSE)
  modular_regressions(type = "glmer", fam = "gaussian", dv = "firm_value", cv = c("rnd", "competition", "quality"), iv = "profit", mv = c("cogs", "board_size"), fe = "industry", data = data, full_model = TRUE, show = FALSE, show_cv = FALSE)
  
  modular_regressions(type = "glm", fam = "binomial", dv = "female_ceo", cv = c("rnd", "competition", "quality"), iv = "profit", mv = c("cogs", "board_size"), robust_type = 0, var_cluster = NULL, data = data, full_model = TRUE, show = TRUE, show_cv = TRUE)
  modular_regressions(type = "glm", fam = "binomial", dv = "female_ceo", cv = c("rnd", "competition", "quality"), iv = "profit", mv = c("cogs", "board_size"), robust_type = 2, var_cluster = "industry", data = data, full_model = FALSE, show = TRUE, show_cv = FALSE)
  modular_regressions(type = "glmer", fam = "binomial", dv = "female_ceo", iv = "profit", mv = c("cogs", "board_size"), fe = "industry", data = data, full_model = TRUE, show = TRUE, show_cv = FALSE)

ha-pu/supportR documentation built on Sept. 13, 2020, 5:52 p.m.