title: Assignment 1
author: YOUR NAME
date: September 25, 2019 (due October 2, 2019)
output: html_document
`{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
`
Note: This is an individual assignment. No discussion with a fellow student is allowed. Honor code is in place.
## Question 1
1. Write a R function that generates (simulates) n observations from the sequence
$$
y_t = alpha + phi y_{t-1} + varepsilon_t, ,,t = 1,2,,n
$$
starting with $y_0 = 0$, where $varepsilon_t$ is a discrete random variable that takes the value 1 with prob .5 and the value -1 with prob .5.
`{r}
# write your code here
`
2. Write another function that does the same problem, but this time under the assumption that $varepsilon_t$ is N(0,1).
`{r}
# write your code here
`
3. Use these two functions to generate 500 observations on each process. Assume that $alpha = .5$ and $phi = .7$.
`{r}
# write your code here
set.seed(1)
`
4. Use the ggplot2 package to display the two time series you have generated on the same plot.
`{r}
# write your code here
`
## Question 2
Suppose that in the population, Y, the variable of interest, follows a N(mu,sigma2) distribution, where mu is the mean and sigma2 is the variance. Suppose that you have n iid observations on Y, y_i, where i goes from 1 to n.
1. Write down the model of y_i as a regression.
2. Under the assumption that mu = 2.5 and sigma2 is 1.5, write down code for generating n = 200 iid observations from the population.Store the generated data in a data.frame called datdf.
`{r}
# write your code here
set.seed(10)
`
3. Now use the MCMCregressg function to estimate the N(mu,sigma2) model on the data you just generated. Based on the output, what are the posterior mean and variance of mu and sigma2?
`{r}
# write your code here
`
4. use the sampled MCMC draws from question 3, and the method of composition to predict y(n+1) by the method of composition. From this simulation, what do you find are the posterior mean and sd of y(n+1)?
`{r}
# write your code here
set.seed(100)
`
Reviews
There are no reviews yet.