Announcement

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

  • Chi2 test for Trend

    Hi,

    I am interested to perform a chi2 test for trend on my data, where Y variable is binary and X variable are my timepoints. I want to see if the positive increase over time is significant. Would the stata command nptrend be the right way of doing this?


    Thank you very much,

    Palvin

  • #2
    You don't mention whether your data are clustered (correlated across time). If they're independent, then take a look at the StataCorp FAQ for tests for trend and scroll down to the section with with the term "Cochran–Armitage test" in its title. (Be sure to continue reading the next two sections, as well.)

    Comment


    • #3
      Thank you Joseph. It is independent. I have seen this page - but I was not very clear. Hope you can help me out.

      1. Wat are the differences between nptrend and ptrend.
      2. Is the stata command of cochran armitage, 'ptrend x1 y"?
      3. the chi2(2) for departure in the ptrend output would give the cochran armitage p value?

      thank you very much Joseph.

      Comment


      • #4
        I read the FAQ as saying that if you want the Cochran-Armitage test for trend using official Stata commands, then do the following:

        .ÿversionÿ14.1

        .ÿ
        .ÿclearÿ*

        .ÿsetÿmoreÿoff

        .ÿinputÿbyteÿ(xÿcount0ÿcount1)ÿÿÿÿ

        ÿÿÿÿÿÿÿÿÿÿÿÿxÿÿÿÿcount0ÿÿÿÿcount1
        ÿÿ1.ÿ1ÿÿÿ19ÿÿÿÿ1
        ÿÿ2.ÿ2ÿÿÿ31ÿÿÿÿ5
        ÿÿ3.ÿ3ÿÿÿ67ÿÿÿ21
        ÿÿ4.ÿend

        .ÿ
        .ÿquietlyÿreshapeÿlongÿcount,ÿi(x)ÿj(y)

        .ÿ
        .ÿquietlyÿcorrelateÿyÿxÿ[fweight=count]

        .ÿtempnameÿQtrend

        .ÿscalarÿdefineÿ`Qtrend'ÿ=ÿr(N)ÿ*ÿr(rho)^2

        .ÿdisplayÿinÿsmclÿasÿtextÿ"Qtrendÿ=ÿ"ÿasÿresultÿ`Qtrend'ÿ///
        >ÿÿÿÿÿasÿtextÿ",ÿpÿ=ÿ"ÿasÿresultÿchi2tail(1,ÿ`Qtrend')
        Qtrendÿ=ÿ4.5464579,ÿpÿ=ÿ.03298692

        .ÿ
        .ÿexit

        endÿofÿdo-file


        .


        And you could instead do the following
        Code:
        regress y c.x [fweight=count]
        test x
        But they really recommended that you do the following if you insist upon a linear trend, because it also gives you a test of departure from linearity
        Code:
        vwls y c.x [fweight=count]
        To which I would add
        Code:
        glm y c.x i.x [fweight=count], family(binomial) link(identity) nolog
        as an alternative to consider.

        Comment

        Working...
        X