Tuesday, 11 April 2023

R function prevalenceCI

 

prevalenceCI calculates the confidence interval for prevalence study. The function takes four arguments:


  • x: number of positive cases.
  • n: sample size.
  • ci.lev: level of confidence.
  • ci.method: confidence interval calculation method (default=“all”, alternatives=“agresti.coull”,“exact”,“Jeffreys”,“Wald”,“Wilson”).

The function uses the prevalence package and returns the confidence interval for prevalence study using different methods.


prevalenceCI<-function(x,n,ci.lev=0.95,ci.method="all") {

#x:number of positive cases

#n:sample size

#ci.lev:level of confidence

#ci.method:confidence interval calculation method (default="all", alternatives="agresti.coull","exact","Jeffreys","Wald","Wilson")

library(prevalence)

results<- propCI(x,n)

tem=NULL

ifelse(ci.method=="agresti.coull",tem<-results[1,],

ifelse(ci.method=="exact",tem<-results[2,],

ifelse(ci.method=="",tem<-results[3,],

ifelse(ci.method=="",tem<-results[4,],

ifelse(ci.method=="",tem<-results[5,],

tem<- results)))))

return(tem)

}


No comments:

Post a Comment

Understanding Anaerobic Threshold (VT2) and VO2 Max in Endurance Training

  Introduction: The Science Behind Ventilatory Thresholds Every endurance athlete, whether a long-distance runner, cyclist, or swimmer, st...