Announcement

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

  • 2x3 categorical interaction

    Hi Listers,

    I want to make sure I am correctly interpreting my 2*3 interaction following a logistic regression. My predictors are sex (m vs. f) and task type (easy vs. medium vs. high) on completion rates (yes/no).

    I find including the interaction term in my model does improve the fit using a likelihood ratio test so I would like to know what is going on. Male and easy are the reference in my anlalysis category as coded as 0. logistic pass i.sex##i..task

    To compare females (to males) for each test type, I use the following:

    logistic pass i.sex#i..task i.task

    which a colleague pointed out is equivalent to:

    lincom 1.sex_n+1.sex#0.task
    lincom 1.sex_n+1.sex#1.task
    lincom 1.sex_n+1.sex#2.task

    Is this correct?

    I am unsure why, in the lincom statement, only sex and the interaction term are included but not task - any explanation would be much appreciated.

    Thanks,
    Laura




  • #2
    Hi Laura. It sounds to me as if you want to examine the effect of sex for each task separately. If so, perhaps you can adapt this example.

    Code:
    clear *
    use http://www.stata-press.com/data/r15/lbw.dta
    
    // Variables smoke and race have 2 and 3 levels respectively.
    logistic low i.smoke##i.race
    // Show log-odds of outcome for each cell
    margins smoke#race, predict(xb)
    // Examine effect of smoke at each level of race
    margins r.smoke@race, predict(xb) contrast(nowald effects)
    HTH.
    --
    Bruce Weaver
    Email: [email protected]
    Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
    Version: Stata/MP 18.0 (Windows)

    Comment


    • #3
      Hi Bruce,

      Thanks for your reply. It works just fine and when I adapt your command to my data
      margins r.sex@task, predict(xb) contrast(nowald effects) produces estimates akin to when I use: logistic pass i.sex#i..task i.task

      So I feel more confident that the latter approach is working - it seems to be computing the ratio of the odds as calculated by:

      margins sex#task

      Thanks again!

      Comment


      • #4
        No worries, Laura. If you want to express the simple effects sex as odds ratios, you could tack on a few more lines of code, like this:

        Code:
        clear *
        use http://www.stata-press.com/data/r15/lbw.dta
        
        // Variables smoke and race have 2 and 3 levels respectively.
        logistic low i.smoke##i.race
        // Show log-odds of outcome for each cell
        margins smoke#race, predict(xb)
        // Examine effect of smoke at each level of race
        margins r.smoke@race, predict(xb) contrast(nowald effects)
        // ADDED LINES BEGIN HERE
        // Save results to working dataset
        matrix t = r(table)'
        matrix list t
        svmat t
        browse t*
        // Express the contrasts odds ratios
        generate double OR = exp(t1)
        generate double Lower = exp(t5)
        generate double Upper = exp(t6)
        rename (t1 t2 t5 t6) (LogOR SE lower upper)
        list LogOR SE lower upper OR Lower Upper in 1/3
        Output from the final list command:

        Code:
        . list LogOR SE lower upper OR Lower Upper in 1/3
        
             +--------------------------------------------------------------------------------+
             |    LogOR         SE       lower      upper          OR       Lower       Upper |
             |--------------------------------------------------------------------------------|
          1. | 1.750516   .5982763    .5779162   2.923116   5.7575745   1.7823206   18.599156 |
          2. | 1.193923   .8411752   -.4547507   2.842596   3.3000002   .63460616   17.160249 |
          3. | .2231435   .6491753   -1.049217   1.495504        1.25   .35021199   4.4615837 |
             +--------------------------------------------------------------------------------+

        --
        Bruce Weaver
        Email: [email protected]
        Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
        Version: Stata/MP 18.0 (Windows)

        Comment


        • #5
          That's great, thank you!

          Comment

          Working...
          X