DAT 537 Assignment 2
Note: This is an individual assignment. No discussion with a fellow student is allowed. Honor code is in place.
Copyright By PowCoder代写 加微信 powcoder
## Question 1
1. Write a R function that generates (simulates) n observations from the sequence
yt =α+φyt−1 +εt, t=1,2,…,n
starting with y0 = 0, where εt is a discrete random variable that takes the value 1 with prob .5 and the value -1 with prob .5.
2. Write another function that does the same problem, but this time under the assumption that εt is N(0,1).
3. Use these two functions to generate 500 observations on each process. Assume that α = .5 and φ = .7.
4. Use the ggplot2 package to display the two time series you have generated on the same plot.
## Question 2
Suppose that in the population, Y , the variable of interest, follows a N(μ,σ2) distribution, where μ is the mean and σ2 is the variance. Suppose that you have n iid observations on Y , yi, where i goes from 1 to n.
1. Write down the model of yi as a regression.
yi = μ + εi, εi ~N(0,σ2),i = 1, 2, …, n
2. Under the assumption that μ = 2.5 and σ2 = 1.5, write down code for generating n = 200 iid
observations from the population. Store the generated data in a data.frame called datdf.
3. Now use the MCMCregressg function to estimate the N(μ,sigma^2) model on the data you just generated.
Based on the output, what are the posterior mean and variance of μ and sigma^2?
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com