4
$\begingroup$

I would like to perform a Fixed effect logit estimation in R. Can someone point out a package that can do the job?

Note: For the time being I'm not really interested in the random effect.

Update;

Essentially I wonder if there is the plm package for a binary response model.

Here is some documentation for the plm package:

http://cran.r-project.org/web/packages/plm/index.html
http://dss.princeton.edu/training/Panel101.pdf

$\endgroup$
1
  • $\begingroup$ It might help to post the head() of your data. $\endgroup$
    – Jack Ryan
    Mar 26, 2014 at 18:09

4 Answers 4

4
$\begingroup$

There is a new R Package called "bife" that performs Fixed Effects binary logit Models.

https://cran.r-project.org/web/packages/bife/vignettes/howto.html

$\endgroup$
7
  • 4
    $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$
    – Sycorax
    Oct 1, 2016 at 15:47
  • 1
    $\begingroup$ Sycorax, in general you're right, but the question was "Can someone point out a package that can do the job?". Therefore, I don't see why my answer doesn't include "the essential parts of the answer here". $\endgroup$
    – theRman
    Oct 8, 2016 at 20:46
  • $\begingroup$ Thanks for the link. I think the package is best for FE logit model in R. However, I want to include lags of dependent & independent variables in logit regression of daily time series dataset. Is there any package for it? $\endgroup$ Oct 3, 2017 at 8:43
  • $\begingroup$ looks like the link changed... :D $\endgroup$
    – Jakob
    Sep 3, 2019 at 15:37
  • 1
    $\begingroup$ Be careful to those reading this as the correct answer and read the other answers below. The bife package performs the demeaned/dummy variable version of fixed effects but using a logistic function. This is not quite analogous to how this operation works for a linear model and the math breaks down (see generic_user's answer below). As Glen_b says below, usually when economists etc refer to "logistic model with fixed effects" they are referring to a conditional logistic regression as in the xtlogit command in STATA. the clogit command in the survival package is closer. $\endgroup$ Jun 5, 2021 at 2:54
10
$\begingroup$

If you mean logistic regression, for example, along the lines of

$Y_i\sim\text{Bernoulli}(1,p_i)\,$, with

$\text{logit}(p_i) = X\beta\,$,

(equivalently, $P[Y_i=1] = \frac{\exp(X\beta)}{1+\exp(X\beta)},$)

then use glm. For example:

glm(y~x1+x2,family=binomial)

There are examples in the help at ?glm.predict, ?infert and ?esoph.

If you mean fitting a logistic curve via least squares, like

$E(Y) = \alpha \cdot(\frac{\exp(\beta_0+\beta_1 x)}{1+\exp(\beta_0+\beta_1 x)})$

then use nls. There's an example of fitting a logistic function in the help at ?nls.

Both are part of the standard R installation.

If you mean something else, you need to clarify what you want.


I see from this answer that apparently economists use 'fixed effect model' to refer to a conditional logit model, even though it's far from the only fixed effect model involving a logit. Who would have thought.

As ndoogan mentions in one of the other answers, there's a conditional logistic regression model (clogit) in the survival package.

$\endgroup$
8
$\begingroup$

I'm almost certain that you mean conditional logistic regression. This will estimate the within-group relationship between your independent variables and your binary dependent variable. It's similar to adding a dummy for each individual (as in fixed effects). In which case, use the clogit() function in the survival package that is included with R.

$\endgroup$
5
$\begingroup$

Standard fixed effects assumptions break down in nonlinear models (like logit).

When you can assume gaussian disturbance, you can model: $$ y_{it} = X_{it}\beta + u_{it}\\ y_{it} = X_{it}\beta + \alpha_i + \epsilon_{it}\\ y_{it} - \bar{y}_i = (X_{it}-\bar{X}_i) \beta + \alpha_i - \bar\alpha_i + \epsilon_{it} -\bar\epsilon_i\\ y_{it}^{dm} = X_{it}^{dm} \beta + \epsilon_{it}^{dm} $$ where $dm$ is the deviation from the mean. This is the within transformation. You get rid of all of your time-invariant heterogeneity, and if you can make an argument that $E[\epsilon_{it}|X,\alpha]=0$, then $\beta$ gets a causal interpretation.

Try this math with a logit link functions and you'll see that it all breaks down. Other approaches exist -- one of the other answerers suggested conditional logit.

$\endgroup$
1
  • $\begingroup$ This is true but hardly comes close to answering the question. $\endgroup$ Mar 22, 2020 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.