---
title: Assignment 3 Due Friday, October 18 at midnight
author: Your name
format:
  html:
    embed-resources: true
  #pdf: default
  
---

Download the .qmd source for this document [here](https://raw.githubusercontent.com/juliaSchedler/Stat416_CourseWebsite/refs/heads/main/Assignments/Assignment3.qmd).

## 1. Math
Recall the so-called "trend-stationary" model 
$$
x_t = \mu_t + y_t
$$

1. [3 points] There are three terms (symbols) in that equation. Which symbol corresponds to the trend, and which corresponds to the stationary part? What would you call the remaining symbol?

2. We have considered a few possible models for the trend:
$$
\begin{aligned}
\mu_{LM,t} &= \beta_0 + \beta_1 t  \\
\mu_{RW,t} &=  \delta + \mu_{RW, t-1} + w_t
\end{aligned}
$$
2. [2 points] What do "RW" and "LM" stand for?

3. [4 points] Between $\mu_{LM,t}$ and $\mu_{RW,t}$, which has "more interesting" temporal structure[2 points]? Why[2 points]?

4. [4 points] Write down the equations for $x_{LM, t}$ and $x_{RW,t}$

Consider this (edited) excerpt from the textbook (page 49):

::: {.callout-tip appearance="simple" icon="false"}
## Differencing vs. Detrending

One advantage of differencing over detrending to remove trend is that no parameters are estimated in the differencing operation. One disadvantage, however, is that differencing does not yield and estimate of the stationary process $y_t$. 

For example, if we difference a random walk $x_t$ with drift $\delta$, 

$$
x_t - x_{t-1} = \delta + w_t + y_t - y_{t-1}.
$$

If an estimate of $y_t$ is essential, then detrending may be more appropriate. This would be the case, for example, if we were interested in the business cycle of commodities.

If the goal is to coerce the data to stationarity, then differencing may be more appropriate. Differencing is also a viable tool if the trend is fixed, that is, when using $\mu_{LM,t}$ as the trend model, we have:
$$
x_t - x_{t-1} = \beta_1 + y_t - y_{t-1}
$$
Because differencing plays a central role in time series analysis, it receives its own notaiton. The first difference is denoted:
$$
\nabla x_t = x_t - x_{t-1}
$$
As we have seen, the first difference eliminates a linear trend. A second difference can eliminate a quadratic trend, and so on. Differences of order $d$ are denoted:
$$
\nabla^d = (1-B)^d
$$
:::

5. [1 point] Take a look in the book. What is $B$ called? 

6. [6 points] Why is it an "advantage" that no parameters are estimated in the differencing operation?

7. [6 points] Connect part 2 question 9 below to a sentence in the above excerpt.    

7. [10 points] What kind of plot might you make to check if the data has been "coerced to stationarity"?

8. [3 points] Rate your math anxiety (1 = effortless, 100 = nightmare) while working on this problem.


## 2. Data Analysis (code)

1. [10 points] Adapt the code from Example 1.2 in the book to plot just the global land temperature series in a time series plot. [2 points]. Describe the structure of the trend and/or seasonal components, if present[8 points]. 

```{r}
#| label: part 1
#| message: true
# your code here
```

2. [4 points] How frequently were the observations collected? 
```{r}
#| label: part 2
#| message: true
# your code here
```

3. [5 points] Plot the autocorrelation function of the global land temperature series. Comment on the temporal structure.

```{r}
#| label: part 3
#| message: true
# your code here
```
4. [15 points] Estimate the trend of the series using a symmetric, equally weighted 5-point moving average[4 points]. Plot the trend estimate on top of the data [4 points]. Comment on the trend-- does it reveal any patterns difficult to see in the data?[7 points]

```{r}
#| label: part 4
#| message: true
# your code here
```

5. [10 points] Estimate the trend of the series using a linear regression on time[3 points]. Plot the trend estimate on top of the data[3 points]. Is this trend estimate comparable to the moving average?[4 points]

```{r}
#| label: part 5
#| message: true
# your code here
```

6. [15 points] De-trend the data with respect to each of the trends you estimated [4 points each]. Make a time series plot of each result [1 point each] and an acf of each result [1 point each]. Comment on the temporal structure in each of the plots. 

```{r}
#| label: part 6
#| message: true
# your code here
```

7. [20 points] Difference the time series and plot the result[5 points]. Also compute the acf and plot it[5 points]. Comment on whether the differencing has "coerced the data to stationarity"[10 points]. 

```{r}
#| label: part 7
#| message: true
# your code here
```

8. [11 points] Estimate the sum of squared error for both the linear regression and the moving average [3 points each]. What do they suggest about which model is "better"?[3 points] Does this agree with your visual assessments in 3 and 4?[2 points]

```{r}
#| label: part 8
#| message: true
# your code here
```

9. [10 points] Why can't you do part 6 for the differenced series?

10. [3 points] Ensure that when you render the document to .html to turn in that you have `embed-resources: true` in the options at the top of the document (you may also turn in a pdf). Also, set message to false for all the code chunks.

## 3. The literature
The original paper for the data set you just analyzed [can be found here](https://agupubs.onlinelibrary.wiley.com/doi/epdf/10.1029/JD092iD11p13345). 

1. [2 points] Set a timer for 5 minutes. Find one sentence you feel you understand, and one you do not understand but would like to understand better. 

2. [4 points] Take a look at Figure 6. There are six time series plotted. One is the data plotted in number 1 of the coding portion, the other is the moving average estimate estimated in number 3. Which of the six series are they?

3. [4 points] The textbook for our class states on page 3 that "the data are annual temperature anomalies averaged over the Earth's land area.". Does the book state what is specifically meant by "anomaly" here? 

4. [2 points] Consider the concept of averaging over the Earth's land area, then take a look at Figure 1. Describe in therms of the "circles" how you might calculate that global average. 

5. [15 points] Figure 3 plots correlation coefficients between annual mean temperature changes for pairs of randomly selected stations having at least 50 common years in their records. How can you rephrase "annual mean tempearture changes" in terms of detrending or differencing? 

## 4. Weights

1. [6 points] One might consider the points I have given to each numbered problem as "weights". Based on the weights, which content is the most important? Answer on both the individual problem level and the section level (i.e. math, code, etc).
