Linear Hypothesis for Ordinary Least Squares with Robust Standard Errors
Linear Hypothesis for Ordinary Least Squares with Robust Standard Errors
This function fits a linear model with robust standard errors and performs linear hypothesis test.
lh_robust(..., data, linear_hypothesis)
Arguments
...: Other arguments to be passed to lm_robust
data: A data.frame
linear_hypothesis: A length 1 character string or a matrix specifying combination, to be passed to the hypothesis.matrix argument of car::linearHypothesis. Joint hypotheses are currently not handled by lh_robust. See linearHypothesis for more details.
Returns
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 analysis 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. Note that the estimate returned is the value of the LHS of an equation of the form f(X) = 0. Hyptheses "x - z = 1", "x +1= z + 2" and "x-z-1=0" will all return the value for "x-y-1"
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. Currently CR2 standard errors are not handled by lh_robust.
Examples
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 errorslhro <- 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.framelhro <- 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)