Bookmark and Share

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, is already up and running.

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

Re: st: bootstrapping with senspec

From   "Roger B. Newson" <>
Subject   Re: st: bootstrapping with senspec
Date   Tue, 04 Sep 2012 11:57:25 +0100

As Nick seems to suspect, -senspec- was not really designed for use with -bootstrap-, because, as stated in -help senspec-, -senspec- does not save many Saved Results (just the sample number and the numbers of opositive and negative observations). If you want to bootstrap a sensitivity or specificity (or any other proportion), then you should use a command that estimates proportions and stores them in Saved Results in -r()- and/or -e()-.

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 04/09/2012 10:38, Nick Cox wrote:
Roger Newson, the author of -senspec-, is  a member of this list and
no doubt will comment. But this looks wrong to me. In essence,
-senspec- generates lots of variables. But you are trying to force
them into scalars. In practice what that will mean is that the first
value of each variable, and only the first value, will be carried
over. I think you need another approach.

In future postings, please note details that the FAQ explains:

1. No; you should not attach the dataset. Attachments should not be
sent to Statalist.

2. For "STATA" read "Stata" throughout.


On Tue, Sep 4, 2012 at 10:23 AM, Bains, Lauren <> wrote:

I am trying to use bootstrapping in STATA 12.1 to calculate 95% confidence intervals of "sensitivity", "specificity", and "accuracy" on a clustered dataset of diagnosing positive and negative lymph node metastases clustered by pelvic side (right and left pelvic sides).  I am new to programming with STATA, and am having some problems with the CIs, which I assume are likely related to my initial programming attempts.

I am using the module senspec to return the true positives (TP), false negatives (FN), TN, FP, calculate accuracy, and return the sensitivity, specificity, and accuracy, which I downloaded from:

My bootstrapping program looks like this (apologies for what is likely an inelegant attempt):

capture program drop bootstrap_sens_spec_da
program define sens_spec_da, rclass
         tempvar s_calc_sens s_calc_spec fp1 fn1 tp1 tn1
         senspec `1' `2', sensitivity(`s_calc_sens') specificity(`s_calc_spec') nfpos(`fp1') nfneg(`fn1') ntpos(`tp1') ntneg(`tn1')
         return scalar calc_da = (`tp1'+`tn1')/(`tp1'+`tn1'+`fp1'+`fn1')
         return  scalar calc_sens =`s_calc_sens'
         return scalar calc_spec =`s_calc_spec'

Then, I am using bootstrapping to calculate the confidence intervals:

bootstrap r(calc_sens) r(calc_spec) r(calc_da), reps(1000) cluster(side): sens_spec_da histo_LN_ bin_R3_LN_
estat bootstrap, all

Some of the time this seems to work although the CIs seem large, compared with the results that one gets for sensitivity and specificity when not accounting for clustering using, for example, diagt.  Sometimes it does not work at all.  Using diagt to find the sensitivity and specificity for the 3rd reader works fine, but the bootstrapping fails.  Here is the output of diagt:

. diagt histo_LN_ bin_R3_LN_

            |      bin_R3_LN_
  histo_LN_ |      Pos.       Neg. |     Total
   Abnormal |        25         19 |        44
     Normal |        25        171 |       196
      Total |        50        190 |       240

True abnormal diagnosis defined as histo_LN_ = 1

                                                   [95% Confidence Interval]
Prevalence                         Pr(A)     18.3%     13.6%      23.8%
Sensitivity                      Pr(+|A)     56.8%     41.0%     71.7%
Specificity                      Pr(-|N)     87.2%     81.7%     91.6%

And here is STATA's output of bootstrapping on the readings for R3 (the third reader):

. bootstrap r(calc_sens) r(calc_spec) r(calc_da), reps(1000) cluster(side): sens_spec_da histo_LN_ bin_R3_LN_

Bootstrap results                               Number of obs      =       240
                                                 Replications       =      1000

       command:  sens_spec_da histo_LN_ bin_R3_LN_
         _bs_1:  r(calc_sens)
         _bs_2:  r(calc_spec)
         _bs_3:  r(calc_da)

                                     (Replications based on 2 clusters in side)
              |   Observed   Bootstrap                         Normal-based
              |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        _bs_1 |          1          .        .       .            .           .
        _bs_2 |          0  (omitted)
        _bs_3 |   .1833333   .0235188     7.80   0.000     .1372373    .2294294

  (notice that the first two results, for sensitivity and specificity, fail to match with diagt)

This is my first time posting to the STATA listserv, so I give my apologies in advance if I have provided too much (or not enough) detail.  I can attach the dataset if that would be helpful.  Any suggestions would be much appreciated!

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index