---
title: "Time Series Homework: Chapter 5 Lesson 5"
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)

```

## Questions

### Question 1 - Key Definitions (5 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"}
-   **State the bias correction procedure for log-transform estimates** <!-- Delete this and put your answer here. -->
:::

### Question 2 - Logarithmic Transformation Estimation and Bias Correction (60 points)

You used the Food and Beverage Retail Sales series (NAICS: 4521) in the previous homework assignment. You estimated it with non-linear exponential model.

a)  Please estimate the Food and Beverage Retail Sales series using the logarithmic transformation of the series. Report the results in a professionally formatted table.

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



```
:::

b)  Please justify your model specification.

::: {.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 logarithmic transformation 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. -->
:::

d)  Please evaluate the estimation residuals and use the appropriate bias correction procedure for log-transform estimates. Please justify your choice.

::: {.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 - Logarithmic Transformation vs Non-linear Estimation (40 points)

You have estimated and interpreted two models for the Food and Beverage Retail Sales series.

a)  Compare the relative ease of interpreting and explaining the regression coefficients.

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

b)  Use the AIc, AICc, and BIC to compare your prefer specifications of each model.

::: {.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: 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 (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2a: Log Estimation**                      | Students propose three alternative models that are plausible candidates for the data-generating process of the 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.                                                                                                                                                   | 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 more models are not plausible candidates for the data generating process. The code is not easy to read. |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2b: Model Selection**                     | 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 model selection criteria missing. Their justification lacks a discussion of the non-algorithmic factors influencing model selection.                                                                                                                                                                                 |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (10)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2c: Interpretation of 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.\                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | \                                                                                                                                                                                                                                                                                                                                         |
|                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | \                                                                                                                                                                                                                                                                                                                                         |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 2d:Bias Correction**                      | Students evaluate the estimation residuals, using a histogram to identify patterns that may indicate bias in the log-transform estimates. They select the appropriate bias correction procedure based on their assessment, considering factors such as the nature of the data, the assumptions of the bias correction method, and the potential impact on model accuracy. Their justification is clear, reasoned, and takes into account relevant considerations.  | Students don't adequately evaluate the estimation residuals or choose an appropriate bias correction procedure. Their analysis of the residuals may lack depth or overlook important patterns, such as skewness or outliers, which could indicate bias. The justification for the chosen method may be vague or lack detail.              |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3a: Ease of Interpretation**              | Students compare the ease of interpreting and explaining the regression coefficients between the two models. They highlight the differences in interpretation stemming from the functional form of each model and articulate how these differences impact the clarity and intuitiveness of the coefficients' meanings.                                                                                                                                             | Students don't provide enough evidence that they understand how to interpret regression coefficients.                                                                                                                                                                                                                                     |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|                                                           | **Mastery (20)**                                                                                                                                                                                                                                                                                                                                                                                                                                                   | **Incomplete (0)**                                                                                                                                                                                                                                                                                                                        |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| #### **Question 3b: Log vs Non-Linear Exponential Model** | Students effectively use AIC, AICc, and BIC to compare model specifications, providing insightful analysis on the trade-offs between model complexity and goodness of fit. They justify their preferred model based on the results of these criteria.                                                                                                                                                                                                              | There is one or more model selection criteria missing. Their justification lacks a discussion of the non-algorithmic factors influencing model selection.                                                                                                                                                                                 |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Total Points**                                          | **105**                                                                                                                                                                                                                                                                                                                                                                                                                                                            |                                                                                                                                                                                                                                                                                                                                           |
+-----------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
