Binomialverteilung

par(mfrow = c(1,2))
n = 3
p = 0.25
k = 0:n

y1 = dbinom(k, n, p)
barplot(y1, space=10, names.arg = k)

Hypergeometrische Verteilung

N = 4*3
G = N/4
n = 3
y2 = dhyper(k, G, N-G, n)
barplot(y2, space = 10, names.arg = k)

Poisson

lambda <- 3
k <- 0:20
y3 <- dpois(k, lambda)
barplot(y3, space=10, names.arg = k)

?barplot

Geometrische Verteilung

p <- 0.5
k = 0:20
y4 = dgeom(k, p)

barplot(y4, space=10, names.arg = k, ylim = c(0,p))

Bayes

Let A represent the event “positive Test”, B the event “Person infected”. Let the specificity of the test be 95% and the Type I error be 0.1%. What’s the probability of a person with a positive test being infected?

b <- 0.005
a_given_b <- .95
a_given_not.b <- .01

# P(B|A)?
new_prior <- a_given_b * b / sum(a_given_b*b, a_given_not.b*(1-b))
new_prior
## [1] 0.3231293

Now, given a 2nd positive test, what is the probability now?

new_prior2 <- a_given_b*new_prior / sum(a_given_b*new_prior,a_given_not.b*(1-new_prior))
new_prior2
## [1] 0.9784258

3rd Test:

a_given_b*new_prior2 / sum(a_given_b*new_prior2,a_given_not.b*(1-new_prior2))
## [1] 0.999768

So 2 tests should suffice