Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logit linear assumption

    Hello! I am attempting to test the logit regression assumption that independent variables will have a linear relationship to the logit of the dependent. As I understand it, the code to test this would be the following: gen logitdependent= logit(dependent) twoway (scatter logitdependent independent) From the following, you would be able to at least visually see a linear (or not) relationship. However, my use of logit(dependent) creates a variable with no observations and thus nothing to plot. If I use a log(dependent) function, my variable has observations and depicts a scatter plot. I'm wondering if a. This is the best or appropriate code or manner of testing this assumption and b. if so, why is the logit function seemingly eliminating my observations? As I am relatively new to stata and logistic regression, I apologize for any simply oversights I may have displayed here. Thanks, Matt

  • #2
    try -lowess- with the logic option

    Comment


    • #3
      Note that the logits of the observed dependent variables (0 and 1) are plus and minus infinity, so they're going to be missing in Stata.

      Comment


      • #4
        To follow up on Rich's suggestion, what you're looking for sounds like a logit analogue of what Frank E. Harrell, Jr.,* calls a calibration plot, which itself is basically a (continuous, graphical) LOWESS analogue of the discrete Hosmer-Lemeshow goodness-of-fit test. I don't have the book in front of me now, but I recall that, in consideration of his audience, he plots predicted probability against the LOWESS smooth of the 0/1 observed values, instead of the linear predictor against logit transforms (which, although smoothed and thus present, aren't visible in the plot for the reason that Brendan mentioned). I've illustrated both in the code below.

        If you're interested in just "testing" for deviation from linearity in your logit model fit, then you can do that by adding a polynomial term in your model and using a likelihood-ratio test (see below).

        *Harrell FE Jr. Regression modeling strategies: with applications to linear models, logistic regression, and survival analysis New York: Springer; 2001.

        Code:
        version 13.1
        
        clear *
        set more off
        
        sysuse auto
        logit foreign c.turn, nolog
        
        *
        * Calibration plot
        *
        predict double pr, pr
        lowess foreign turn, mcolor(black) lineopts(lcolor(black) lpattern(dash)) ///
            addplot((line pr turn, lcolor(black) lpattern(solid))) ///
            ytitle(Pr(Foreign)) ylabel(, angle(horizontal) nogrid) ///
            title("") subtitle("") note("") legend(off)
        pause on
        pause
        
        *
        * Logit analogue
        *
        predict double xb, xb
        lowess foreign turn, logit mcolor(black) lineopts(lcolor(black) lpattern(dash)) ///
            addplot((line xb turn, lcolor(black) lpattern(solid))) ///
            ytitle(Linear Predictor) ylabel(, angle(horizontal) nogrid) ///
            title("") subtitle("") note("") legend(off)
        
        *
        * "Test" of nonlinearity
        *
        summarize turn, meanonly
        generate double c_turn = turn - r(mean)
        logit foreign c.c_turn##c.c_turn, nolog
        estimates store Full
        quietly logit foreign c.c_turn, nolog
        lrtest Full
        
        exit

        Comment

        Working...
        X