View source: R/estimatr_lh_robust.R

lh_robust | R Documentation |

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

```
lh_robust(..., data, linear_hypothesis)
```

`...` |
Other arguments to be passed to |

`data` |
A |

`linear_hypothesis` |
A character string or a matrix specifying combination, to be passed to the hypothesis.matrix argument of car::linearHypothesis
See |

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`

.

An object of class `"lh_robust"`

containing the two following components:

`lm_robust` |
an object as returned by |

`lh` |
A data frame with most of its columns pulled from |

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.

```
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)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.