R: Generate samples from posterior with MCMC

31 Views Asked by At

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.

We assume that the results of different tests are independent.

Let q = 10%, p = 95% and s = 20%

  1. Generate data for 1000 people who came to be tested

I did it with this code:

samp <- sample(1:4, 1000, replace=TRUE, prob=c(.19,.01,.08,.72))

stat <- c("sick", "sick", "healthy", "healthy")
tst <- c("positive", "negative", "positive", "negative")
test_data <- data.frame(
  health = stat[samp], 
  test_result = tst[samp]
)
head(test_data)

Let te periors to be:

$$f_q(q)=\begin{cases}2q, &\text{if } 0\leq q\leq1\\ 0, &\text{otw } \end{cases}.$$

$$f_p(p)=\begin{cases}2(1-p), &\text{if } 0\leq p\leq1\\ 0, &\text{otw } \end{cases}.$$

$$s\sim U(0,1)$$

I was asked to Generate 10,000 samples from posterior with MCMC.

My question is if have to product all these periors because they are independent and then to run MCMC and generate the samples or I have to do this separately for each prior?