We will define the following probabilities for a PCR test:
p - The probability that a pcr test of a **sick** person, will show us a positive result.
q - The probability that a pcr test of a **healthy** person, will show us a positive result.
s - The general percentage of patients in the population.
Let q = 10%, p = 95% and s = 20%
We want to generate data of 1000 people how came to check,
I did it in this way:
s = 0.2
p = 0.95
q = 0.1
true_result = c()
test_result = c()
for (i in 1:1000){
x = runif(1,0,1)
if (x<=s){
true_result = append(true_result,1)
r = runif(1,0,1)
if (r<=p){
test_result = append(test_result,1)
}else{
test_result = append(test_result,0)
}
}else{
true_result = append(true_result,0)
r = runif(1,0,1)
if (r<=q){
test_result = append(test_result,1)
}
else{
test_result = append(test_result,0)
}
}
}
Now, we want to generate 10,000 sample from the posterior.
And for that we need the prior and likelihood.
Let the priors to be:
**f_q(q) = 2q if x in [0,1] and 0 otw.**
**f_p(p)= 2(1-p) if x in [0,1] and 0 otw.**
**s ~ u(0,1)**
I calculated the joint prior in this way:
JointPrior <- function(p,s,q){
if(p<=0 | p>=1){
return (0)
}
if (q<= 0 | q>=1){
return(0)
}
return(s*2*q*2*(1-p))
}
The part where I get stuck is in the Likelihood calculation..
How can I calculate the likelihood? can someone help me with that?