---
title: "Lab 10"
author: "Name here"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(warning = FALSE)
library(readr)
library(ggplot2)
library(dplyr)
library(lubridate)
library(ggfortify)
library(forecast)
library(tseries)
```
Please use D2L to turn in both the PDF/ Word output and your R Markdown file.


## Q1. Random Walk Sims (50 points)
For this question we will simulate a set of random walks to determine various properties

### a. 
Simulate 1000 random walks (this can be done with the code in lecture 17 or using arima.sim) of length 100. Using the Dickey-Fuller test, how many of random walks reject the null hypothesis of a non-stationary series? What is your expectation for this proportion?

### b. 
Simulate 1000 pairs of random walks (that is two independent series of random variables) with length 100. Using the Phillips-Ouliaris test, how many of pairs of random walks reject the null hypothesis of a non-cointegrated series? What is your expectation for this proportion?

### c. 536 Only
Simulate 1000 pairs of random walks (that is two independent series of random variables) with length 100. Fit a simple linear model with one series regressed against the other. What proportion of these regression models have a *significant* slope parameter (p-value < .05)? What is your expectation for this proportion?


## Q2. Avocados (50 points)

### a. 
Check whether the organic and conventional avocadoes are cointegrated. Interpret the results from the hypothesis test that you choose to use.
```{r}
avo <- read_csv('http://www.math.montana.edu/ahoegh/teaching/timeseries/data/avocado_west.csv')

ggplot(data = avo, aes(y = AveragePrice, x = Date)) + geom_line(aes(color = type))

avo.conv <- avo %>% filter(type == 'conventional') %>% arrange(Date)

avo.org <- avo %>% filter(type == 'organic') %>% arrange(Date)
```

### b. 
If the two series are not cointegrated, performing a regression analysis will potentially lead to spurious results and is not advised. Regardless of the results above, fit and intepret a vector autoregressive process for the two series (conventional and organic avocado prices).