El Teorema de Bayes enunciado por el matemático inglés Thomas Bayes (1702-1761) es un sistema de cálculo de probabilidades pero hecho de forma inversa a cómo se calculan habitualmente.
Tiene en cuenta la información que conocemos que se ha producido en determinado entorno con determinados factores para saber cuáles de esos factores han producido esas consecuencias.
tabla=sample(0:1, 10, replace=TRUE)
print(tabla)
## [1] 1 1 1 1 1 1 1 0 1 1
prop.table(table(tabla))
## tabla
## 0 1
## 0.1 0.9
lanza_moneda=function(n){
tabla=sample(0:1, n, replace=TRUE)
p=prop.table(table(tabla))
return(p[1])
}
lanza_moneda(10)
## 0
## 0.7
p=sapply(10:1000, lanza_moneda)
n=10:1000
plot(n,p,type="l")
abline(h=0.5,col="red")
#Probabilidad Condicional
##Ejercicio de Clase (con base en la tabla observada)
a=85
b=65
c=45
d=55
hombres=a+b
mujeres=c+d
alcohol=a+c
Nalcohol=b+d
n=a+b+c+d
h=hombres/n
h
## [1] 0.6
al=alcohol/n
al
## [1] 0.52
m=1-(hombres/n)
m
## [1] 0.4
Nal=1-(alcohol/n)
Nal
## [1] 0.48
p1=h+al-(a/n)
p1
## [1] 0.78
p2=m+Nal-(d/n)
p2
## [1] 0.66
p3=(c/n)/m
p3
## [1] 0.45
library(epiR)
## Loading required package: survival
## Package epiR 2.0.19 is loaded
## Type help(epi.about) for summary information
## Type browseVignettes(package = 'epiR') to learn how to use epiR for applied epidemiological analyses
##
a=72
b=100
c=18
d=150
matrix(c(a,b,c,d), nrow=2, byrow=TRUE)
## [,1] [,2]
## [1,] 72 100
## [2,] 18 150
tabla=as.table(matrix(c(a,b,c,d), nrow=2, byrow=TRUE))
colnames(tabla)=c("Enfermo", "Sano")
rownames(tabla)=c("Positivo", "Negativo")
tabla
## Enfermo Sano
## Positivo 72 100
## Negativo 18 150
Probabilidades=epi.tests(tabla, conf.level=0.95)
Probabilidades
## Outcome + Outcome - Total
## Test + 72 100 172
## Test - 18 150 168
## Total 90 250 340
##
## Point estimates and 95 % CIs:
## ---------------------------------------------------------
## Apparent prevalence 0.51 (0.45, 0.56)
## True prevalence 0.26 (0.22, 0.31)
## Sensitivity 0.80 (0.70, 0.88)
## Specificity 0.60 (0.54, 0.66)
## Positive predictive value 0.42 (0.34, 0.50)
## Negative predictive value 0.89 (0.84, 0.94)
## Positive likelihood ratio 2.00 (1.66, 2.40)
## Negative likelihood ratio 0.33 (0.22, 0.51)
## ---------------------------------------------------------
a=120
b=140
c=480
d=260
matrix(c(a,b,c,d), nrow=2, byrow=TRUE)
## [,1] [,2]
## [1,] 120 140
## [2,] 480 260
tabla1=as.table(matrix(c(a,b,c,d), nrow=2, byrow=TRUE))
colnames(tabla1)=c("niña", "niño")
rownames(tabla1)=c("menor24", "mayor24")
tabla1
## niña niño
## menor24 120 140
## mayor24 480 260
Probabilidades1=epi.tests(tabla1, conf.level=0.95)
Probabilidades1
## Outcome + Outcome - Total
## Test + 120 140 260
## Test - 480 260 740
## Total 600 400 1000
##
## Point estimates and 95 % CIs:
## ---------------------------------------------------------
## Apparent prevalence 0.26 (0.23, 0.29)
## True prevalence 0.60 (0.57, 0.63)
## Sensitivity 0.20 (0.17, 0.23)
## Specificity 0.65 (0.60, 0.70)
## Positive predictive value 0.46 (0.40, 0.52)
## Negative predictive value 0.35 (0.32, 0.39)
## Positive likelihood ratio 0.57 (0.46, 0.70)
## Negative likelihood ratio 1.23 (1.13, 1.34)
## ---------------------------------------------------------