---
title: "HW 7"
author: "Name here"
date: "Due November 12, 2018"
output: html_document
---

### Q1. 

#### a. (4 points)
Identify the p and q values for the following ARMA models written in the characteristic equation.

- $(1−\frac{1}{2}B)(1−\frac{1}{3}B)x_t = w_t$

- $(1−\frac{1}{2}B)x_t = (1−\frac{1}{3}B)w_t$

#### b. (4 points)
Express the following ARMA models with the characteristic equation.

- $x_t= \frac{1}{2} x_{t-1} + w_t + \frac{1}{4} w_{t-1}$

- $x_t=  w_t - \frac{3}{4} w_{t-1} + \frac{1}{8} w_{t-2}$

### Q2. (10 points)
Include code for this question. Note the simulations should be conducted several times to limit the Monte Carlo variation in your answers.

#### 436 Only

Simulate a MA(1) process with $\beta = .5$ and estimate the lag 1 and lag 2 correlation (you can use the `arima.sim` function). That is estimate $\rho(x_t, x_{t+1})$ and $\rho(x_t, x_{t+1})$.

How do the results match with your expectations?

#### 536 Only

Simulate a ARMA(1,1) process with $\alpha = .7$ and $\beta = .5$ and estimate the lag 1 and lag 2 correlation (you can use the `arima.sim` function). That is estimate $\rho(x_t, x_{t+1})$ and $\rho(x_t, x_{t+1})$.

How do the results match with your expectations?

### Q3. (7 points)

Evaluate the code below and describe the results.
```{r}
library(readr)
library(dplyr)
library(forecast)
bakery.sales <- read_csv('http://math.montana.edu/ahoegh/teaching/timeseries/data/BreadBasket.csv')
pastry.count <- bakery.sales %>% filter(Item %in% c('Pastry','Scandinavian','Medialuna','Muffin','Scone')) %>% group_by(Date) %>% tally() %>% rename(num.pastry = n) %>% select(num.pastry) %>% pull() %>% ts(frequency =7)
```

#### 436 Only
```{r, eval = F}
ggtsdisplay(pastry.count)
auto.arima(pastry.count, max.d = 0, seasonal = F)
```
#### 536 Only
```{r, eval = F}
ggtsdisplay(pastry.count)
auto.arima(pastry.count, max.d = 0, max.D = 0)
```

