Announcement

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

  • Sensitivity, Specificity, PPV, NPV.+likelihood,- likelihood

    Hi,
    I want to calculate sensitivity,specificity,PPV,NPV.+likelihood,- likelihhod ratio for my data set. I have transferred the data sheet from SPSS to STATA. My disease staus was coded in SPSS file into 1 (disease positive) and 2 (disease negative) and test variable- 1 (positive) and 2 (negative). After transferring into STATA, it is categorizing positive and negative automatically for disease and normal and abnormal under test variable thus giving me a wrong statistics. Kindly advise

  • #2
    Hi, Ankit.

    There are a few options. Have you tried -diagt-?

    Code:
    findit diagt
    Last edited by Tiago Pereira; 16 Apr 2025, 06:54.

    Comment


    • #3
      While coding dichotomous variables as 1 = positive 2 = negative is useful in some other statistical packages, the native commands in Stata expect the coding to be negative = 0 and positive = 1 (or some other non-zero value). I have no idea what you mean when you say "After transferring into STATA, it is categorizing positive and negative automatically for disease and normal and abnormal under test variable..." Whether you imported to Stata by using SPSS's Save As command or Stata's -import spss-, Stata is not going to change the numerical values of the variables. It seems to me that what you need is to -recode disease test (2 = 0)-. If the variables have value labels, you will need to modify those to reflect the change from 2 to 0 to represent negative/normal.

      Once you do that, the usual Stata commands for diagnostic tests, such as -lsens- and -lroc- or -roctab- will function properly. Or you can follow Tiago Pereira's suggestion in #2--it requires installing a user-written command, but that one will work with variable that contain any two distinct values.

      Comment


      • #4
        Thank you, sir, for your feedback. However, after categorizing my positive values as 1 and negative values as 0 in the STATA file, it is not generating the desired results. After putting the tab command between the gold standard and the test variable , my TP=78,FP=98,TN=123,FN=26, yielding a sensitivity of 44.3% and specificity of 82.6% as per diagt command. According to the formula, sensitivity is calculated as TP/(TP+FN) = 78/(78+26) = 75%. There is a discordance in the results. please help

        Comment


        • #5
          @Clyde Schechter
          Sir, one more thing I would like to bring to your kind notice is that when I give the diagtest command, sensitivity and specificity are displayed correctly as per the formula. However, with the diagt command, they are displayed incorrectly. I need PPV,NPV, likelihood +/- ratio, and odds ratio, which are covered under the diagt command, not in the diagtest command.

          Comment


          • #6
            Hello Ankit Bhardwaj. It would help others a lot if you used -dataex- to share a small dataset followed by the commands you are executing. See items 12.1 through 12.3 in the FAQ.
            --
            Bruce Weaver
            Email: [email protected]
            Version: Stata/MP 18.5 (Windows)

            Comment


            • #7
              You probably just need to get the orientation correct:
              Code:
              . diagti  78 26 98 123
              
                    True |
                 disease |      Test result
                  status |      Neg.       Pos. |     Total
              -----------+----------------------+----------
                  Normal |       123         98 |       221 
                Abnormal |        26         78 |       104 
              -----------+----------------------+----------
                   Total |       149        176 |       325 
              
                                                                [95% Confidence Interval]
              ---------------------------------------------------------------------------
              Prevalence                         Pr(A)     32.0%     27.0%      37.4%
              ---------------------------------------------------------------------------
              Sensitivity                      Pr(+|A)     75.0%     65.6%     83.0%
              Specificity                      Pr(-|N)     55.7%     48.8%     62.3%
              ROC area               (Sens. + Spec.)/2      0.65      0.60      0.71 
              ---------------------------------------------------------------------------
              Likelihood ratio (+)     Pr(+|A)/Pr(+|N)      1.69      1.41      2.03 
              Likelihood ratio (-)     Pr(-|A)/Pr(-|N)      0.45      0.32      0.64 
              Odds ratio                   LR(+)/LR(-)      3.77      2.25      6.30 
              Positive predictive value        Pr(A|+)     44.3%     36.8%     52.0% 
              Negative predictive value        Pr(N|-)     82.6%     75.5%     88.3% 
              ---------------------------------------------------------------------------
              Works for me.

              Comment


              • #8
                You may be on to something there, daniel klein. Most of the resources I am familiar with lay out the 2x2 table with test results in in the rows (T+ in row 1, T- in row 2) and disease status in the columns (D+ in column 1, D- in column 2). For your example in #7, the table would look like this:


                Code:
                           |          col
                       row |        D+         D- |     Total
                -----------+----------------------+----------
                        T+ |      a=78       b=98 |       176
                        T- |      c=26      d=123 |       149
                -----------+----------------------+----------
                     Total |       104        221 |       325

                Because that layout is so common (at least in the resources I know), I wish -diagt- had an option to use that layout.

                Paul T Seed, what do you reckon? Is there any chance of adding that option? Thanks for considering.
                --
                Bruce Weaver
                Email: [email protected]
                Version: Stata/MP 18.5 (Windows)

                Comment

                Working...
                X