Packages

install.packages("MKmisc")
Installing package into ‘/home/sergiouribe/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
probando la URL 'https://cran.rstudio.com/src/contrib/MKmisc_0.993.tar.gz'
Content type 'application/x-gzip' length 42863 bytes (41 KB)
==================================================
downloaded 41 KB

* installing *source* package ‘MKmisc’ ...
** package ‘MKmisc’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (MKmisc)

The downloaded source packages are in
    ‘/tmp/Rtmp8urSj7/downloaded_packages’

Calculations

To achieve a sensibility, i.e. 95%

power.diagnostic.test(sens = 0.95, 
                      sig.level = 0.05, 
                      delta = 0.1,
                      power = 0.8)

     Diagnostic test exact power calculation 

           sens = 0.95
              n = 68
             n1 = 68
          delta = 0.1
      sig.level = 0.05
          power = 0.8
           prev = NULL

NOTE: n is number of cases, n1 is number of controls

To achieve a specificity, i.e. 95%

power.diagnostic.test(spec = 0.95, 
                      delta = 0.1,
                      power = 0.8)

     Diagnostic test exact power calculation 

           sens = NULL
              n = 68
             n1 = 68
          delta = 0.1
      sig.level = 0.05
          power = 0.8
           prev = NULL

NOTE: n is number of controls, n1 is number of cases

Adding alpha = 5%

power.diagnostic.test(spec = 0.95,
                      delta = 0.1,
                      sig.level = 0.5, 
                      power = 0.8)

     Diagnostic test exact power calculation 

           sens = NULL
              n = 18
             n1 = 18
          delta = 0.1
      sig.level = 0.5
          power = 0.8
           prev = NULL

NOTE: n is number of controls, n1 is number of cases

Given a 20% prevalence

power.diagnostic.test(spec = 0.95,
                      delta = 0.1,
                      prev = 0.2, 
                      sig.level = 0.5, 
                      power = 0.8)

     Diagnostic test exact power calculation 

           sens = NULL
              n = 18
             n1 = 4.5
          delta = 0.1
      sig.level = 0.5
          power = 0.8
           prev = 0.2

NOTE: n is number of controls, n1 is number of cases

If we have only 20 cases

power.diagnostic.test(spec = 0.95,
                      delta = 0.1,
                      NMAX = 20, 
                      sig.level = 0.5, 
                      power = 0.8)

     Diagnostic test exact power calculation 

           sens = NULL
              n = 18
             n1 = 18
          delta = 0.1
      sig.level = 0.5
          power = 0.8
           prev = NULL

NOTE: n is number of controls, n1 is number of cases

Sample size for ROC

library(pROC)
Type 'citation("pROC")' for a citation.

Attaching package: ‘pROC’

The following objects are masked from ‘package:stats’:

    cov, smooth, var

Build a roc object:

print(rocobj) # also smooth print(smooth(rocobj))

Call:
roc.default(response = aSAH$outcome, predictor = aSAH$s100b)

Data: aSAH$s100b in 72 controls (aSAH$outcome Good) < 41 cases (aSAH$outcome Poor).
Area under the curve: 0.7314

Plot

Determine power of one ROC curve:

power.roc.test(rocobj)

     One ROC curve power calculation 

         ncases = 41
      ncontrols = 72
            auc = 0.7313686
      sig.level = 0.05
          power = 0.9904833

Same as:

power.roc.test(ncases = 41,
               ncontrols = 72,
               auc = 0.73,
               sig.level = 0.05)

     One ROC curve power calculation 

         ncases = 41
      ncontrols = 72
            auc = 0.73
      sig.level = 0.05
          power = 0.9897453

sig.level=0.05 is implicit and can be omitted:

power.roc.test(ncases = 41,
               ncontrols = 72,
               auc = 0.73)

     One ROC curve power calculation 

         ncases = 41
      ncontrols = 72
            auc = 0.73
      sig.level = 0.05
          power = 0.9897453

Determine ncases & ncontrols:

power.roc.test(auc = rocobj$auc,
               sig.level = 0.05,
               power = 0.95,
               kappa=1.7)

     One ROC curve power calculation 

         ncases = 29.29764
      ncontrols = 49.806
            auc = 0.7313686
      sig.level = 0.05
          power = 0.95
power.roc.test(auc = 0.73, 
               sig.level = 0.05,
               power = 0.95,
               kappa=1.7)

     One ROC curve power calculation 

         ncases = 29.6702
      ncontrols = 50.43933
            auc = 0.73
      sig.level = 0.05
          power = 0.95

Determine sig.level:

power.roc.test(ncases = 41,
               ncontrols = 72,
               auc = 0.73,
               power = 0.95,
               sig.level=NULL)

     One ROC curve power calculation 

         ncases = 41
      ncontrols = 72
            auc = 0.73
      sig.level = 0.009238584
          power = 0.95

Determine detectable AUC:

power.roc.test(ncases = 41,
               ncontrols = 72,
               sig.level = 0.05,
               power = 0.95)

     One ROC curve power calculation 

         ncases = 41
      ncontrols = 72
            auc = 0.6961054
      sig.level = 0.05
          power = 0.95

References

A. Flahault, M. Cadilhac, and G. Thomas (2005). Sample size calculation should be performed for design accuracy in diagnostic test studies. Journal of Clinical Epidemiology, 58(8):859-862.

H. Chu and S.R. Cole (2007). Sample size calculation using exact methods in diagnostic test studies. Journal of Clinical Epidemiology, 60(11):1201-1202.

M.R. Chernick amd C.Y. Liu (2002). The saw-toothed behavior of power versus sample size and software solutions: single binomial proportion using exact methods. Am Stat, 56:149-155.

Xavier Robin, Natacha Turck, Alexandre Hainard, et al. (2011) “pROC: an open-source package for R and S+ to analyze and compare ROC curves”. BMC Bioinformatics, 7, 77. DOI: 10.1186/1471-2105-12-77.

LS0tCnRpdGxlOiAiU2FtcGxlIHNpemUgY2FsY3VsYXRpb24gZm9yIGRpYWdub3N0aWMgc3R1ZGllcyIKb3V0cHV0OiAKICBodG1sX25vdGVib29rOiAKICAgIHRoZW1lOiBjZXJ1bGVhbgogICAgdG9jOiB5ZXMKICAgIHRvY19mbG9hdDogdHJ1ZQotLS0KCiMgUGFja2FnZXMKYGBge3J9Cmluc3RhbGwucGFja2FnZXMoIk1LbWlzYyIpCmxpYnJhcnkoTUttaXNjKQpgYGAKCiMgQ2FsY3VsYXRpb25zCiMjIFRvIGFjaGlldmUgYSBzZW5zaWJpbGl0eSwgaS5lLiA5NSUKYGBge3J9CnBvd2VyLmRpYWdub3N0aWMudGVzdChzZW5zID0gMC45NSwgCiAgICAgICAgICAgICAgICAgICAgICBkZWx0YSA9IDAuMSwKICAgICAgICAgICAgICAgICAgICAgIHBvd2VyID0gMC44KQpgYGAKCiMjIFRvIGFjaGlldmUgYSBzcGVjaWZpY2l0eSwgaS5lLiA5NSUKYGBge3J9CnBvd2VyLmRpYWdub3N0aWMudGVzdChzcGVjID0gMC45NSwgCiAgICAgICAgICAgICAgICAgICAgICBkZWx0YSA9IDAuMSwKICAgICAgICAgICAgICAgICAgICAgIHBvd2VyID0gMC44KQpgYGAKCkFkZGluZyBhbHBoYSA9IDUlCgpgYGB7cn0KcG93ZXIuZGlhZ25vc3RpYy50ZXN0KHNwZWMgPSAwLjk1LAogICAgICAgICAgICAgICAgICAgICAgZGVsdGEgPSAwLjEsCiAgICAgICAgICAgICAgICAgICAgICBzaWcubGV2ZWwgPSAwLjUsIAogICAgICAgICAgICAgICAgICAgICAgcG93ZXIgPSAwLjgpCmBgYAoKIyMgR2l2ZW4gYSAyMCUgcHJldmFsZW5jZQoKYGBge3J9CnBvd2VyLmRpYWdub3N0aWMudGVzdChzcGVjID0gMC45NSwKICAgICAgICAgICAgICAgICAgICAgIGRlbHRhID0gMC4xLAogICAgICAgICAgICAgICAgICAgICAgcHJldiA9IDAuMiwgCiAgICAgICAgICAgICAgICAgICAgICBzaWcubGV2ZWwgPSAwLjUsIAogICAgICAgICAgICAgICAgICAgICAgcG93ZXIgPSAwLjgpCmBgYAoKIyMgSWYgd2UgaGF2ZSBvbmx5IDIwIGNhc2VzCgpgYGB7cn0KcG93ZXIuZGlhZ25vc3RpYy50ZXN0KHNwZWMgPSAwLjk1LAogICAgICAgICAgICAgICAgICAgICAgZGVsdGEgPSAwLjEsCiAgICAgICAgICAgICAgICAgICAgICBOTUFYID0gMjAsIAogICAgICAgICAgICAgICAgICAgICAgc2lnLmxldmVsID0gMC41LCAKICAgICAgICAgICAgICAgICAgICAgIHBvd2VyID0gMC44KQpgYGAKCiMgU2FtcGxlIHNpemUgZm9yIFJPQwpgYGB7cn0KaW5zdGFsbC5wYWNrYWdlcygicFJPQyIpCmxpYnJhcnkocFJPQykKYGBgCmBgYHtyfQpkYXRhKGFTQUgpCmhlYWQoYVNBSCkKYGBgCiMjIEJ1aWxkIGEgcm9jIG9iamVjdDoKYGBge3J9CnJvY29iaiA8LSByb2MoYVNBSCRvdXRjb21lLCBhU0FIJHMxMDBiKQpwcmludChyb2NvYmopIC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