Announcement

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

  • LRTEST poisson vs negative binomial loop

    Hello everyone, im testing over dispersion in a count variable. I'm using Hilbe's book "Negative binomial regression" for the analysis. He used the formula LR = −2(LP − LNB), but calculate it by hand and then used chiprob(1, result)/2. All my independent variables are presence or ausence of drug consumption, that means i have to adjust models separately.

    local sus binoh bintab binmar bincoc binpas
    foreach var of local sus {
    poisson num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
    estimates store m1
    nbreg num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
    estimates store m2
    lrtest m1 m2
    }

    test involves different estimators: nbreg vs. poisson

    this is what i got. And it make sense because im not using the same function. I need to store the log likelihood of my models and then use the formula, but i dont know how to make it efficient.

    Please, i need some ideas. Thank you very much.

  • #2
    LP=Log likelihood poisson; LNB=Log likelihood negative binomial

    Comment


    • #3
      You do not need to do the test by hand, just use the -force- option to override the error.

      Code:
      lrtest m1 m2, force

      Comment


      • #4
        Thank you Andrew, that worked for me. I improved my code and this is what i got.

        Code:
        local sus binoh bintab binmar bincoc binpas
        foreach var of local sus {
        poisson num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
        scalar m1 = e(11)
        nbreg num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
        scalar m2 = e(11)
        lrtest m1 m2, force
        }
        Code:
        11 invalid name
        I got this error. it seems that i cant store e(11) in a loop, im missing something important.

        Comment


        • #5
          You are now mixing the manual approach and my suggestion. m1 and m2 refer to models in the lrtest syntax, not scalars.

          Code:
          local sus binoh bintab binmar bincoc binpas
          foreach var of local sus{
              poisson num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
              estimates store m1
              nbreg num_psex `var' sexo i.or_sexual i.tramo_etario edad_inicio nse
              estimates store m2
             lrtest m1 m2, force
          }

          Comment


          • #6
            Thank you Andrew, you were right, i was mixing de approaches. Now it worked perfectly.

            Comment

            Working...
            X