-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_logistic.ado
85 lines (56 loc) · 1.83 KB
/
validate_logistic.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
/***
# Title
__validate_logistic__ --- Calculate optimism corrected measures of logistic model performance
## Syntax
__validate_logistic__, [reps(str) seed(str)]
- - -
Options:
> __reps__ (_str_): The number of bootstrap replicates to calculate optimism. Defaults to 50.
> __seed__ (_str_): The seed for the bootstrap simulation. Defaults to 1.
- - -
## Description
This command calculates the optimism corrected measures of AUC and the Brier score for a previously estimated logistic regression model.
## Example
getvdata sex.age.response
logistic response i.sex age
validate_logistic
***/
capture program drop validate_logistic
program validate_logistic
syntax , [reps(str) seed(str)]
if inlist("`e(cmd)'", "logistic", "logit") != 1 {
display "This command is for logistic regression."
display "The most recent estimation command was " "`e(cmd)'"
exit
}
if "`reps'" == "" {
local reps = "50"
display "setting reps(" "`reps'" ")"
}
if "`seed'" == "" {
local seed = "1"
display "setting seed(" "`seed'" ")"
}
qui tempfile tmpfile
qui save `tmpfile'
tokenize `"`e(cmdline)'"'
predict _phat, pr
quietly brier `e(depvar)' _phat
local obs_auc = r(roc_area)
local obs_brier = r(brier)
drop _phat
qui simulate delta_auc = r(delta_auc) delta_brier = r(delta_brier), reps(`reps') seed(`seed'): logistic_one_delta, command(`e(cmdline)')
//hist delta_auc
qui summarize delta_auc
local corrected_auc = `obs_auc' - r(mean)
//hist delta_brier
qui summarize delta_brier
local corrected_brier = `obs_brier' - r(mean)
display ""
display "| Measure | Observed | Optimism corrected |"
display "|---------|----------|--------------------|"
display "| AUC | " %4.3f `obs_auc' " | " %4.3f `corrected_auc' " |"
display "| Brier | " %4.3f `obs_brier' " | " %4.3f `corrected_brier' " |"
clear
qui use `tmpfile'
end