---
title: "Time Series Homework: Chapter 5 Lesson 2"
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(nlme,tsibble, fable,feasts, tsibbledata,
               fable.prophet, patchwork,lubridate, 
               rio,ggplot2,kableExtra,tidyquant, 
               dplyr , plotly,tidymodels, 
               multilevelmod, broom.mixed
)
```

## Questions

### Question 1 - 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"}
-   **Motivate the use of the harmonic seasonal model** <!-- Delete this and put your answer here. -->

-   **State the additive model with harmonic seasonal component** <!-- Delete this and put your answer here. -->
:::

### Question 2 - Seasonal Harmonics: Quarterly Data (35 points)

##### a) State a linear regression model with a quadratic trend and quarterly harmonic seasonal variables. Your model should be written in the expanded form, showing each component, not using the summation notation.

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

##### b) Using the time variable created below, create the quarterly harmonic seasonal variables of your model. In a plot, overlap all the seasonal variables you created for the first four quarterly seasons. Please make sure you label each variable.

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



```
:::

c)  Currently, the only difference between all the variables you created is the frequency of the underlying sine and cosine functions. Please explain the effect of changing the frequency of the functions used to create the harmonic variables. What is the purpose of doing so?

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

d)  When we estimate the model parameters $\alpha_{s}=A\cos(\phi)$ and $\alpha_{c}= A\sin(\phi)$ how does different values of the parameters change the shape of the fitted harmonic components, please explain.

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

### Question 3 - Seasonal Harmonics: Daily Data (15 points)

##### a) State a linear regression model with an exponential trend and daily harmonic seasonal variables. Your model should be written in the expanded form, showing each component, not using the summation notation.

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

##### b) Using the time variable created below, create the daily harmonic seasonal variables of your model. In a plot, overlap all the seasonal variables you created for the first four weekly seasons.

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



```
:::

### Question 4 - Model Selection CriteriaAIC (30 points)

In time series analysis,the concept of model selection criteria plays a crucial role. Model selection criteria are statistical measures designed to help us choose the most appropriate model from a set of competing models. These criteria balance the trade-off between model complexity and goodness of fit to the data, aiding us in identifying the model that best captures the underlying patterns and dynamics of the time series data. Commonly used criteria include the Akaike Information Criterion (AIC), its corrected version (AICc), and the Bayesian Information Criterion (BIC), each offering unique perspectives on model selection. Understanding these criteria is essential for effectively building and evaluating time series models, empowering analyst to make informed decisions when analyzing real-world time series. While these criteria provide helpful guidance they are not without their caveats.By acknowledging and navigating these limitations thoughtfully, you can enhance the robustness and reliability of your time series analyses.

##### a) Please research the Akaike Information Criterion (AIC). Please state the model selection criteria and it's potential limitations.

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

##### b) Please research the AICc (Akaike Information Criterion corrected). Please state the model selection criteria and it's potential limitations.

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

##### c) Please research the BIC (Bayesian Information Criterion). Please state the model selection criteria and it's potential limitations.

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

### Rubric

+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| **Criteria**                                                         | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 1: 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 2a: Quadratic trend, quarterly harmonics model**     | Students state the linear regression model with a quadratic trend and quarterly harmonic seasonal variables, providing each component in expanded form.                                                   | The model is incorrect, it contains extraneous components, or is not showing all the components to be evaluated.                                                                                                                       |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 2b: Quadratic trend, quarterly harmonics variables** | Students create the quarterly harmonic seasonal variables and plot them, ensuring clear labeling for each variable and providing well-commented code.                                                     | The variables are not created correctly, the plot is missing, or the plot is not correctly labeled. Code is not commented or is hard to read.                                                                                          |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 2c: Frequency**                                      | Students provide a clear explanation of how changing the frequency of the sine and cosine functions affects the harmonic variables and the purpose of doing so in modeling seasonal patterns.             | The response doesn't make clear that students understand the effect of changing the frequency on sine and cosine functions and their applications to seasonal pattern modeling.                                                        |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 2d: Amplitude and Phase**                            | Students explain how different values of the parameters affect the shape of the fitted harmonic components, considering variations in amplitude and phase angle, and provide well-commented explanations. | Explanation of how different values of the parameters change the shape of the fitted harmonic components may be incomplete, inaccurate, or unclear, lacking depth or coherence in discussing variations in amplitude and phase angle.  |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (5)**                                                                                                                                                                                           | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 3a: Exponential trend, weekly harmonics model**      | Students state the linear regression model with a exponential trend and daily harmonic seasonal variables, providing each component in expanded form.                                                     | The model is incorrect, it contains extraneous components, or is not showing all the components to be evaluated.                                                                                                                       |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 3b: Exponential trend, weekly harmonics variables**  | Students create the daily harmonic seasonal variables and plot them, ensuring clear labeling for each variable and providing well-commented code.                                                         | The variables are not created correctly, the plot is missing, or the plot is not correctly labeled. Code is not commented or is hard to read.                                                                                          |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 4a: AIC**                                            | Students accurately research the Akaike Information Criterion (AIC), stating its model selection criteria and potential limitations clearly and concisely.                                                | The model selection criterion is not stated correctly or is not clear that the student understand the tradeoffs and limitations of the criteria.                                                                                       |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (10)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 4b: AICc**                                           | Students accurately research the AICc (Akaike Information Criterion corrected), stating its model selection criteria and potential limitations clearly and concisely.                                     | The model selection criterion is not stated correctly or is not clear that the student understand the tradeoffs and limitations of the criteria.                                                                                       |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
|                                                                      | **Mastery (15)**                                                                                                                                                                                          | **Incomplete (0)**                                                                                                                                                                                                                     |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| #### **Question 4c: BIC**                                            | Students accurately research the Bayesian Information Criterion (BIC), stating its model selection criteria and potential limitations clearly and concisely.                                              | The model selection criterion is not stated correctly or is not clear that the student understand the tradeoffs and limitations of the criteria.                                                                                       |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
| **Total Points**                                                     | 95                                                                                                                                                                                                        |                                                                                                                                                                                                                                        |          |
+----------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------+
