 Dr. Smita Pakhale,

Im physician too and even though not a beginer in R, I do have a hard time
with R some times. Last year I had the same problem you are having right now
and some more experinced friends form a local R list gave me a hand. Below
are the two functions that resulted from my problem.

The two of them have some stuff in portuguese but if you are familiar with
diagnosis  then you will have no problmes. They estimate confidence
intervals with binomial distribution which may not give confidence intervals
higher then 100, which happens when using normal distribution and extreme
point estimates values .

The first one estimate from a dataframe estructure. The second will heve to
input the numbers from the 2x2 tables. I hope it helps. Of course you may
edit them as you wish to give the best results. Send news later!!!

# Function to input columns of a data frame (first column is the test under
evaluation and the second is the reference test.)

diagtest<-function(teste,gold,dec=1){
require(epitools)
tab<-table(2-teste,2-gold,dnn=c(deparse(substitute(teste)),deparse(substitute(gold))))
VP<-tab[1,1]
FP<-tab[1,2]
FN<-tab[2,1]
VN<-tab[2,2]
dig<-2+dec
n<-sum(tab)
p<-(VP+FN)/n
s<-VP/(VP+FN)
s.ci<-as.numeric(binom.wilson(VP, VP+FN, conf.level = 0.95)[4:5])
e<-VN/(FP+VN)
e.ci<-as.numeric(binom.wilson(VN, FP+VN, conf.level = 0.95)[4:5])
rvp<-s/(1-e)
rvn<-e/(1-s)
acu<-(VP+VN)/n
acu.ci<-as.numeric(binom.wilson(VP+VN, n, conf.level = 0.95)[4:5])
vpp<-VP/(VP+FP)
vpp.ci<-as.numeric(binom.wilson(VP, VP+FP, conf.level = 0.95)[4:5])
vpn<-VN/(VN+FN)
vpn.ci<-as.numeric(binom.wilson(VN, VN+FN, conf.level = 0.95)[4:5])
dor<-(VP+VN)/(FP+FN)
cet<-(FP+FN)/n
cet.ci<-as.numeric(binom.wilson(FP+FN,n, conf.level = 0.95)[4:5])
cat("\n\n")
print(tab)
cat("\n\n")
cat("O teste possui os seguinte parametros","\n")
cat("Sensibilidade: ",round(s,dig)*100,"% (",round(s.ci[1],dig)*100," a
",round(s.ci[2],dig)*100,")\n")
cat("Especifidade: ",round(e,dig)*100,"% (",round(e.ci[1],dig)*100," a
",round(e.ci[2],dig)*100,")\n")
cat("Acurácia: ",round(acu,dig)*100,"% (",round(acu.ci[1],dig)*100," a
",round(acu.ci[2],dig)*100,")\n")
cat("Classificação errônea total: ",round(cet,dig)*100,"%
(",round(cet.ci[1],dig)*100," a ",round(cet.ci[2],dig)*100,")\n")
cat("DOR: ",round(dor,dig),"\n")
cat("Razão de Verossimilhança Positiva: ",round(rvp,dig),"\n")
cat("Razão de Verossimilhança Negativa: ",round(rvn,dig),"\n")
cat("Considerando um prevalência de : ",round(p,dig)*100,"%\n")
cat("Valor Preditivo Positivo: ",round(vpp,dig)*100,"%
(",round(vpp.ci[1],dig)*100," a ",round(vpp.ci[2],dig)*100,")\n")
cat("Valor Preditivo Negativo: ",round(vpn,dig)*100,"%
(",round(vpn.ci[1],dig)*100," a ",round(vpn.ci[2],dig)*100,")\n\n\n")
}
diagtest(BNP,ICC)



# Function to input the values from a 2x2 table

diagtest<-function(a,b,c,d,dec=1){
require(epitools)
dig<-2+dec
n<-a+b+c+d
p<-(a+c)/n
s<-a/(a+c)
s.ci<-as.numeric(binom.wilson(a, a+c, conf.level = 0.95)[4:5])
e<-d/(b+d)
e.ci<-as.numeric(binom.wilson(d, b+d, conf.level = 0.95)[4:5])
rvp<-s/(1-e)
rvn<-e/(1-s)
acu<-(a+d)/n
acu.ci<-as.numeric(binom.wilson(a+d, n, conf.level = 0.95)[4:5])
vpp<-(s*p)/(s*p+(1-e)*(1-p))
vpn<-((1-p)*e)/((1-p)*e+p*(1-s))
cat("O teste possui os seguinte parametros","\n")
cat("Sensibilidade: ",round(s,dig)*100,"% (",round(s.ci[1],dig)*100," a
",round(s.ci[2],dig)*100,")\n")
cat("Especifidade: ",round(e,dig)*100,"% (",round(e.ci[1],dig)*100," a
",round(e.ci[2],dig)*100,")\n")
cat("Acurácia: ",round(acu,dig)*100,"% (",round(acu.ci[1],dig)*100," a
",round(acu.ci[2],dig)*100,")\n")
cat("Razão de Verossimilhança Positiva: ",rvp,"\n")
cat("Razão de Verossimilhança Negativa: ",rvn,"\n")
cat("Considerando um prevalência de : ",round(p,dig)*100,"%\n")
cat("Valor Preditivo Positivo: ",round(vpp,dig)*100,"%\n")
cat("Valor Preditivo Negativo: ",round(vpn,dig)*100,"%\n")
}
diagtest(300,5,5,500)

Best regards,
Pedro Brasil

	[[alternative HTML version deleted]]

