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

## Data

```{r, message=FALSE}

food_bev_ts <- rio::import("https://byuistats.github.io/timeseries/data/retail_by_business_type.parquet") |>
  filter(naics == 445) |>
  as_tsibble(index = month)

dep_stores_ts <- rio::import("https://byuistats.github.io/timeseries/data/retail_by_business_type.parquet") |>
  filter(naics == 4521) |>
  as_tsibble(index = month)

```

## 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"}
-   **Explain when to use a log-transformation** <!-- Delete this and put your answer here. -->

-   **Explain when to use non-linear models** <!-- Delete this and put your answer here. -->
:::

### Question 2 - Model Selection (55 points)

##### a) Plot the Department Stores (NAICS: 445) series.

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



```
:::

##### b) Using the plot, speculate, which model is likely to be a good fit for the time series? Please specify the trend, seasonality, and random component modeling choices.

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

##### c) Please estimate three alternative models you think could be reasonable candidates for the data generating process for the Department Stores time series. Provide a table comparing the models the AIC, AICc, and BIC.

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



```
:::

##### d) Justify your preferred model, make sure you take into account both the model selection criteria and the discussion on the dangers of only using algorithms for model selection found on the Time Series notebook (5.3).

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



```

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

### Question 3 - Non-linear Model (35 points)

##### a) Plot the Food and Beverage Retail Sales series (NAICS: 4521) series.

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



```
:::

##### b) Estimate an exponential non-linear model. Report the results in a professionally formatted tables.

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



```

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

##### c) Please interpret the estimates for the coefficients of the non-linear exponential model. Pretend you are presenting the results to an executive who took a linear regression course in undergraduate but is not an expert.

::: {.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 (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: Plot**                                | Students plot the series, ensuring high-quality visualization with clear labels and titles.                                                                                                                                                                                                                                                                                                                                                                                                                       | Submissions have low-quality visualizations or unclear labeling.                                                                                                                                                                                                                                                                          |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2b: Model Speculation**                   | Students provide a well-reasoned speculation on the likely model fit based on the plot, specifying model features for the trend, seasonality, and random component modeling choices. They articulate their reasoning clearly and logically, demonstrating an understanding of time series modeling principles.                                                                                                                                                                                                    | Submissions lack one or more modeling components, or provide a vague or superficial reasoning. The discussion doesn't provide enough evidence of understanding. The mathematical expressions are not in LaTex format and are hard to read                                                                                                 |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2c: Model Candidate**                     | Students propose three alternative models that are plausible candidates for the data-generating process of the Department Stores time series. The estimates include a models for the trend, seasonality, and random component. If there is autocorrelated error terms, the students apply the appropriate algorithm to avoid bias. They estimate each model and construct a clear and organized table comparing the models based on the AIC, AICc, and BIC criteria. The code is well-commented and easy to read. | There is one or more models missing. The estimation procedures has autocorrelation bias. There is one or more model components missing (trend, seasonality, random component). The table and results are not easy to read. One or mode models are not plausible candidates for the data generating process. The code is not easy to read. |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2d: Model Selection and Justification**   | The model justification uses statistical tests, practical significance and interpretability considerations, and model selection criteria to show what variables to include and which not to include. Students demonstrate a comprehensive understanding of the strengths and weaknesses of different model selection approaches and effectively integrate this knowledge into their justification.                                                                                                                | Students struggle to provide a clear and well-supported justification for their preferred model. They may overlook one or more of the criteria enumerated in the mastery section of this rubric item. Their justification doesn't provide enough evidence of mastery of model selection principles.\                                      |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (5)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3a: Plot**                                | Students plot the series, ensuring high-quality visualization with clear labels and titles.                                                                                                                                                                                                                                                                                                                                                                                                                       | Submissions have low-quality visualizations or unclear labeling.                                                                                                                                                                                                                                                                          |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3b: Non-Linear Exponential Model**        | Students estimate an exponential non-linear model. They present the results in professionally formatted tables, including all relevant parameters and statistics. The estimates include a model for the trend, seasonality, and random component. If there is autocorrelated error terms, the students apply the appropriate algorithm to avoid bias.                                                                                                                                                             | The estimation procedures has autocorrelation bias. There is one or more model components missing (trend, seasonality, random component). The table and results are not easy to read. The code is not easy to read.                                                                                                                       |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3d: Interpretation Non-Linear Estimates** | Students provide correct and understandable interpretations of the coefficient estimates for the logarithmic transformation model, catering to the level of their audience. They effectively communicate the implications of each coefficient in straightforward language, making the interpretation accessible to someone with limited statistical expertise.                                                                                                                                                    | Interpretations of the coefficient estimates are incorrect or unclear, making it difficult for a non-expert audience to understand the implications of the results. Students may use overly technical or jargon-filled language, failing to effectively communicate the interpretation to the intended audience.\                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | \                                                                                                                                                                                                                                                                                                                                         |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Total Points**                                          | **100**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                                                                           |
+-----------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
