Skip to contents

Given a model returned by a function such as lm() and one or more expressions to evaluate, construct a point estimate and confidence intervals on the expression(s) using the exact delta method. Estimate p-values using the t distribution as an exact finite-sample distribution.

Usage

lincom(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")

lincom(model, wt + 3, 2 * hp)
#> # A tibble: 2 × 7
#>   Expression Estimate `Std. Error` `t-Value` `Pr(>|t|)` `CI Lower` `CI Upper`
#>   <chr>         <dbl>        <dbl>     <dbl>      <dbl>      <dbl>      <dbl>
#> 1 wt + 3      -0.878        0.651      -1.35  0.188        -2.21       0.454 
#> 2 2 * hp      -0.0635       0.0140     -4.55  0.0000882    -0.0921    -0.0350

# equivalently, supply your own parameter names
library(glue)
lincom(model, b2 + 3, 2 * b3, params = glue("b{1:3}"))
#> # A tibble: 2 × 7
#>   Expression Estimate `Std. Error` `t-Value` `Pr(>|t|)` `CI Lower` `CI Upper`
#>   <chr>         <dbl>        <dbl>     <dbl>      <dbl>      <dbl>      <dbl>
#> 1 b2 + 3      -0.878        0.651      -1.35  0.188        -2.21       0.454 
#> 2 2 * b3      -0.0635       0.0140     -4.55  0.0000882    -0.0921    -0.0350
#> 
#>  Where b1=(Intercept), b2=wt, b3=hp