Skip to contents

Given a model returned by a function such as lm() and one or more expressions to evaluate, jointly test the null hypothesis that the expression are all zero, using the exact delta method to construct an F statistic. This is a finite-sample Wald test.

Usage

test(model, ..., vcov. = NULL, params = NULL)

Arguments

model

A linear model, fit by a call to lm, feols, or lm_robust

...

One or more expressions involving parameters in model

vcov.

Optional specify the covariance of the model. Can be a matrix, function or lambda. Defaults to stats::vcov(model)

params

Optional character vector. rename the model parameters to make them easier to refer to in your expressions in ...

Details

There are two ways to refer to model parameters in your expressions.

  • The names of your model coefficients, such as educ and abil. Note that "strange" expressions that do not evaluate to a symbol in R code must be surrounded by backticks, e.g. `(Intercept)` or `educ:abil`.

  • Using the names supplied as the params argument to this function. The order of the coefficients is the order returned by coef(model).

By default, the covariances of the model parameters are taken from the stats::vcov() function. This is a generic function that will produce different results for different model types. That means that lm() models will have a homoskedastic covariance matrix, whereas feols and lm_robust models will have the type of robust covariance matrix that you specify when creating the model. You can override this default behavior by using the vcov. argument.

Examples

library(fixest)
model <- feols(mpg ~ wt + hp, data = mtcars, vcov = "HC1")

test(model, wt + 3, 2 * hp)
#> Error in summaryTable.test(x): object 'model' not found

# equivalently, supply your own parameter names
library(glue)
test(model, wt + 3, 2 * hp, params = glue("b{1:3}"))
#> Error in purrr::map_dbl(exprs, quo_eval):  In index: 1.
#> Caused by error:
#> ! object 'wt' not found