- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I am trying to calculate sensitivity and specificity of a test (e.g. test2) with reference to a standard test (e.g. test1). I am interested to know a way where I can calculate sensitivity and specificity without multiple proc freq steps. A sample of my data is gievn below:
data sensitivity_study;
input test1 test2;
datalines;
1 1
1 0
0 1
0 0
1 1
1 0
0 0
0 0
0 0
0 0
;
run;
Thank you in advance for your kind reply.
With Regards,
Deepak
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This could give you a start . data sensitivity_study; input test1 test2; datalines; 1 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 ; run; proc sql; select test1,sum(test1=test2)/count(*) as sensitivity, case when test1=0 then 'specificity' else 'sensitivity' end as name from sensitivity_study group by test1; quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is the same as this question, essentially.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This could give you a start . data sensitivity_study; input test1 test2; datalines; 1 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 ; run; proc sql; select test1,sum(test1=test2)/count(*) as sensitivity, case when test1=0 then 'specificity' else 'sensitivity' end as name from sensitivity_study group by test1; quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp,
Great solution as I have been looking for without generating 2 by 2 table.
Thanks.
With Kind regards,
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp,
Is it possible to extend this code to calculate PPV and NPV.
Thank you in advance for your kind reply.
Regards,
Deepak
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Technically , it could be . Give us formula about them .
Or you could change
sum(test1=test2)/count(*)
into
sum(test1 ne test2)/count(*)
and see whether it is what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp,
I tried the following sas code but could not generate the desired result.
data sensitivity_study;
input test1 test2;
datalines;
1 1
1 0
0 1
0 0
1 1
1 0
0 0
0 0
0 0
0 0
;
run;
proc sql;
select test1,sum(test1 ne test2)/count(*) as ppv,
case when test1=0 then 'NPV' else 'PPV' end as name
from sensitivity_study
group by test1;
quit;
Can you kindly help me further.
Positive Predictive Value =True Positive/(True Positive + False Positive) |
Negative Predictive Value=True Negative/(True Negative + False Negative) Thank you in advance for your kind reply. Regards, Deepak |
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The logic is to write a sum statement with the conditions inside the sum statement that meet your requirements, ie true positive is test1=1 and test2=1.
The first link I posted demonstrates this a bit. You should be able to extend the logic already provided to your new scenario. Please try and post what you've tried and isn't working if you need further help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
OK. Just change GROUP variable into TEST2. data sensitivity_study; input test1 test2; datalines; 1 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 ; run; proc sql; select test2,sum(test1=test2)/count(*) as ppv, case when test2=0 then 'NPV' else 'PPV' end as name from sensitivity_study group by test2; quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ksharp,
Kindly accept my apology for the delayed reply. Your tips has worked nicely and has provided me a very simple way to calulate Sensitivity, Specificity, PPV, NPV without creating 2 by 2 table.
Thanks a lot for your honest effort to help me.
Appreciated.
Regards,
Deepak