程序代写 DAT 537 Assignment 3

DAT 537 Assignment 3

title: “Assignment 3”

Copyright By PowCoder代写 加微信 powcoder

output: pdf_document

“`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
rm(list=ls())
Note: This is an individual assignment. No discussion with a fellow student is allowed. Honor code is in place.

## Question 1

Suppose that you are given data from a normal population. The true value of μ in the population is .6 and the true value of σ2 is 1 (which you know). You have 500 observations from this population.

You then calculate the posterior on this grid. This is the code that you use to calculate the posterior of μ. and to plot the prior and posterior of μ.

1. Explain what is going on in the above code, line by line.

2. Next you decide to plot the prior and the posterior on the same graph using ggplot2.
Write code to do this. Your plot should have different colors the prior and the posterior, and a legend.

3. Write code to get 10,000 values from the posterior. Use this sample to find the posterior mean, sd, and .025 and .975 quantiles of μ.

4. Finally, you are asked to predict yn+1. Use the appropriate simulation method to get a sample of 10,000 values from the Bayesian prediction density of y501. Use these draws to find the mean, sd, and .025 and .975 quantiles of the predictive distribution.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com