regression: Customized all-in-one regression function

Description Usage Arguments Examples

View source: R/regression.R

Description

Function performs default regression via ordinary least squares. It also supports dummy variables which are not included in the dataset data, but in a global variable attached to a formula. With this input, this function can filter for a subset, remove outliers at a certain cutoff and remove dummies that are NA.

Usage

1
2
regression(formula, data = NULL, subset = NULL, dummies = NULL,
  cutoff = NULL, rmDummyNA = TRUE, vcov = NULL)

Arguments

formula

of type formula.

data

An optional data frame contain the variables in the model (excluding the dummy variables).

subset

Vector of integers or booleans defining the subset of observations to be used.

dummies

String denoting the name of the variable (i.e. matrix or data frame) containing all dummy variables.

cutoff

Relative cutoff on each side in percent (default: NULL). Values are given in percient, e.g. 0.5 represents 0.5% at each end).

rmDummyNA

Boolean indicating whether to remove dummy variables with NA coefficient (default: removal).

vcov

Estimator used for computing the covariance matrix. Default is NULL which results in to the ordinary least squares estimator. Alternatives, are, for instance, NeweyWest from the sandwich package.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
x <- 1:100
clusters <- rep(c(1, 2), 50)
dummies <- model.matrix(~ clusters)
y <- x + clusters + rnorm(100)
d <- data.frame(x = x, y = y)

m <- regression(formula("y ~ x + dummies"), data = d, subset = 1:90,
                dummies = "dummies", cutoff = 0.5)
summary(m)

library(sandwich)
m <- regression(formula("y ~ x + dummies"), data = d, subset = 1:90,
                dummies = "dummies", cutoff = 0.5, vcov = NeweyWest)
summary(m)

sfeuerriegel/ResearchGroupTools documentation built on May 29, 2019, 8:01 p.m.