Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: Combining ROC curves in one graph

 From Charles Lindsey To statalist@hsphsun2.harvard.edu Subject Re: st: Combining ROC curves in one graph Date Fri, 19 Aug 2011 16:25:39 -0500

```Kim Peters wrote:
> I have plotted three ROC curves using
>
> roctab x1 y1, graph name(rocgraph1) nodraw
> roctab x2 y2, graph name(rocgraph2) nodraw
> roctab x3 y3, graph name(rocgraph3) nodraw
>
> How can I combine these three roclines into one graph.
>  || or (...) do not seem to work.

All the receiver operating characteristic (ROC) commands in Stata use a
```
single status variable, with one or more classification variables. You can automatically draw ROC curves for different classifiers using the same status variable. A new command, -rocreg- can be used to draw ROC curves for different status variables in the same graph.
```
Kim can use the new command -rocreg- to draw the graph she desires.

Here is a short answer to Kim's question.

You can use -rocreg- to fit several models, create the new variables
containing the false-positive rate and ROC values, and then plot the ROC
curves using -twoway-.

Here is a more detailed answer to Kim's question.

Let's consider an example using the Hanley data, where an individual's
neurological disease status is classified on a single 5-scale rating.

```
In the code below, we load the data and create a fictional disease-status variable, -ndisease-, which zeroes the true status variable, -disease-, with probability 2/10.
```
. set seed 12345671
. webuse hanley, clear
. generate ndisease = disease
. replace ndisease = 0 if runiform() > .8

```
Now we use -rocreg- to estimate a nonparametric ROC curve of -disease- and classification variable -rating-. We use the -quietly- prefix to suppress output, and the -nobootstrap- option to prevent the bootstrap calculation of standard errors because we are only interested in the estimates of the false-positive rate and ROC value.
```
. quietly rocreg disease rating, nobootstrap

```
The ROC and false-positive rate values are saved as variables -_roc_rating- and -_fpr_rating-. We rename the -_roc_rating- and -_fpr_rating- variables before fitting the next ROC model, because we will need them for the graph.
```
. rename _roc_rating roc_disease
. rename _fpr_rating fpr_disease

Now we run -rocreg- on the -ndisease- status variable.

. quietly rocreg ndisease rating, nobootstrap

We rename the generated ROC and false-positive rate variables that this
execution of rocreg creates.

. rename _roc_rating roc_ndisease
. rename _fpr_rating fpr_ndisease

```
Now we will draw the ROC curves with -rating- as a classifier for -disease-, and with -rating- as a classifier for -ndisease-. -twoway scatter- is used with the || overlay operator. Since we are using the empirical estimate of the ROC curve, We use the -connect(J)- option rather than a simple line connector.
```
. twoway scatter roc_disease fpr_disease, connect(J) sort || ///
scatter roc_ndisease fpr_ndisease, connect(J) sort         ///
legend(label(1 disease) label(2 ndisease))

Kim Peters also wrote:
> Moreover, I would like to do the same thing after rocfit and rocplot:
>
> rocfit x1 y1
> rocplot, confband name(rocfit1) nodraw
> rocfit x2 y2
> rocplot, confband name(rocfit2) nodraw
> rocfit x3 y3
> rocplot, confband name(rocfit3) nodraw
>
> P.S. I don't want to array the separately drawn graphs into one using
> graph combine. I just need one graph that contains all three ROC
> lines.

```
Kim can use a similar method with -rocreg- and the -probit ml- options to get combined ROC curves for the parametric case.
```
Charles Lindsey,
StataCorp

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```