Learn R Programming

estimatr (version 0.30.6)

lh_robust: Linear Hypothesis for Ordinary Least Squares with Robust Standard Errors

Description

This function fits a linear model with robust standard errors and performs linear hypothesis test.

Usage

lh_robust(..., data, linear_hypothesis)

Arguments

...

Other arguments to be passed to lm_robust

data

A data.frame

linear_hypothesis

A character string or a matrix specifying combination, to be passed to the hypothesis.matrix argument of car::linearHypothesis See linearHypothesis for more details.

Value

An object of class "lh_robust" containing the two following components:

lm_robust

an object as returned by lm_robust.

lh

A data frame with most of its columns pulled from linearHypothesis' output.

The only analyis directly performed by lh_robust is a t-test for the null hypothesis of no effects of the linear combination of coefficients as specified by the user. All other output components are either extracted from linearHypothesis or lm_robust.

The original output returned by linearHypothesis is added as an attribute under the "linear_hypothesis" attribute.

Details

This function is a wrapper for lm_robust and for linearHypothesis. It first runs lm_robust and next passes "lm_robust" object as an argument to linearHypothesis.

Examples

Run this code
# NOT RUN {
library(fabricatr)
dat <- fabricate(
  N = 40,
  y = rpois(N, lambda = 4),
  x = rnorm(N),
  z = rbinom(N, 1, prob = 0.4),
  clusterID = sample(1:4, 40, replace = TRUE)
)

# Default variance estimator is HC2 robust standard errors
lhro <- lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0")

# The linear hypothesis argument can be specified equivalently as:
lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z = 2x")
lh_robust(y ~ x + z, data = dat, linear_hypothesis = "2*x +1*z")
lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0")

# Also recovers other sorts of standard erorrs just as specified in \code{\link{lm_robust}}
lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0", se_type = "classical")
lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0", se_type =  "HC1")

#  Can tidy() main output and subcomponents in to a data.frame
lhro <- lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0")
tidy(lhro )
tidy(lhro$lm_robust)
tidy(lhro$lh)

# Can use summary() to get more statistics on the main output and subcomponents.
summary(lhro)
summary(lhro$lm_robust)
summary(lhro$lh)

# }

Run the code above in your browser using DataLab