-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassi.ado
94 lines (90 loc) · 4.34 KB
/
classi.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
*! version 1.0.0 February 10, 2009 @ 16:50:37
*! immediate classification table
program define classi, rclass
version 9
syntax anything(everything)
local cnt 1
tokenize `"`anything'"', parse("\")
if `"`2'"'!="\" | `"`4'"'!="" {
Usage
}
tokenize `"`1' `3'"'
if `"`4'"'=="" | `"`5'"'!="" {
Usage
}
local cnt 1
local letters "a b c d"
foreach letter of local letters {
capture confirm integer number ``cnt''
if _rc {
Usage
}
if ``cnt'' < 0 {
Usage
}
local `letter' ``cnt''
local ++cnt
}
ret scalar P_corr = ((`a'+`d')/(`a'+`b'+`c'+`d'))*100
ret scalar P_p1 = (`a'/(`a'+`c'))*100 // sensitivity
ret scalar P_n0 = (`d'/(`b'+`d'))*100 // specificity
ret scalar P_p0 = (`b'/(`b'+`d'))*100 // false + given ~D
ret scalar P_n1 = (`c'/(`a'+`c'))*100 // false - given D
ret scalar P_1p = (`a'/(`a'+`b'))*100 // + pred value
ret scalar P_0n = (`d'/(`c'+`d'))*100 // - pred value
ret scalar P_0p = (`b'/(`a'+`b'))*100 // false + given +
ret scalar P_1n = (`c'/(`c'+`d'))*100 // false - given -
global S_1 "`return(P_corr)'"
global S_2 "`return(P_p1)'"
global S_3 "`return(P_n0)'"
global S_4 "`return(P_p0)'"
global S_5 "`return(P_n1)'"
global S_6 "`return(P_1p)'"
global S_7 "`return(P_0n)'"
global S_8 "`return(P_0p)'"
global S_9 "`return(P_1n)'"
di _n as text "Immediate classification table"
di _n in smcl as text _col(15) "{hline 8} True {hline 8}" _n ///
`"Classified {c |}"' _col(22) `"D"' _col(35) ///
`"~D {c |}"' _col(46) `"Total"'
di in smcl as text "{hline 11}{c +}{hline 26}{c +}{hline 11}"
di in smcl as text _col(6) "+" _col(12) `"{c |} "' ///
as result %9.0g `a' _col(28) %9.0g `b' ///
as text `" {c |} "' ///
as result %9.0g `a'+`b'
di in smcl as text _col(6) "-" _col(12) "{c |} " ///
as result %9.0g `c' _col(28) %9.0g `d' ///
as text `" {c |} "' ///
as result %9.0g `c'+`d'
di in smcl as text "{hline 11}{c +}{hline 26}{c +}{hline 11}"
di in smcl as text `" Total {c |} "' ///
as result %9.0g `a'+`c' _col(28) %9.0g `b'+`d' ///
as text `" {c |} "' ///
as result %9.0g `a'+`b'+`c'+`d'
di _n in smcl as text "{hline 50}"
di as text `"Sensitivity"' _col(33) `"Pr( +| D)"' ///
as result %8.2f return(P_p1) `"%"' _n ///
as text `"Specificity"' _col(33) `"Pr( -|~D)"' ///
as result %8.2f return(P_n0) `"%"' _n ///
as text `"Positive predictive value"' _col(33) `"Pr( D| +)"' ///
as result %8.2f return(P_1p) `"%"' _n ///
as text `"Negative predictive value"' _col(33) `"Pr(~D| -)"' ///
as result %8.2f return(P_0n) `"%"'
di in smcl as text "{hline 50}"
di as text `"False + rate for true ~D"' _col(33) `"Pr( +|~D)"' ///
as result %8.2f return(P_p0) `"%"' _n ///
as text `"False - rate for true D"' _col(33) `"Pr( -| D)"' ///
as result %8.2f return(P_n1) `"%"' _n ///
as text `"False + rate for classified +"' _col(33) `"Pr(~D| +)"' ///
as result %8.2f return(P_0p) `"%"' _n ///
as text `"False - rate for classified -"' _col(33) `"Pr( D| -)"' ///
as result %8.2f return(P_1n) `"%"'
di in smcl as text "{hline 50}"
di as text `"Correctly classified"' _col(42) ///
as result %8.2f return(P_corr) `"%"'
di in smcl as text "{hline 50}"
end
program Usage
display as error "specify cells as a b \ c d, where a, b, c, and d are non-negative integers"
exit 198
end