Moritz Schwarz
Moritz Schwarz

Reputation: 2489

Extract degrees of freedom from a fixest feols object

simple question: Can I extract the final degrees of freedom after a feols estimation using the fixest package?

res = feols(Sepal.Length ~ Sepal.Width + Petal.Length | Species, iris)
summary(res)

I know that there are many fancy ways to specify the df in fixest, but I'd just want the result (depending on which option I choose).

For example in the lfe package using felm, I can do so easily like this:

res = felm(Sepal.Length ~ Sepal.Width + Petal.Length | Species | 0 | 0, iris)
res$df

Thanks!

Upvotes: 2

Views: 596

Answers (3)

Laurent Bergé
Laurent Bergé

Reputation: 1372

What you're looking for is: degrees_freedom(res, "resid", vcov = "iid")


The VCOV has an influence on the values produced by degrees_freedom. Here's an explanation.

By default:

  • the VCOV is clustered wrt the first fixed-effect (if FEs are present)
  • when the VCOV is clustered, FEs that are nested with the cluster are dropped in the DoF calculation (to avoid over-penalization)

The number 3 obtained in degrees_freedom(res, "k") is not the number of fixed-effects. It's the number of regressors, excluding the nested FEs (and adding the intercept).

By changing the way the VCOV is computed, you change the output of degrees_freedom. Here the nestedness is the problem, so you can remove it:

degrees_freedom(res, "resid", vcov = cluster ~ ssc(fixef.K = "full"))
#> [1] 145

But the easiest way is to use an "iid" VCOV.


Agreed the help page only implicitly refers to this by saying that the values depend on the type of VCOV. This could be clearer, I'll try to improve that!

Upvotes: 4

jay.sf
jay.sf

Reputation: 72673

We may find them after summary in the attributes of the scaled covariance matrix, check str(summary(res)).

attr(summary(res)$cov.scaled, 'dof.K')
# [1] 3

Upvotes: 2

akrun
akrun

Reputation: 887038

There is a degrees_freedom

> degrees_freedom(res, type = "k")
[1] 3
> degrees_freedom(res, type = "resid")
[1] 147
> degrees_freedom(res, type = "t")
[1] 2

By changing the type, can get different degrees of freedom i.e ?degrees_freedom shows

type - Character scalar, equal to "k", "resid", "t". If "k", then the number of regressors is returned. If "resid", then it is the "residuals degree of freedom", i.e. the number of observations minus the number of regressors. If "t", it is the degrees of freedom used in the t-test. Note that these values are affected by how the VCOV of x is computed, in particular when the VCOV is clustered.


Or may use

fitstat(res, "g", simplify = TRUE)

Or could be

unname(res$fixef_sizes)

Upvotes: 3

Related Questions