Overview

Presentation on the 35th REQUIRE.

Sensitivity and Specificity

library(epiR)
## Loading required package: survival
## Package epiR 1.0-4 is loaded
## Type help(epi.about) for summary information
## 
tab <- matrix(c(32,5,6,35), nrow = 2, byrow = TRUE)
tab
##      [,1] [,2]
## [1,]   32    5
## [2,]    6   35
epi.tests(tab)
##           Outcome +    Outcome -      Total
## Test +           32            5         37
## Test -            6           35         41
## Total            38           40         78
## 
## Point estimates and 95 % CIs:
## ---------------------------------------------------------
## Apparent prevalence                    0.47 (0.36, 0.59)
## True prevalence                        0.49 (0.37, 0.60)
## Sensitivity                            0.84 (0.69, 0.94)
## Specificity                            0.88 (0.73, 0.96)
## Positive predictive value              0.86 (0.71, 0.95)
## Negative predictive value              0.85 (0.71, 0.94)
## Positive likelihood ratio              6.74 (2.93, 15.47)
## Negative likelihood ratio              0.18 (0.09, 0.38)
## ---------------------------------------------------------

Sample size calculation

Use function(sample.se)

sample.se <- function(se, p, L, alpha=.05){
  return(((se * (1-se))/(L^2 * p)) * (qnorm(alpha/2, lower.tail=F)^2))
}
sample.se(se=.8, p=c(.10, .05, .01), L=.1)
## [1]  614.6334 1229.2668 6146.3341

Estimate PPV and NPV using sensitivity, specificity, and prevalence

ppp.npv <- function(se, sp, p){
  ppp <- (p * se)/((p*se) + ((1-p)*(1-sp)))
  npv <- (sp * (1-p))/((sp*(1-p)) + (p*(1-se)))
  return(data.frame(ppp,npv))
}
ppp.npv(se=.9, sp=.9, p=c(.01,.05,.1))
##          ppp       npv
## 1 0.08333333 0.9988789
## 2 0.32142857 0.9941860
## 3 0.50000000 0.9878049

Bias due to exposure misclassification

exp.bias <- function(p, se, sp, I.ctr, I.exp){
  a <- se * p * I.exp + (1-sp) * (1-p) * I.ctr
  b <- se * p * (1-I.exp) + (1-sp) * (1-p) * (1-I.ctr)
  c <- (1-se) * p * I.exp + sp * (1-p) * I.ctr
  d <- (1-se) * p * (1-I.exp) + sp * (1-p) * (1-I.ctr)
  
  RRt <- I.exp/I.ctr
  RRo <- (a/(a+b))/(c/(c+d))
  bias <- (RRo-RRt)/RRt*100
  return(data.frame(RRtrue=RRt, RRbiased=RRo, bias))
}

exp.bias(p =c(.1,.3,.5), se = 0.5, sp = 1.0, 
         I.ctr = 0.01, I.exp = 0.02)
##   RRtrue RRbiased bias
## 1      2      1.9   -5
## 2      2      1.7  -15
## 3      2      1.5  -25
exp.bias(p =c(.1,.3,.5), se = 0.2, sp = .6, 
         I.ctr = 0.01, I.exp = 0.02)
##   RRtrue  RRbiased      bias
## 1      2 0.9323308 -53.38346
## 2      2 0.8627451 -56.86275
## 3      2 0.8484848 -57.57576
exp.bias(p =c(.1,.3,.5), se = 0.2, sp = .6, 
         I.ctr = 0.02, I.exp = 0.02)
##   RRtrue RRbiased          bias
## 1      1        1 -2.220446e-14
## 2      1        1 -2.220446e-14
## 3      1        1 -2.220446e-14

Bias due to outcome misclassification

out.bias <- function(p, se, sp, I.ctr, I.exp){
  a <- se * p * I.exp + (1-sp) * p * (1-I.exp)
  b <- (1-se) * p * I.exp + sp * p * (1-I.exp)
  c <- se * (1-p) * I.ctr + (1-sp) * (1-p) * (1-I.ctr)
  d <- (1-se) * (1-p) * I.ctr + sp * (1-p) * (1-I.ctr)
  RRt <- I.exp/I.ctr
  RRo <- (a/(a+b))/(c/(c+d))
  bias <- (RRo-RRt)/RRt*100
  return(data.frame(RRtrue=RRt, RRbiased=RRo,bias))
}

out.bias(se=.3, sp=.98, p=.1, I.ctr=.25, I.exp=.5)
##   RRtrue RRbiased      bias
## 1      2 1.777778 -11.11111
out.bias(se=.3, sp=.98, p=.1, I.ctr=.01, I.exp=.02)
##   RRtrue RRbiased      bias
## 1      2 1.122807 -43.85965

Bias impact analysis

bias.impact <- function(mat, se.exp, se.ctr, sp.exp, sp.ctr){
  ##Biased odds ratio
  p11 <- mat[1,1]
  p10 <- mat[2,1]
  p01 <- mat[1,2]
  p00 <- mat[2,2]

  ##create input data
  se.exp <- seq(min(se.exp), max(se.exp), by=.01)
  se.ctr <- seq(min(se.ctr), max(se.ctr), by=.01)
  sp.exp <- seq(min(sp.exp), max(sp.exp), by=.01)
  sp.ctr <- seq(min(sp.ctr), max(sp.ctr), by=.01)
  
  ##all combinations
  pattern <- expand.grid(se.exp=se.exp,se.ctr=se.ctr, sp.exp=sp.exp, sp.ctr=sp.ctr)
  pattern$ORbiased <- (p11*p00)/(p10*p01)
  pattern$ORtrue <- NA
  
  #unbiased odds ratio
  for(i in 1:nrow(pattern)){
    form1 <- (p11*p00)/(p10*p01)
    num <-   (p00*(1-pattern$sp.ctr[i])-p10*pattern$sp.ctr[i])*(p11*(1-pattern$se.exp[i])-p01*pattern$se.exp[i])
    denom <- (p01*(1-pattern$sp.exp[i])-p11*pattern$sp.exp[i])*(p10*(1-pattern$se.ctr[i])-p00*pattern$se.ctr[i])
    Rbias <- form1*(num/denom)
    pattern$ORtrue[i] <- pattern$ORbiased[i]/Rbias
  }
  minimum <- pattern[which.min(pattern$ORtrue),]
  maximum <- pattern[which.max(pattern$ORtrue),]
  
  return(list(minimum=minimum, maximum=maximum, pattern=pattern))
}

mat <- matrix(c(573,1315, 3150, 11107), ncol=2)
rownames(mat) <- c("young", "old")
colnames(mat) <- c("drug", "no drug")
mat
##       drug no drug
## young  573    3150
## old   1315   11107
bias.impact(mat, 
            se.exp = c(.68, .75), se.ctr = c(.61, .65), 
            sp.exp = c(.97, .98), sp.ctr = c(.97, .98))
## $minimum
##    se.exp se.ctr sp.exp sp.ctr ORbiased   ORtrue
## 88   0.75   0.61   0.97   0.98 1.536438 1.220516
## 
## $maximum
##    se.exp se.ctr sp.exp sp.ctr ORbiased   ORtrue
## 73   0.68   0.65   0.98   0.97 1.536438 1.825742
## 
## $pattern
##     se.exp se.ctr sp.exp sp.ctr ORbiased   ORtrue
## 1     0.68   0.61   0.97   0.97 1.536438 1.565211
## 2     0.69   0.61   0.97   0.97 1.536438 1.536014
## 3     0.70   0.61   0.97   0.97 1.536438 1.507887
## 4     0.71   0.61   0.97   0.97 1.536438 1.480771
## 5     0.72   0.61   0.97   0.97 1.536438 1.454613
## 6     0.73   0.61   0.97   0.97 1.536438 1.429363
## 7     0.74   0.61   0.97   0.97 1.536438 1.404975
## 8     0.75   0.61   0.97   0.97 1.536438 1.381406
## 9     0.68   0.62   0.97   0.97 1.536438 1.596258
## 10    0.69   0.62   0.97   0.97 1.536438 1.566482
## 11    0.70   0.62   0.97   0.97 1.536438 1.537797
## 12    0.71   0.62   0.97   0.97 1.536438 1.510143
## 13    0.72   0.62   0.97   0.97 1.536438 1.483466
## 14    0.73   0.62   0.97   0.97 1.536438 1.457716
## 15    0.74   0.62   0.97   0.97 1.536438 1.432844
## 16    0.75   0.62   0.97   0.97 1.536438 1.408807
## 17    0.68   0.63   0.97   0.97 1.536438 1.627305
## 18    0.69   0.63   0.97   0.97 1.536438 1.596950
## 19    0.70   0.63   0.97   0.97 1.536438 1.567707
## 20    0.71   0.63   0.97   0.97 1.536438 1.539515
## 21    0.72   0.63   0.97   0.97 1.536438 1.512320
## 22    0.73   0.63   0.97   0.97 1.536438 1.486068
## 23    0.74   0.63   0.97   0.97 1.536438 1.460713
## 24    0.75   0.63   0.97   0.97 1.536438 1.436208
## 25    0.68   0.64   0.97   0.97 1.536438 1.658352
## 26    0.69   0.64   0.97   0.97 1.536438 1.627418
## 27    0.70   0.64   0.97   0.97 1.536438 1.597617
## 28    0.71   0.64   0.97   0.97 1.536438 1.568888
## 29    0.72   0.64   0.97   0.97 1.536438 1.541173
## 30    0.73   0.64   0.97   0.97 1.536438 1.514421
## 31    0.74   0.64   0.97   0.97 1.536438 1.488582
## 32    0.75   0.64   0.97   0.97 1.536438 1.463609
## 33    0.68   0.65   0.97   0.97 1.536438 1.689399
## 34    0.69   0.65   0.97   0.97 1.536438 1.657886
## 35    0.70   0.65   0.97   0.97 1.536438 1.627527
## 36    0.71   0.65   0.97   0.97 1.536438 1.598260
## 37    0.72   0.65   0.97   0.97 1.536438 1.570027
## 38    0.73   0.65   0.97   0.97 1.536438 1.542774
## 39    0.74   0.65   0.97   0.97 1.536438 1.516450
## 40    0.75   0.65   0.97   0.97 1.536438 1.491011
## 41    0.68   0.61   0.98   0.97 1.536438 1.691531
## 42    0.69   0.61   0.98   0.97 1.536438 1.659978
## 43    0.70   0.61   0.98   0.97 1.536438 1.629581
## 44    0.71   0.61   0.98   0.97 1.536438 1.600276
## 45    0.72   0.61   0.98   0.97 1.536438 1.572008
## 46    0.73   0.61   0.98   0.97 1.536438 1.544720
## 47    0.74   0.61   0.98   0.97 1.536438 1.518364
## 48    0.75   0.61   0.98   0.97 1.536438 1.492892
## 49    0.68   0.62   0.98   0.97 1.536438 1.725084
## 50    0.69   0.62   0.98   0.97 1.536438 1.692905
## 51    0.70   0.62   0.98   0.97 1.536438 1.661905
## 52    0.71   0.62   0.98   0.97 1.536438 1.632019
## 53    0.72   0.62   0.98   0.97 1.536438 1.603190
## 54    0.73   0.62   0.98   0.97 1.536438 1.575361
## 55    0.74   0.62   0.98   0.97 1.536438 1.548482
## 56    0.75   0.62   0.98   0.97 1.536438 1.522505
## 57    0.68   0.63   0.98   0.97 1.536438 1.758637
## 58    0.69   0.63   0.98   0.97 1.536438 1.725832
## 59    0.70   0.63   0.98   0.97 1.536438 1.694229
## 60    0.71   0.63   0.98   0.97 1.536438 1.663762
## 61    0.72   0.63   0.98   0.97 1.536438 1.634372
## 62    0.73   0.63   0.98   0.97 1.536438 1.606002
## 63    0.74   0.63   0.98   0.97 1.536438 1.578600
## 64    0.75   0.63   0.98   0.97 1.536438 1.552117
## 65    0.68   0.64   0.98   0.97 1.536438 1.792189
## 66    0.69   0.64   0.98   0.97 1.536438 1.758759
## 67    0.70   0.64   0.98   0.97 1.536438 1.726553
## 68    0.71   0.64   0.98   0.97 1.536438 1.695505
## 69    0.72   0.64   0.98   0.97 1.536438 1.665554
## 70    0.73   0.64   0.98   0.97 1.536438 1.636642
## 71    0.74   0.64   0.98   0.97 1.536438 1.608718
## 72    0.75   0.64   0.98   0.97 1.536438 1.581730
## 73    0.68   0.65   0.98   0.97 1.536438 1.825742
## 74    0.69   0.65   0.98   0.97 1.536438 1.791686
## 75    0.70   0.65   0.98   0.97 1.536438 1.758877
## 76    0.71   0.65   0.98   0.97 1.536438 1.727247
## 77    0.72   0.65   0.98   0.97 1.536438 1.696736
## 78    0.73   0.65   0.98   0.97 1.536438 1.667283
## 79    0.74   0.65   0.98   0.97 1.536438 1.638836
## 80    0.75   0.65   0.98   0.97 1.536438 1.611343
## 81    0.68   0.61   0.97   0.98 1.536438 1.382914
## 82    0.69   0.61   0.97   0.98 1.536438 1.357118
## 83    0.70   0.61   0.97   0.98 1.536438 1.332266
## 84    0.71   0.61   0.97   0.98 1.536438 1.308309
## 85    0.72   0.61   0.97   0.98 1.536438 1.285197
## 86    0.73   0.61   0.97   0.98 1.536438 1.262888
## 87    0.74   0.61   0.97   0.98 1.536438 1.241341
## 88    0.75   0.61   0.97   0.98 1.536438 1.220516
## 89    0.68   0.62   0.97   0.98 1.536438 1.410345
## 90    0.69   0.62   0.97   0.98 1.536438 1.384037
## 91    0.70   0.62   0.97   0.98 1.536438 1.358693
## 92    0.71   0.62   0.97   0.98 1.536438 1.334260
## 93    0.72   0.62   0.97   0.98 1.536438 1.310690
## 94    0.73   0.62   0.97   0.98 1.536438 1.287939
## 95    0.74   0.62   0.97   0.98 1.536438 1.265964
## 96    0.75   0.62   0.97   0.98 1.536438 1.244726
## 97    0.68   0.63   0.97   0.98 1.536438 1.437776
## 98    0.69   0.63   0.97   0.98 1.536438 1.410957
## 99    0.70   0.63   0.97   0.98 1.536438 1.385119
## 100   0.71   0.63   0.97   0.98 1.536438 1.360211
## 101   0.72   0.63   0.97   0.98 1.536438 1.336183
## 102   0.73   0.63   0.97   0.98 1.536438 1.312989
## 103   0.74   0.63   0.97   0.98 1.536438 1.290587
## 104   0.75   0.63   0.97   0.98 1.536438 1.268936
## 105   0.68   0.64   0.97   0.98 1.536438 1.465207
## 106   0.69   0.64   0.97   0.98 1.536438 1.437876
## 107   0.70   0.64   0.97   0.98 1.536438 1.411546
## 108   0.71   0.64   0.97   0.98 1.536438 1.386163
## 109   0.72   0.64   0.97   0.98 1.536438 1.361676
## 110   0.73   0.64   0.97   0.98 1.536438 1.338040
## 111   0.74   0.64   0.97   0.98 1.536438 1.315210
## 112   0.75   0.64   0.97   0.98 1.536438 1.293146
## 113   0.68   0.65   0.97   0.98 1.536438 1.492639
## 114   0.69   0.65   0.97   0.98 1.536438 1.464796
## 115   0.70   0.65   0.97   0.98 1.536438 1.437972
## 116   0.71   0.65   0.97   0.98 1.536438 1.412114
## 117   0.72   0.65   0.97   0.98 1.536438 1.387169
## 118   0.73   0.65   0.97   0.98 1.536438 1.363090
## 119   0.74   0.65   0.97   0.98 1.536438 1.339833
## 120   0.75   0.65   0.97   0.98 1.536438 1.317356
## 121   0.68   0.61   0.98   0.98 1.536438 1.494522
## 122   0.69   0.61   0.98   0.98 1.536438 1.466644
## 123   0.70   0.61   0.98   0.98 1.536438 1.439787
## 124   0.71   0.61   0.98   0.98 1.536438 1.413896
## 125   0.72   0.61   0.98   0.98 1.536438 1.388919
## 126   0.73   0.61   0.98   0.98 1.536438 1.364810
## 127   0.74   0.61   0.98   0.98 1.536438 1.341523
## 128   0.75   0.61   0.98   0.98 1.536438 1.319018
## 129   0.68   0.62   0.98   0.98 1.536438 1.524167
## 130   0.69   0.62   0.98   0.98 1.536438 1.495736
## 131   0.70   0.62   0.98   0.98 1.536438 1.468346
## 132   0.71   0.62   0.98   0.98 1.536438 1.441941
## 133   0.72   0.62   0.98   0.98 1.536438 1.416469
## 134   0.73   0.62   0.98   0.98 1.536438 1.391882
## 135   0.74   0.62   0.98   0.98 1.536438 1.368133
## 136   0.75   0.62   0.98   0.98 1.536438 1.345182
## 137   0.68   0.63   0.98   0.98 1.536438 1.553812
## 138   0.69   0.63   0.98   0.98 1.536438 1.524828
## 139   0.70   0.63   0.98   0.98 1.536438 1.496905
## 140   0.71   0.63   0.98   0.98 1.536438 1.469987
## 141   0.72   0.63   0.98   0.98 1.536438 1.444020
## 142   0.73   0.63   0.98   0.98 1.536438 1.418954
## 143   0.74   0.63   0.98   0.98 1.536438 1.394744
## 144   0.75   0.63   0.98   0.98 1.536438 1.371345
## 145   0.68   0.64   0.98   0.98 1.536438 1.583457
## 146   0.69   0.64   0.98   0.98 1.536438 1.553920
## 147   0.70   0.64   0.98   0.98 1.536438 1.525465
## 148   0.71   0.64   0.98   0.98 1.536438 1.498033
## 149   0.72   0.64   0.98   0.98 1.536438 1.471570
## 150   0.73   0.64   0.98   0.98 1.536438 1.446026
## 151   0.74   0.64   0.98   0.98 1.536438 1.421354
## 152   0.75   0.64   0.98   0.98 1.536438 1.397509
## 153   0.68   0.65   0.98   0.98 1.536438 1.613102
## 154   0.69   0.65   0.98   0.98 1.536438 1.583012
## 155   0.70   0.65   0.98   0.98 1.536438 1.554024
## 156   0.71   0.65   0.98   0.98 1.536438 1.526078
## 157   0.72   0.65   0.98   0.98 1.536438 1.499120
## 158   0.73   0.65   0.98   0.98 1.536438 1.473098
## 159   0.74   0.65   0.98   0.98 1.536438 1.447964
## 160   0.75   0.65   0.98   0.98 1.536438 1.423673