7.2.15

Hows many cows? in R

Our cows problem as posted before here can also be solved in R (obviously). Compare our results with the simulation results.
################################
# We are looking at 0.7 cutoff
# point for sensitivity
################################
# Using R
# Iterate over values
###############################

n = numeric(1)
n.low = 4 # lower limit of n
n.high = 7 # upper limit of n
pr = numeric(0)
p = 0.25 # prevalence of dss
n_ = numeric(0)
pr_ = numeric(0)

for(i in n.low:n.high) {
  n = i
  print(n)
  pr = 1 - pbinom(0, n, p)
  print(pr)
  n_[i] = n
  pr_[i] = pr
}
The results are as follows:
## [1] 4
## [1] 0.6835937
## [1] 5
## [1] 0.7626953
## [1] 6
## [1] 0.8220215
## [1] 7
## [1] 0.8665161
# sample size vs sensitivity
cbind(n=n_[n.low:n.high], Sensitivity=pr_[n.low:n.high])
##      n Sensitivity
## [1,] 4   0.6835937
## [2,] 5   0.7626953
## [3,] 6   0.8220215
## [4,] 7   0.8665161
# only 0.7 & above
cbind(n=n_[n.low:n.high], Sensitivity=pr_[n.low:n.high])[pr_[n.low:n.high] > 0.7, ]
##      n Sensitivity
## [1,] 5   0.7626953
## [2,] 6   0.8220215
## [3,] 7   0.8665161

No comments:

Post a Comment