Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Question on ROC analysis

From   Roger Newson <>
To   "" <>
Subject   Re: st: Question on ROC analysis
Date   Tue, 24 May 2011 16:09:12 +0100

Thanks to Steven for the appreciation of -somersd-.

And the end-point transformation of the confidence intervals doesn't have to be done by hand, either. The -parmest- package, downloadable from SSC, allows the user to produce an output dataset (or resultsset), with 1 observation per estimated parameter and data on estimates, confidence limits, P-values and other parameter attributes. The estimates and confidence limits can then be transformed using -replace-.

For instance, if you use -parmest- with -somersd- with the option -transf(z)- (specifying the hyperbolic arctangent), then you can -replace- the estimates and confidence limits for the transformed parameters in the output dataset with their hyperbolic tangents to get a confidence interval for Somers' D itself. And you can then -replace- the estimates and confidence limits for Somers' D in the output dataset with estimates and confidence limits for Harrell's c (also known as the ROC area) usinc the transformation


where c is Harrell's c and D is Somers' D.

I hope this helps.

Best wishes


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Web page:
Departmental Web page:

Opinions expressed are those of the author, not of the institution.

On 24/05/2011 14:43, Steven Samuels wrote:

Another advantage of using -somersd-: It can produce asymmetric confidence intervals for the AUC, which will often be more accurate for high or low values of the AUC. You do this by computing the intervals for Fisher's Z transform of Somers' D statistic, then transforming them by hand to intervals for the AUC ("Harrell's c").

Ref: Roger Newson Confidence intervals for rank statistics: Somers’ D and extensions.  The Stata Journal (2006) 6, Number 3, pp. 309–334 available at:

**************************CODE BEGINS*******
sysuse auto, clear
gen y = 1/mpg
gen ylow = y<.05
gen yhigh = 1-ylow
gen x = weight
gen nx = -x

somersd ylow nx, tdist tr(z)
matrix b = e(b)
local z= b[1,1]
matrix v=e(V)
local v =v[1,1]

local bound = sqrt(`v')*invttail(e(df_r),0.5*(1-c(level)/100))
local ll   = `z'-`bound'
local ul   = `z' + `bound'
local auc  = (exp(2*`z')-1)/(exp(2*`z')+1)
local auc  = (`auc'+1)/2
local llim = (exp(2*`ll')-1)/(exp(2*`ll')+1)
local llim = (`llim'+1)/2
local ulim = (exp(2*`ul')-1)/(exp(2*`ul')+1)
local ulim = (`ulim'+1)/2
//asymmetric interval
di "Asymmetric: auc ="%9.7g `auc' " llim ="%9.7g `llim'  " ulim ="%9.7g `ulim'
// compare to symmetric interval:
somersd ylow nx, tdist tr(c)
**************************CODE ENDS*******


On May 23, 2011, at 5:29 PM, Megan Deitchler wrote:

Thanks - this helped.  I can now graph what I want but am still having
trouble calculating the AUC.

I am trying to use Roger Newson's somersd package for this, using the
c transformation option.  I receive the following error:

      tidotforsomersd():  3499  tidottree() not found
                <istmt>:     -  function returned error

Any suggestions?

On Thu, May 19, 2011 at 3:19 PM, Steven Samuels<>  wrote:

Roger -senspec- from SSC should do what you want.


On May 19, 2011, at 2:46 PM, Megan Deitchler wrote:

I am interested in carrying out a simple two variable ROC analysis.

I want to assess how well low values of my x variable predict a low value of
my y variable (e.g. y variable with cutoff less than 200).

However, if I understand correctly, the conventional ROC analysis in Stata
creates the ROC by using incrementally increasing values of x to predict y.

How do I adapt the analysis so that the AUC result I obtain will
be consistent with the relationship I am interested in quantifying?

*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index