Question: This is a Statistics assignment, but we need to do the R coding using Jags, so the R code has to be put in JAGS

 This is a Statistics assignment, but we need to do theR coding using Jags, so the R code has to be putin JAGS form. Please answer with R code, and note that we

This is a Statistics assignment, but we need to do the R coding using Jags, so the R code has to be put in JAGS form.

Please answer with R code, and note that we are using JAGS

Thank you :-)

A farmer has a large paddock with N=1500 sheep. There are two different coloured sheep in the paddock; white or black. You have been tasked with estimating the total number of black sheep in the paddock, K. Rather than enumerating all of the sheep (which, for obvious reasons, is unfeasible), you decide to collect a sample of size n=50 without replacement for three consecutive days. The number of black sheep you count on the three days is y=(11,8,12). This is an example of a hypergeometric likelihood model, because you are counting without replacement on each of the three days. You may assume that the sampling on the three days are independent of each other. Let Y be a hypergeometric random variable. The probability mass function for Y is given by: P(Y=k)=((n)(Kk)(NKnk). You already know what N and n are, and you want to estimate parameter K. You will use a discrete-uniform prior on K, where each value, K=0,1,,1500, is equally likely. That is: p(K)=15011,K=0,1,,1500 Hint 1: You can use the categorical distribution in JAGS to model the discrete-uniform prior. Have a look at the dcat function in the JAGS user manual to use for your prior. Hint 2: Have a look at the the dhyper function in the JAGS user manual for your likelihood. There are four arguments for the dhyper function. The first is the number of black sheep, the second is the number of white sheep, the third is the sample size, and the fourth is set to 1. (a) [2 Marks] Write the R code to create a vector p; the prior probability of each possible value of K. (b) [3 Marks] Create your data as a list and variable to monitor. Note, your data list should contain y,N,p, and n. You may also set M=3 to represent the number of data points you have (this may be useful for your likelihood in 1 (c)). (c) 6 Marks ] Write the JAGS model code for this problem. Hint: dcat starts at 1. You will need a deterministic transformation to ensure the lowest possible value for K is 0 . (d) [2 Marks] Run your MCMC simulation in JAGS by sourcing "run_jags.R". Run your code for 10,000 proper steps, with 1,000 burn-in, and a thinning factor of 1. Plot the trace plot of K and comment on whether you think the chain has converged. (e) [7 Marks] (i) [1 Marks] Compute the posterior median for the total number of black sheep in the paddock. (ii) [2 Marks] Compute the 95% credible interval for the total number of black sheep in the paddock, and state your answer in plain English. (iii) [2 Marks] Compute the posterior probability that there are at least 400 black sheep in the paddock, and state your answer in plain English. (iv) 2 Marks] Compute the posterior probability that there are fewer than 200 black sheep in the paddock, and state your answer in plain English. A farmer has a large paddock with N=1500 sheep. There are two different coloured sheep in the paddock; white or black. You have been tasked with estimating the total number of black sheep in the paddock, K. Rather than enumerating all of the sheep (which, for obvious reasons, is unfeasible), you decide to collect a sample of size n=50 without replacement for three consecutive days. The number of black sheep you count on the three days is y=(11,8,12). This is an example of a hypergeometric likelihood model, because you are counting without replacement on each of the three days. You may assume that the sampling on the three days are independent of each other. Let Y be a hypergeometric random variable. The probability mass function for Y is given by: P(Y=k)=((n)(Kk)(NKnk). You already know what N and n are, and you want to estimate parameter K. You will use a discrete-uniform prior on K, where each value, K=0,1,,1500, is equally likely. That is: p(K)=15011,K=0,1,,1500 Hint 1: You can use the categorical distribution in JAGS to model the discrete-uniform prior. Have a look at the dcat function in the JAGS user manual to use for your prior. Hint 2: Have a look at the the dhyper function in the JAGS user manual for your likelihood. There are four arguments for the dhyper function. The first is the number of black sheep, the second is the number of white sheep, the third is the sample size, and the fourth is set to 1. (a) [2 Marks] Write the R code to create a vector p; the prior probability of each possible value of K. (b) [3 Marks] Create your data as a list and variable to monitor. Note, your data list should contain y,N,p, and n. You may also set M=3 to represent the number of data points you have (this may be useful for your likelihood in 1 (c)). (c) 6 Marks ] Write the JAGS model code for this problem. Hint: dcat starts at 1. You will need a deterministic transformation to ensure the lowest possible value for K is 0 . (d) [2 Marks] Run your MCMC simulation in JAGS by sourcing "run_jags.R". Run your code for 10,000 proper steps, with 1,000 burn-in, and a thinning factor of 1. Plot the trace plot of K and comment on whether you think the chain has converged. (e) [7 Marks] (i) [1 Marks] Compute the posterior median for the total number of black sheep in the paddock. (ii) [2 Marks] Compute the 95% credible interval for the total number of black sheep in the paddock, and state your answer in plain English. (iii) [2 Marks] Compute the posterior probability that there are at least 400 black sheep in the paddock, and state your answer in plain English. (iv) 2 Marks] Compute the posterior probability that there are fewer than 200 black sheep in the paddock, and state your answer in plain English

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!