---
title: "Time Series Homework: Chapter 4 Lesson 4"
subtitle: "Please_put_your_name_here"
format: 
  html:
    embed-resources: true
    toc: true
---

```{r, echo=FALSE, message=FALSE, warning=FALSE}

# Loading R packages
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, 
               tsibble, fable,
               feasts, tsibbledata,
               fable.prophet,
               patchwork,
               lubridate, 
               rio,
               ggplot2,
               kableExtra
               )
```

## Data

```{r, message=FALSE}

exuseu <- rio::import("https://byuistats.github.io/timeseries/data/exuseu.csv")
```

## Questions

### Question 1 - Context and Measurement (10 points)

The first part of any time series analysis is context. You cannot properly analyze data without knowing what the data is measuring. Without context, the most simple features of data can be obscure and inscrutable. This homework assignment will center around the series below.

Please research the time series. In the spaces below, give the data collection process, unit of analysis, and meaning of each observation for the series.

#### a) Dollar-Euro Exchange Rate

[FRED](https://fred.stlouisfed.org/series/DEXUSEU)

::: {.callout-note title="Answer" icon="false"}
<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

### Question 2 - Key Definitions (10 points)

Answer the prompt to the learning outcome below. Include any mathematical expressions or illustrations that may accompany the definitions and ideas if available.

::: {.callout-note title="Answer" icon="false"}
-   **Explain the difference between parameters of the data generating process and its sample estimates** <!-- Delete this and put your answer here. -->
:::

### Question 3 - Sneaky AR(2) (50 points)

#### a) Simulate an AR(2) process with $n=100, \mu=0,\alpha_1=0.25, \alpha_2=0.1, \sigma^2=1$

::: {.callout-note title="Answer" icon="false"}
```{r}



```
:::

#### b) Is the AR(2) process stationary? Please use the characteristic equation method (use R) and report your results in a table.

::: {.callout-note title="Answer" icon="false"}
```{r}



```
:::

#### c) Let R decide how many lags between 1 and 9 to fit the simulated series. Try it a few times. How often were the model parameters inside the estimate's confidence intervals?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

#### d) Increase n to 1000. Repeat part c. Did the R routine obtain better estimates?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

#### e) How much trust should you have in R's model fitting routine when you don't know what the data generating process is?

::: {.callout-note title="Answer" icon="false"}
<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

### Question 4 - Stationarity and AR(p) fitting (60 points)

A key assumption when fitting AR(p)) models is that the time series data is stationary. Stationarity ensures that the statistical properties of the series remain constant over time, so our estimates of the mean, variance, and temporal relationships are valid. Non-stationary data, characterized by trends or changing mean and variance, can lead to unreliable parameter estimates and inaccurate forecasts when using AR(p) models. To address non-stationarity, a common solution is to apply differencing, particularly first differencing. By employing first differencing, the non-stationary series can be transformed into a stationary form, allowing for the application of AR(p) models with more confidence and accuracy.

#### a) Plot the Dollar-Euro Exchange Rate series, it's correlogram, and a partial correlogram. Is the series stationary?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

#### b) Fit an AR(p) model to the data by letting R choose how many lags to use? Please report your results in a table.

::: {.callout-note title="Answer" icon="false"}
```{r}



```
:::

#### c) Is the fitted model stationary? Would you use the fitted model as the basis for forecasting?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

#### d) Take the first-difference of the Dollar-Euro Exchange Rate series.

::: {.callout-note title="Answer" icon="false"}
```{r}



```
:::

#### e) Plot the differenced series, it's correlogram, and a partial correlogram. Is the series stationary?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

#### f) Fit an AR(p) model to the data by letting R choose how many lags to use? Please report your results in a table.

::: {.callout-note title="Answer" icon="false"}
```{r}



```
:::

#### g) Is the fitted model stationary? Would you use the fitted model as the basis for forecasting?

::: {.callout-note title="Answer" icon="false"}
```{r}



```

<!-- Delete this and put your answer here. The three colons mark the end of your answer. -->
:::

### Rubric

+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Criteria**                                            | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 1: Context and Measurement**            | The student thoroughly researches the data collection process, unit of analysis, and meaning of each observation for both the requested time series. Clear and comprehensive explanations are provided.                                                                                                                                                                                                          | The student does not adequately research or provide information on the data collection process, unit of analysis, and meaning of each observation for the specified series.                                                                                                                                  |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2: Definitions**                        | The student provides sufficient evidence of mastery of the outcome prompt. The submission included mathematical expressions or illustration if available in the text or the Time Series Notebook                                                                                                                                                                                                                 | The student did not provide sufficient evidence to evaluate the outcome prompt.                                                                                                                                                                                                                              |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3a: Simulation 1**                      | Students correctly simulate the AR(2) process with specified parameters using well-commented code in R.                                                                                                                                                                                                                                                                                                          | Students attempt to simulate the AR(2) process but encounter errors in parameter specification or fail to produce the correct dataset length. Code clarity may be lacking.                                                                                                                                   |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3b: Stationarity**                      | Students use well-commented R code to determine the stationarity of the AR(2) process using the characteristic equation method.                                                                                                                                                                                                                                                                                  | Students may make errors in implementing or interpreting the characteristic equation method. Results reporting may lack clarity, and code comments may be insufficient.                                                                                                                                      |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3c: AR(p) fitting**                     | Students utilize well-commented R code to fit AR models with varying lag numbers to the simulated series. Their discussion of the frequency of estimates marching model parameters is clear and easy to understand                                                                                                                                                                                               | Students may make errors in specifying lag ranges or interpreting results. Reporting of parameter confidence intervals may be incomplete, and code comments may lack clarity.                                                                                                                                |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3d: Increased n**                       | Students correctly increase the sample size to 1000 and repeat the procedure from part c with well-commented code. They compare the results with those obtained using a smaller sample size.                                                                                                                                                                                                                     | Students may fail to adequately compare results or assess estimate quality when increasing the sample size. Analysis may be incomplete or inaccurate, and code comments may lack clarity.                                                                                                                    |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3e: Evaluation**                        | Students provide a thoughtful analysis of the reliability of R's model fitting routine in unknown data generating process situations. They discuss potential limitations and considerations when relying on automated model fitting algorithms. The response shows the students understand the relatioship between sample size and the precision of estimates.                                                   | Students may provide a superficial analysis or overlook important considerations when discussing R's model fitting routine reliability. Analysis may lack depth or accuracy, and code comments may be insufficient.\                                                                                         |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4a: Plot Original Series**              | Students create high-quality plots of the Dollar-Euro Exchange Rate series, its correlogram, and a partial correlogram, ensuring clarity and appropriate labeling. They analyze the plots to determine stationarity, providing clear explanations supported by the visual evidence.                                                                                                                              | Students produce plots of the Dollar-Euro Exchange Rate series, its correlogram, and a partial correlogram but with lower quality or clarity, lacking appropriate labeling or detail. Analysis of stationarity may be incomplete or inaccurate, lacking clear explanations supported by the visual evidence. |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4b: AR(p) fitting**                     | Students use R to fit an AR(p) model to the data, allowing R to determine the optimal number of lags. They report the results in a clear and organized table format, including parameter estimates and statistical significance.                                                                                                                                                                                 | Students encounter difficulties in fitting the AR(p) model or fail to properly report the results in a table format. Inaccuracies or omissions in parameter estimates and statistical significance reporting may be present.                                                                                 |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (15)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4c: Fitted Model Stationarity**         | Students assess the stationarity of the fitted AR(p) model using the absolute value of the roots of the characteristic equation. They use the polyroot() function. Students make a reasoned judgment regarding the model's suitability for forecasting, considering its stationarity and the sensitivity of the forecast to changes in parameter values that may be statistical but not practically significant. | Students provide an incomplete or inaccurate assessment of the stationarity of the fitted AR(p) model. Their judgment regarding the model's suitability for forecasting may lack justification or clarity.                                                                                                   |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4d: First Difference**                  | Students correctly compute the first difference of the Dollar-Euro Exchange Rate series in R.                                                                                                                                                                                                                                                                                                                    | Students encounter errors or inaccuracies in computing the first difference, resulting in incorrect or incomplete data transformation.                                                                                                                                                                       |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4e: Plot Difference**                   | Students create high-quality plots of the differenced series, its correlogram, and a partial correlogram, ensuring clarity and appropriate labeling. They analyze the plots to determine stationarity, providing clear explanations supported by the visual evidence.                                                                                                                                            | Students produce plots of the differenced series, its correlogram, and a partial correlogram but with lower quality or clarity, lacking appropriate labeling or detail. Analysis of stationarity may be incomplete or inaccurate, lacking clear explanations supported by the visual evidence.               |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4f: AR(p) fitting of first difference** | Students use R to fit an AR(p) model to the differenced data, allowing R to determine the optimal number of lags. They report the results in a clear and organized table format, including parameter estimates and statistical significance.                                                                                                                                                                     | Students encounter difficulties in fitting the AR(p) model to the differenced data or fail to properly report the results in a table format. Inaccuracies or omissions in parameter estimates and statistical significance reporting may be present.                                                         |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                         | **Mastery (15)**                                                                                                                                                                                                                                                                                                                                                                                                 | **Incomplete (0)**                                                                                                                                                                                                                                                                                           |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 4g: Stationarity and Evaluation**       | Students assess the stationarity of the fitted AR(p) model on the differenced data using the characteristic equation of the parameter estimates. They make a reasoned judgment regarding the model's suitability for forecasting, considering its stationarity, magnitude and significance of coefficient estimates.                                                                                             | Students provide an incomplete or inaccurate assessment of the stationarity of the fitted AR(p) model on the differenced data. Their judgment regarding the model's suitability for forecasting may lack justification or clarity.\                                                                          |
|                                                         |                                                                                                                                                                                                                                                                                                                                                                                                                  | \                                                                                                                                                                                                                                                                                                            |
|                                                         |                                                                                                                                                                                                                                                                                                                                                                                                                  | \                                                                                                                                                                                                                                                                                                            |
|                                                         |                                                                                                                                                                                                                                                                                                                                                                                                                  | \                                                                                                                                                                                                                                                                                                            |
|                                                         |                                                                                                                                                                                                                                                                                                                                                                                                                  | \                                                                                                                                                                                                                                                                                                            |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Total Points**                                        | **125**                                                                                                                                                                                                                                                                                                                                                                                                          |                                                                                                                                                                                                                                                                                                              |
+---------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
