---
title: "linear regression with ARMA noise"
output: html_document
---

## Linear regression with ARMA noise

Simulate data from a linear regression with ARMA noise in the following way: 
- Create an exogenous variable $x_t$ - either simulate this randomly, or pick deterministic values for example using some function of t
- Simulate the noise terms $\epsilon_t$ using an ARMA(1,1) model with parameters $\alpha_1=0.5$ and $\beta_1=0.5$. Is this process stationary?
- Calculate $y_t$ from $x_t$ and $\epsilon_t$ using the model $y_t = 2x_t + \epsilon_t$.

Next we fit a regression model to the simulated data

- Fit a regression model with ARMA(p,q) noise to the simulated data for various p and q. Compare the models using AIC. Which p and q give the best fit? 

- For the ARMA(1,1) model: estimate the parameters and compare them to the true values used for simulation. Check that the model is reasonable by checking that the residuals look like white noise. 

## Data example

Recall the elspot dataset from the lectures.

```{r}
elspot<-read.csv("https://asta.math.aau.dk/eng/static/datasets?file=elspot.csv", header = TRUE)
forecast<-ts(elspot[,2])
price<-ts(elspot[,3])
ts.plot(forecast,-price,col=1:2) # Price is negative to make the series positively correlated
```

In the lectures we fitted a regression model with AR(1) noise to the data.

- Try to fit various ARMA(p,q) models to the data with various p and q. Compare using AIC and residual plots.

- The forecasted wind and solar power production for day n+1 is 3000. Predict the elspot price on day n+1 and make a 95% confidence interval for this price.