Announcement

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

  • Wilcoxon matched-pairs signed-ranks test

    Hello,

    I've tried using the signrank function with before/after data with equal before and after values. I understand it is necessary to exclude pairs that are equal (x2i - x1i = 0) but the function doesn't do that. I need to add an if statement to the function to exclude those cases (I'm using the dataset from the manual which I modifiy to have equal paired values):

    gen delta=MPG1-MPG2
    signrank MPG1= MPG2 if delta!=0

    This gives me the correct total sum values and the correct p value whereas if I don't add the if statement, the total sum values are those I find if I rank equal pairs (by hand or using an online calculator).

    Maybe there is something I don't understand. Has anyone had the same problem? What is the use of including paired equal values (statistical significance?)

    M. CATALA

  • #2
    I'm not sure if I understood your query.

    Unfortunately, you didn't clarify which command you performed in the data set so as to it to "modify to have equal paired values".

    That said, using the same data set, albeit I didn't envisage the reason you decided to exclude the observations where there was no difference between pre-post values, you can see below that your second command gives the same results (including the sum of ranks = 66, instead of 78) when you drop the only observation with zero delta:

    Code:
    . webuse fuel
    
    . signrank mpg1=mpg2
    
    Wilcoxon signed-rank test
    
            sign |      obs   sum ranks    expected
    -------------+---------------------------------
        positive |        3        13.5        38.5
        negative |        8        63.5        38.5
            zero |        1           1           1
    -------------+---------------------------------
             all |       12          78          78
    
    unadjusted variance      162.50
    adjustment for ties       -1.63
    adjustment for zeros      -0.25
                         ----------
    adjusted variance        160.63
    
    Ho: mpg1 = mpg2
                 z =  -1.973
        Prob > |z| =   0.0485
    
    . gen delta = mpg2-mpg1
    
    . gen id = _n
    
    . list mpg1 mpg2 delta id in 1/12
    
         +--------------------------+
         | mpg1   mpg2   delta   id |
         |--------------------------|
      1. |   20     24       4    1 |
      2. |   23     25       2    2 |
      3. |   21     21       0    3 |
      4. |   25     22      -3    4 |
      5. |   18     23       5    5 |
         |--------------------------|
      6. |   17     18       1    6 |
      7. |   18     17      -1    7 |
      8. |   24     28       4    8 |
      9. |   20     24       4    9 |
     10. |   24     27       3   10 |
         |--------------------------|
     11. |   23     21      -2   11 |
     12. |   19     23       4   12 |
         +--------------------------+
    
    . signrank mpg1=mpg2 if delta !=0
    
    Wilcoxon signed-rank test
    
            sign |      obs   sum ranks    expected
    -------------+---------------------------------
        positive |        3        10.5          33
        negative |        8        55.5          33
            zero |        0           0           0
    -------------+---------------------------------
             all |       11          66          66
    
    unadjusted variance      126.50
    adjustment for ties       -1.63
    adjustment for zeros       0.00
                         ----------
    adjusted variance        124.88
    
    Ho: mpg1 = mpg2 
                 z =  -2.013
        Prob > |z| =   0.0441
    
    . drop if id ==3
    (1 observation deleted)
    
    . signrank mpg1=mpg2
    
    Wilcoxon signed-rank test
    
            sign |      obs   sum ranks    expected
    -------------+---------------------------------
        positive |        3        10.5          33
        negative |        8        55.5          33
            zero |        0           0           0
    -------------+---------------------------------
             all |       11          66          66
    
    unadjusted variance      126.50
    adjustment for ties       -1.63
    adjustment for zeros       0.00
                         ----------
    adjusted variance        124.88
    
    Ho: mpg1 = mpg2
                 z =  -2.013
        Prob > |z| =   0.0441

    Hopefully that helps,

    Best,

    Marcos
    Best regards,

    Marcos

    Comment


    • #3
      Thank you. My question was about the test necessitating removing all equal pairs before ranking and Stata's ranksum test not doing this without specifically asking for it using an if statement or dropping pairs with equal values.
      The first command gives zero with rank sum 1 (means that pair was assigned rank number one). This will lead to having a p value different from what you get if you apply the test by hand or using an online calculator or using R. I was just wondering why the Stata command does not do this in the first place; are there analyses where you would rank equal pairs in the Wilcoxon rank sum test?

      Comment


      • #4
        ​Mathias:
        some remarks on this topic are covered under -signrank- entry in Stata 13.1 .pdf manual (page 2153-2154).
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X