Announcement

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

  • friedman test

    Hello,
    Can we use Friedman test to compare two dependent variables between two groups?
    xpose is required before friedman test, is there a way to perform the test in the ordinary wide arrangement of the data?
    Best regards,

  • #2
    With regard to the first question: no. That wouldn’t be the Friedman test. Maybe you wish to take a look at the structural equation model (SEM) approach.

    With regard to the second question: first, friedman is a user-written program whose author is Rich Goldstein, a very active member of this Forum. That said, there is the user-written skilmack program. I’ve never used it, since it is aimed at Friedman style test with missing data. The good news are: you won’t need to transpose in order to perform the test.

    Hopefully that helps.
    Last edited by Marcos Almeida; 03 May 2020, 17:17.
    Best regards,

    Marcos

    Comment


    • #3
      Be careful about ties when using that user written command: https://www.statalist.org/forums/for...ings-mack-test.

      Comment


      • #4
        I wrote the Friedman test ado file many years ago because a client insisted on it; over the years a number of people have asked if I minded if they took it over and re-wrote to be more friendly and I always said, "fine - do it"; however, no one has so it remains as is; I have never used it since that client and don't expect I ever will so I will not be re-writing it

        why do you want to use it? - maybe someone can suggest an alternative

        Comment


        • #5
          Although it's intended for more versatile use in computing Cochran-Mantel-Haenszel statistics, the user-written emh (for "extended Mantel-Haenszel") command from SSC will also do Friedman's test.

          It gets the same results as shown in Dave's post for R's implementation of the Friedman test.

          .ÿ
          .ÿversionÿ16.1

          .ÿ
          .ÿclearÿ*

          .ÿ
          .ÿquietlyÿimportÿexcelÿ"GrangerÿData.xlsx",ÿsheet(Sheet1)ÿfirstrow

          .ÿlist,ÿnoobsÿseparator(0)

          ÿÿ+-----------+
          ÿÿ|ÿAÿÿÿBÿÿÿCÿ|
          ÿÿ|-----------|
          ÿÿ|ÿ8ÿÿÿ8ÿÿÿ7ÿ|
          ÿÿ|ÿ7ÿÿÿ6ÿÿÿ6ÿ|
          ÿÿ|ÿ6ÿÿÿ8ÿÿÿ6ÿ|
          ÿÿ|ÿ8ÿÿÿ9ÿÿÿ7ÿ|
          ÿÿ|ÿ5ÿÿÿ8ÿÿÿ5ÿ|
          ÿÿ|ÿ9ÿÿÿ7ÿÿÿ7ÿ|
          ÿÿ|ÿ7ÿÿÿ7ÿÿÿ7ÿ|
          ÿÿ|ÿ8ÿÿÿ7ÿÿÿ7ÿ|
          ÿÿ|ÿ8ÿÿÿ6ÿÿÿ8ÿ|
          ÿÿ|ÿ7ÿÿÿ6ÿÿÿ6ÿ|
          ÿÿ|ÿ7ÿÿÿ8ÿÿÿ6ÿ|
          ÿÿ|ÿ9ÿÿÿ9ÿÿÿ6ÿ|
          ÿÿ+-----------+

          .ÿ
          .ÿgenerateÿbyteÿpidÿ=ÿ_n

          .ÿ
          .ÿrenameÿ(AÿBÿC)ÿsco=

          .ÿquietlyÿreshapeÿlongÿsco,ÿi(pid)ÿj(Cdn)ÿstring

          .ÿencodeÿCdnÿ,ÿgenerate(cdn)ÿlabel(Conditions)

          .ÿ
          .ÿemhÿscoÿcdn,ÿanovaÿstrata(pid)ÿtransformation(rank)

          ExtendedÿMantel-Haenszelÿ(Cochran-Mantel-Haenszel)ÿStratifiedÿTestÿofÿAssociation

          ANOVAÿ(RowÿMeanÿScores)ÿStatistic:
          Qÿ(2)ÿ=ÿÿ7.6000,ÿPÿ=ÿ0.0224ÿ
          Transformation:ÿRanks


          .ÿ
          .ÿexit

          endÿofÿdo-file


          .

          Comment


          • #6
            Thanks for these comprehensive replies
            I would like to compare heart failure class (4 grades) before and after two treatments. Do you think EMH is suitable for this comparison?
            I used Silkmack before to compare the change in Dyspnea grade (4 grades) before and after heart transplantation cause I couldn't perform Friedman in Stata, but I got questions from the reviewers why I used this test, as they believe it can be used only if there are missing data. How the results of Smack test in comparison to Friedman test?
            Thanks again
            Last edited by Amr Ahmed; 06 May 2020, 15:28.

            Comment


            • #7
              Originally posted by Amr Ahmed View Post
              I would like to compare heart failure class (4 grades) before and after two treatments. Do you think EMH is suitable for this comparison?
              If you're looking for assessing a treatment × time interaction term, then no.

              Comment


              • #8
                There is no time variable, we assessing the grade pre and post surgery in two groups

                Comment


                • #9
                  Originally posted by Amr Ahmed View Post
                  There is no time variable, we assessing the grade pre and post surgery in two groups
                  Pre and post represent the time variable. You're looking for something akin to
                  Code:
                  manova pre_nyha post_nyha = i.trt
                  manovatest , test(-1 1 0) ytransform(1 -1)
                  which tests the treatment × time interaction, just the same as reshaping the dataset long forming an explicit time variable and fitting a regression model with the treatment-by-time interaction term made explicit. See the illustration below to see what I mean about their equivalence and about the presence of a time factor, implicit in the pre/post (a.k.a., mulitvariate, wide) arrangement such as you think of your dataset, and explicit in the long form.

                  .ÿ
                  .ÿversionÿ16.1

                  .ÿ
                  .ÿclearÿ*

                  .ÿ
                  .ÿsetÿseedÿ`=strreverse("1551702")'

                  .ÿ
                  .ÿquietlyÿdrawnormÿout0ÿout1,ÿdoubleÿcorr(1ÿ0.5ÿ\ÿ0.5ÿ1)ÿn(24)

                  .ÿgenerateÿbyteÿpidÿ=ÿ_n

                  .ÿgenerateÿbyteÿtrtÿ=ÿmod(_n,ÿ2)

                  .ÿ
                  .ÿ*
                  .ÿ*ÿBeginÿhere
                  .ÿ*
                  .ÿquietlyÿmanovaÿout0ÿout1ÿ=ÿi.trt

                  .ÿtempnameÿCÿT

                  .ÿmatrixÿinputÿ`C'ÿ=ÿ(-1ÿÿ1ÿ0)

                  .ÿmatrixÿinputÿ`T'ÿ=ÿ(ÿ1ÿ-1)

                  .ÿmanovatestÿ,ÿtest(`C')ÿytransform(`T')

                  ÿTransformationÿofÿtheÿdependentÿvariables
                  ÿ(1)ÿÿÿÿout0ÿ-ÿout1

                  ÿTestÿconstraint
                  ÿ(1)ÿÿÿÿ-ÿ0.trtÿ+ÿ1.trtÿ=ÿ0

                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿWÿ=ÿWilks'ÿlambdaÿÿÿÿÿÿLÿ=ÿLawley-Hotellingÿtrace
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPÿ=ÿPillai'sÿtraceÿÿÿÿÿRÿ=ÿRoy'sÿlargestÿroot

                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿSourceÿ|ÿStatisticÿÿÿÿÿÿÿÿdfÿÿÿÿF(df1,ÿÿÿÿÿdf2)ÿ=ÿÿÿFÿÿÿProb>F
                  ÿÿÿÿÿÿÿÿÿÿ-----------+-------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿmanovatestÿ|Wÿÿÿ0.9331ÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.58ÿ0.2225ÿe
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Pÿÿÿ0.0669ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.58ÿ0.2225ÿe
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Lÿÿÿ0.0716ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.58ÿ0.2225ÿe
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|Rÿÿÿ0.0716ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1.0ÿÿÿÿÿ22.0ÿÿÿÿÿ1.58ÿ0.2225ÿe
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|-------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿResidualÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ22
                  ÿÿÿÿÿÿÿÿÿÿ-------------------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿeÿ=ÿexact,ÿaÿ=ÿapproximate,ÿuÿ=ÿupperÿboundÿonÿF

                  .ÿ
                  .ÿquietlyÿreshapeÿlongÿout,ÿi(pid)ÿj(tim)

                  .ÿquietlyÿmixedÿoutÿi.trt##i.timÿ||ÿpid:ÿ,ÿremlÿdfmethod(satterthwaite)ÿ///
                  >ÿÿÿÿÿÿÿÿÿnoconstantÿresiduals(unstructured,ÿt(tim))ÿnolrtestÿnolog

                  .ÿcontrastÿR.trt#tim,ÿsmall

                  Contrastsÿofÿmarginalÿlinearÿpredictions

                  Marginsÿÿÿÿÿÿ:ÿasbalanced

                  -----------------------------------------------------------
                  ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿdfÿÿÿÿÿÿÿÿddfÿÿÿÿÿÿÿÿÿÿÿFÿÿÿÿÿÿÿÿP>F
                  -------------+---------------------------------------------
                  outÿÿÿÿÿÿÿÿÿÿ|
                  ÿÿÿÿÿtrt#timÿ|ÿÿÿÿÿÿÿÿÿÿ1ÿÿÿÿÿÿ22.00ÿÿÿÿÿÿÿÿ1.58ÿÿÿÿÿ0.2225
                  -----------------------------------------------------------

                  .ÿ
                  .ÿexit

                  endÿofÿdo-file


                  .


                  So, what I said in #7 holds. You'd probably be better off with your NYHA class data in long format with patient ID to identify the pairs and using something like meologit in a hierarchical regression model that is directly analogous to the mixed example that I illustrate immediately above. Or perhaps using the preoperative NYHA class as a covariate and using something like ologit in a manner analogous to ANCOVA.

                  Comment


                  • #10
                    following up on #4 above, Nick Cox has reminded me about the 2004 version (which I thank Nick for doing); so if you want to use the friedman command directly, ensure that you have the most recent version:
                    Code:
                    . which friedman
                    /Users/rich/Library/Application Support/Stata/ado/plus/f/friedman.ado
                    *! 2.0.1 NJC 27 Nov 2004
                    *! 1.01 Richard Goldstein  17 July 1991

                    Comment


                    • #11
                      Looking at that ado code, I see the formulas used were from 2.11 and 2.8 and on page 458 of the Gibbons reference (4th edition, PDF found online, connect at your own risk, <http://erecursos.uacj.mx/bitstream/handle/20.500.11961/2064/Gibbons%2C%202003.pdf?sequence=14&isAllowed=y>) where it goes on to describe further corrections if ties are present. Ties were just something I stumbled on previously.

                      Comment

                      Working...
                      X