Amit B.

asked • 07/10/22

How to calculate the likelihood?

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?



1 Expert Answer

By:

Sai Kalyan Y. answered • 03/10/25

Tutor
New to Wyzant

A Data Analytics manager in Boston graduated in Data Analytics

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.