3

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

Glen_b
  • 257,508
  • 32
  • 553
  • 939
DJJ
  • 208
  • 1
  • 4
  • 12

4 Answers4

9

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.

Glen_b
  • 257,508
  • 32
  • 553
  • 939
8

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.

ndoogan
  • 1,260
  • 8
  • 21
4

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

DJJ
  • 208
  • 1
  • 4
  • 12
oelshie
  • 56
  • 1
  • 2
  • 3
    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](/review/low-quality-posts/118559) – Sycorax Oct 01 '16 at 15:47
  • 1
    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". – oelshie Oct 08 '16 at 20:46
  • 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? – Mumbo.Jumbo Oct 03 '17 at 08:43
  • looks like the link changed... :D – Jakob Sep 03 '19 at 15:37
  • @Mumbo.Jumbo Did you find an R package that makes it easy to include lags in a longitudinal dataset for logistic regression? – Jeremy K. Feb 19 '20 at 06:04
  • link is broken. I updated it – DJJ Apr 07 '20 at 10:50
  • 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. – Noah Hammarlund Jun 05 '21 at 02:54
3

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.

generic_user
  • 11,981
  • 8
  • 40
  • 63