daDoctoR/R/rep_epi_tests.R

41 lines
1.2 KiB
R
Raw Normal View History

2018-10-04 16:52:09 +02:00
#' A repeated epi.tests function
#'
2018-10-22 14:05:19 +02:00
#' Repeats the epi.tests from the epiR package. Either gs or test should be of length 1.
2018-10-04 16:52:09 +02:00
#' @description For bivariate analyses. The confint() function is rather slow, causing the whole function to hang when including many predictors and calculating the ORs with CI.
#' @param gold the test or meassure used as "golden standard". Format as list of variable names to include. All variables should be formated as dichotomised factor.
#' @param test possible predictive tests to evaluate. Format as list of variable names to include. All variables should be formated as dichotomised factor.
2018-10-22 14:05:19 +02:00
#' @param data dataframe to draw variables from.
2018-10-04 16:52:09 +02:00
#' @keywords ppv npv sensitivity specificity
#' @export
#' @examples
#' rep_epi_tests()
2018-10-22 14:05:19 +02:00
rep_epi_tests<-function(gold,test,data){
2018-10-04 16:52:09 +02:00
require(epiR)
2018-10-22 14:05:19 +02:00
d<-data
2018-10-22 14:07:44 +02:00
tst<-d[,c(test)]
2018-10-22 14:05:19 +02:00
gs<-d[,c(gold)]
2018-10-04 16:52:09 +02:00
ls<-list()
2018-10-22 14:05:19 +02:00
if (length(gold)==1){
2018-10-22 14:07:44 +02:00
for (i in 1:ncol(tst)){
t<-table(tst[,i],gs)
2018-10-04 16:52:09 +02:00
rval <- epi.tests(t, conf.level = 0.95)
2018-10-22 14:07:44 +02:00
n<-names(tst)[i]
2018-10-04 16:52:09 +02:00
ls[[i]]<-list(n,rval)
2018-10-22 14:05:19 +02:00
}}
else {
for (i in 1:ncol(gs)){
2018-10-22 14:07:44 +02:00
t<-table(tst,gs[,i])
2018-10-22 14:12:32 +02:00
rval <- epi.tests(t, conf.level = 0.95)
2018-10-22 14:05:19 +02:00
n<-names(gs)[i]
ls[[i]]<-list(n,rval)
2018-10-04 16:52:09 +02:00
}
2018-10-22 14:05:19 +02:00
}
2018-10-04 16:52:09 +02:00
return(ls)
}