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?

in Statistics Answers by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

Without going into the programming language (which I'm not familiar with, although I get the gist of what you're doing to generate datasets using a random number generator), but, in an effort to help you derive the likelihood, by analysing the concepts you present, my thinking is illustrated by the following tree. I've started with an arbitrary sample of 10000 people from the population and then applied what I think are your statistics.

→(95%)1900 +ve
→(20% patients) 2000 "sick"→⎜
→(5%) 100 -ve
10000 people→
→(10%) 800 +ve
→→→(80%) 8000 "healthy"→⎜ 
→(90%) 7200 -ve

In 10,000 people 1900+800=2700 test +ve (27%); 7300 test -ve (73%).

So the likelihood of anyone in the population testing positive is 27%.

You can substitute algebraic quantities in place of actual figures using the table as a guide.

Not sure if this is what you meant, but I hope it's helpful.

by Top Rated User (1.1m points)

Related questions

1 answer
asked Oct 9, 2021 in Statistics Answers by Noor Level 1 User (120 points) | 411 views
1 answer
1 answer
asked Aug 11, 2014 in Statistics Answers by anonymous | 1.1k views
1 answer
asked Jul 13, 2013 in Statistics Answers by Leon89 Level 1 User (160 points) | 1.6k views
2 answers
1 answer
asked Mar 23, 2013 in Statistics Answers by Akilie Level 1 User (140 points) | 1.4k views
1 answer
Welcome to MathHomeworkAnswers.org, where students, teachers and math enthusiasts can ask and answer any math question. Get help and answers to any math problem including algebra, trigonometry, geometry, calculus, trigonometry, fractions, solving expression, simplifying expressions and more. Get answers to math questions. Help is always 100% free!
87,542 questions
99,811 answers
2,417 comments
523,700 users