0% found this document useful (0 votes)
6 views2 pages

Stat365 Homework 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Stat365 Homework 4

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Stat365 Homework 4 – due 10/25/2024

The homework is created on Posit cloud as an assignment called “Homework


4”. The memory and CPU of the assignment are increased. Please work
under this assignment so you can get the increased memory and CPU
setting.

I have an example homework there already called “HW4_example”, RMD and


HTML file (for Beta-Binomial model we discussed in class). Your homework
should have a similar format like this. Once you are done with homework,
export the knitted HTML and upload it on canvas so our TA can grade it.

For the whole homework use random seed 36501, when you generate
independent samples from the approximated posterior using grid
approximation, and when you use MCMC to derive the posterior.

1. 6.5 b
2. Suppose your prior is what described in section 5.1 f ( π ) =e−e π , πϵ [0 ,1],
and conditional on π ,Y ∨π Bin(n , π ). Suppose that in n = 10
independent trials you observed Y = 2 success (same as in 6.5). Use
grid approximation (same grid as 6.5) to get the posterior distribution
of π and plot it. Also, get the overlay plot of the posterior you got from
6.5b and the posterior you got here, with different colors for each
posterior. Compare the two posteriors and describe the difference
between them. The overlay plot should look like this

To get the posterior from a prior with PDF function f ( pi ) ,you need to
first define a function in R for it using

f <- function(pi) {
exp(1) – exp(pi)
}
Then your prior will be defined as prior <- f(pi_grid)
To get an overlay plot, you need to

 For each method, create a type variable for the prior type, for
example it can take value “Beta(2,2)” for your simulated results
when prior is given as Beta(2,2). It can take value “e - e^pi” for
your simulated results when prior is given as f ( π ) =e−e π
 Use rbind function to concatenate the two simulated data together
by rows
 Use ggplot(data = , aes( x = pi_grid, y = posterior,
color = type)) + geom_* to get the overlay plot
3. 6.6 b, 6.7 b
Please note that your likelihood for Poisson or normal will be the
product of the likelihood for each observed value. There is setup for
Grid approximation for Gamma-Poisson model in section 6.1
4. 6.13, 6.15, 6.17. Please note that
 There is setup for MCMC for Gamma-Poisson model in section 6.2
 Wen you setup MCMC for Normal – Normal model, since the
parameter and data are both unbounded, you can simply use
parameters {real mu} to denote that the parameter mu can be
any real number.
 Produce the trace plot and density plot for each chain individually
for 6.13, produce the trace plot and density plot for all chains
combined for 6.15. and produce the tract plot and density plot for
the individual chain overlaying for 6.17
 For all 6.13, 6.15 and 6.17, in addition to the questions a - e asked
in the textbook, please also do the following f – h
f. Get the effective sample size ratio, is it reasonable?
g. Output the autocorrelation plot for each of the chain (in one plot)
and describe whether the autocorrelation drops quickly to 0 by 5.
h. Calculate ^R , is it satisfactory?

You might also like