type
Post
Created date
Jun 16, 2022 01:21 PM
category
Data Science
tags
Applied forecasting
Economics
status
Published
Language
From
summary
slug
password
Author
Priority
Featured
Featured
Cover
Origin
Type
URL
Youtube
Youtube
icon
This section builds up:
- How to make a regression forecast
- Metrics to decide good regression model
- View residual plots
- Correlation, causation and forecasting behind Regression
Multiple regression and forecasting
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F1df5fbc8-1e0e-4df1-930d-c59578c36e8c%2FUntitled.png%3Ftable%3Dblock%26id%3Ddde952ee-7846-4bd3-b499-1f4344319e09%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3D1BYKOZZRGaYmzWZV6qh58XU4joaE1Kifz9rsANlDHSI?table=block&id=dde952ee-7846-4bd3-b499-1f4344319e09&cache=v2)
- yt is the variable we want to predict: the “response” variable
- Each xj,t is numerical and is called a “predictor”. They are usually assumed to be known for all past and future times.
- The coefficients β1, . . . , βk measure the effect of each predictor after taking account of the effect of all other predictors in the model. I.E., the coefficients measure the marginal effects
Some useful predictors for linear models
Here we introduce 4 ways of dealing with predictors. They are Dummy Variable, Fourieer, Intervention variable, and distributed lag.
Dummy variables
Uses of dummy variables
Fourier series
Problem:
We know how to add dummy variables to the regression model, but the problem is that there will be too many terms (). For example,
- To find quarterly data, we set , then we get 3 dummy variables.
- To find yearly data, we set , then we get 11 dummy variables.
- To find hourly data, we set , then we get 23 dummy variables.
- To find weekly data, we set , then we get 51 dummy variables.
- To find daily data, we set to get the annual seasonality, then we get 364 dummy variables.
Which is way too many.
Solution: Fourier series - (i.e., harmonic regression)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F21dae3e0-5ff7-4ee5-8375-d4c7e6ef9574%2FUntitled.png%3Ftable%3Dblock%26id%3D0c0e3410-08b6-4f0f-a064-68b77c2f961b%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3Dotqi5TGVeZ_diepqaLPDVj5jxHE5mbfTgl-PKvy8Yq4?table=block&id=0c0e3410-08b6-4f0f-a064-68b77c2f961b&cache=v2)
We need fewer predictors than with dummy variables, especially when is large.
- Particularly useful for weekly data, for example, where m≈52. For short seasonal periods (e.g., quarterly data), there is little advantage in using Fourier terms over seasonal dummy variables.
What is K
K is the parameter we set to specify how many pairs of sin and cos terms to include.
- , m = seasonal period
e.g., if we set model(TSLM(Beer ~ trend() +
fourier(K = 2)
)) , then that means the model has 2 pairs of sin and cosWhat if only the first two Fourier terms are used ( and )?
The seasonal pattern will follow a simple sine wave.
A regression model containing Fourier terms is often called a harmonic regression because the successive Fourier terms represent harmonics of the first two Fourier terms.
Example1: Harmonic regression: beer production
recent_production %>% model( f1 = TSLM(Beer ~ trend() + fourier(K = 1)), f2 = TSLM(Beer ~ trend() + fourier(K = 2)), season = TSLM(Beer ~ trend() + season()) )
R interpretation
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F230f317d-b3a7-4cc7-b9bf-33f9255bf195%2FUntitled.png%3Ftable%3Dblock%26id%3Db67fc8b2-e04c-41d9-8f3a-c1ba6a68cad7%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DfT9izoprvh9Z0rr5sHHXZgYJBrHDSrciCFgJp6cHNos?table=block&id=b67fc8b2-e04c-41d9-8f3a-c1ba6a68cad7&cache=v2)
Example2: Harmonic regression: eating-out expenditure
![Looking at the cafe data, it shows a seasonality.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fa46fa5df-f165-4ef6-8a92-e1a7e23ebacd%2FUntitled.png%3Ftable%3Dblock%26id%3D18369341-79f9-4e38-b999-adac6e4ff699%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DM_Z8r65bRMsMMNYonsWe9kscIXHfeaQ0IYjWND9alMk?table=block&id=18369341-79f9-4e38-b999-adac6e4ff699&cache=v2)
R Code for Fourier term
fit <- aus_cafe %>% model( K1 = TSLM(log(Turnover) ~ trend() + fourier(K = 1)), K2 = TSLM(log(Turnover) ~ trend() + fourier(K = 2)), K3 = TSLM(log(Turnover) ~ trend() + fourier(K = 3)), K4 = TSLM(log(Turnover) ~ trend() + fourier(K = 4)), K5 = TSLM(log(Turnover) ~ trend() + fourier(K = 5)), K6 = TSLM(log(Turnover) ~ trend() + fourier(K = 6)) )
This is a yearly dataset, so , we can set k up to 6, having up to 6 pairs of cos and sin.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F1b0d8abb-2dfd-460d-bcbb-e4dcfad118db%2FWebp.net-gifmaker_(1).gif%3Ftable%3Dblock%26id%3D8dad486f-3613-4a9f-b0b4-e5418084f9a5%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DBaS03NTUPJ1Zu8h_CwwMZaBA1Ua2fAeOxh9XiGkuxno?table=block&id=8dad486f-3613-4a9f-b0b4-e5418084f9a5&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F3a95be0d-488d-45bd-9a7f-8c1015d0e7e4%2FUntitled.png%3Ftable%3Dblock%26id%3D14733447-a6fc-451d-9f88-5caaf32ddce7%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3Drah1omts5iUlTMEKf0cfKoey85pJ6vfGqGBfUuibXVA?table=block&id=14733447-a6fc-451d-9f88-5caaf32ddce7&cache=v2)
Interpretation of the plot
- When , it's only going to be 11 coefficients. This is because the sin and cos for the last coefficient is redundant. You've got the sine of pi times t is equal to 0.
- When , the seasonality is actually just a sine wave.
- When , it gets a smaller AICc, and my pattern is now starting to a bit more complicated by adding in one more harmonic.
- There is a tiny difference between and . The AICc of 6 is not as good as 5. So the best model is
Rule of thumb:
- As we add extra terms, the shape of the seasonality gets more complicated. It tries to match what's going on in the data so that's the genius of fourier terms!
- WE can model any type of periodic pattern by having enough terms
What is the benefit of Fourier term?
- To find quarterly data, we set , then we get 3 dummy variables.
- To find yearly data, we set , then we get 11 dummy variables.
- To find weekly data, we set , then we get 51 dummy variables.
We would not bother using quarterly data, as m is small. But when it comes to long periods of seasonality like
- monthly data, we can sometimes save one or two degrees of freedom.
- daily data, with an annual pattern, then , which is large. So, instead of having 364 coefficients, we might use 10, 12 or some small number of fourier terms.
- hourly data, we are modeling a time of day pattern, then , or we are modelling a half-hourly day pattern where , So, instead of having 23 or 47coefficients, we might use 3 or 8 fourier terms.
- weekly data, , because of the extra days after the end of the 52nd week. So, you can have a non-integer .
Can k be non-integer
Of course yes! For weekly data, , because of the extra days after the end of the 52nd week.
So, you can have a non-integer . All you're doing is computing things like 2 pi kt on m, you can do that when m is not an integer there's no problem and so you can handle non-integer seasonality.
Intervention variables
Example: ad expense to the sales
We regress sales on our usual variable ad expenditures and we created a dummy variable to capture whether the sales are taking place during the intervention or not.
We increased our ad expenditures during red framed period of time, for example start giving coupons.
Our dummy variable takes a value of 1 whenever the time period or sales are occurring in a period with our intervention.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F94721915-290c-4769-9aab-c1475a5ea1c3%2FUntitled.png%3Ftable%3Dblock%26id%3D39f09783-00e2-42f3-b625-f3b0b4cf6e00%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DWVg_NX_OLL9WxWqQJJgHnEuVAVYu_3EhvWYvMpIVKUg?table=block&id=39f09783-00e2-42f3-b625-f3b0b4cf6e00&cache=v2)
The value of show us the effect of that particular intervention on the sales value as compared with the the omitted category that is without the intervention
As this example goes, we can have 3 cases:
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F2f0f7531-20fc-49ed-a356-1039b714a73b%2FUntitled.png%3Ftable%3Dblock%26id%3D7c4e6be7-6912-4382-bfe0-6f79df2adfe9%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DeSXblWDKfZqKTo7YC4RZfWQ_Rc3yFmRpDSpJfevUi3g?table=block&id=7c4e6be7-6912-4382-bfe0-6f79df2adfe9&cache=v2)
Case 1: Spikes
We have the output variable against time.
- Our variable was having a slope of and then suddenly we intervene in the market in the mid-period where our ad expenditures went up. Suddenly, we saw that the value of the sales variable went up as well and then the increase in the ad expenditures last until our sales went back to our normal sales.
- When we say normal, here we assume
- The slope changes during the intervention with which the dummy variable = 1.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F69a17f5a-a9a0-4f86-bd81-c661f172aab5%2FUntitled.png%3Ftable%3Dblock%26id%3D4da7119f-b18a-4120-9efd-412814fbe8b2%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DIfmWvaqnAh3pxAzLNy_zz0hZcfGWo9rGhC-MbARj6Lc?table=block&id=4da7119f-b18a-4120-9efd-412814fbe8b2&cache=v2)
Case 2: Steps
Slicing our data into parts, we will denote the time period before the intervention by 0 and the period with the “permanent ” intervention denoted by 1.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F0073829b-d55f-4ca8-8d40-91861bc4ae7f%2FUntitled.png%3Ftable%3Dblock%26id%3Da4cd8281-7a1f-4c27-b6dc-0becbc69f869%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DfHrQ6EQrpMhUDmO6YBjlL_EKzgZ6-ynqBbszuWoJUHg?table=block&id=a4cd8281-7a1f-4c27-b6dc-0becbc69f869&cache=v2)
Case 3: Change of slope
By increasing our ad expenditures, our happens before the intervention
After the intervention is much steeper .
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F856d1078-a788-4d1a-8d51-8f1c2cec1ff8%2FUntitled.png%3Ftable%3Dblock%26id%3D1ca73fad-91a0-44ef-a729-1d29f0eddc8b%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DL4JySS3sHVPeVZzItqU7C9W5juKlKl8aoksKhFHrYjo?table=block&id=1ca73fad-91a0-44ef-a729-1d29f0eddc8b&cache=v2)
NOTE!
- Case 1 and case 2 are linear model, whereas case 3 is non-linear.
We can also make the dummy when variables there are 1) Outliers, 2) Holidays, 3) Trading days, and so on
Distributed lags
Say our and .
We don't necessarily expect when advertising goes up, sales go up straight away. It might take a little while before people actually make the sale, especially for expensive goods. So sometimes you'll want to put in lagged variable of how much did we ever spend on advertising last month and how's that affecting sales this month.
Nonlinear trend
Residual diagnostics
For forecasting purposes, we require the following assumptions:
We use 2 types of Residual plots to
- spot outliers.
- decide whether the linear model was appropriate.
- Scatterplot of residuals εt against each predictor xj,t
- the variance of the residuals may not be constant.
- the relationship is nonlinear
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fe540de3b-7773-43a7-a4b7-194c808b6fb3%2FUntitled.png%3Ftable%3Dblock%26id%3De91e76f4-0161-4bd0-9f19-d404b0ac61b6%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DKMHpm_qP06BuhdOXlDqyb90mnEcyzaYgahEcjTH18P4?table=block&id=e91e76f4-0161-4bd0-9f19-d404b0ac61b6&cache=v2)
If a pattern is observed, there may be “heteroscedasticity” in the errors. This means that
2. Scatterplot residuals against the fitted values yˆt
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F590ca031-80b1-48b2-b49b-540cd0c72861%2FUntitled.png%3Ftable%3Dblock%26id%3D7d946641-7bfb-46f5-9f34-6cede2ca6166%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DHkrPTl-EgBspE_nP1_I4YV4BWJ4F23wl535X6gpAOxY?table=block&id=7d946641-7bfb-46f5-9f34-6cede2ca6166&cache=v2)
If a plot of the residuals vs fitted values shows a pattern, then there is heteroscedasticity in the errors. (Could try a transformation.)
If this problem occurs, a transformation of the forecast variable such as a logarithm or square root may be required
Selecting predictors and forecast evaluation
Comparing regression models
We have AIC, , BIC, to compare the model.
R^2
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F2a631a41-c593-4b2e-9c9b-98e5de6d6932%2FUntitled.png%3Ftable%3Dblock%26id%3Dd7bd7a52-7c28-49d6-acc0-2b761f6f78b0%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DY78Gz7ySWU2RW3ECY8Z8WqGOpuUecJVO9R1VP7W6O_A?table=block&id=d7bd7a52-7c28-49d6-acc0-2b761f6f78b0&cache=v2)
It is not so useful because
- does not allow for “degrees of freedom’ ’.
- Adding any variable tends to increase the value of R^2, even if that variable is irrelevant.
ADJUSTED R^2
![Solution to this is to use ADJUSTED R^2](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fbb7218b9-52f9-4dd2-b07e-0614951882bf%2FUntitled.png%3Ftable%3Dblock%26id%3D6d77ace2-993f-46ac-ae76-cdb3272697b3%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DnVUfhX4NRkWllg0y60QCXlE8ulK2YRnBpcX52dn9h6Y?table=block&id=6d77ace2-993f-46ac-ae76-cdb3272697b3&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F738ea4dd-d1e1-4a78-8b73-3dbaa3aecbff%2FUntitled.png%3Ftable%3Dblock%26id%3Dbd6a2484-52a2-49de-8bc0-5a023b1cadaa%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DhqrG75RNyLq_UmYByn2H_Qt7azbaEO6RG6onZTgxqkY?table=block&id=bd6a2484-52a2-49de-8bc0-5a023b1cadaa&cache=v2)
Akaike’s Information Criterion (AIC)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ff8aeed30-c80c-42e1-9be9-c449147830ee%2FUntitled.png%3Ftable%3Dblock%26id%3D84965e35-aa7a-4d6e-a580-1448b1cd5cb9%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DPtBAnKcr5li9kUm-vEyCOheqUAj0u_AD_Aon290h5sA?table=block&id=84965e35-aa7a-4d6e-a580-1448b1cd5cb9&cache=v2)
where L is the likelihood and k is the number of predictors in the model.
- AIC penalizes terms more heavily than R^2.
- Minimizing the AIC is asymptotically equivalent to minimizing MSE via leave-one-out cross-validation (for any linear regression).
AIC has a caveat because when T (# obs) is too low, the AIC tends to select too many predictors.
Bayesian Information Criterion (SBIC / BIC / SC)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F315d563d-9561-4cd4-9f35-3ee19d45f281%2FUntitled.png%3Ftable%3Dblock%26id%3D57cde0ab-85e6-4ab6-ab45-8d575d569ea6%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DXSGHv4yQlbagW-Mobk8xRgyIP-0_J7i7b0AilVqj40s?table=block&id=57cde0ab-85e6-4ab6-ab45-8d575d569ea6&cache=v2)
where L is the likelihood and k is the number of predictors in the model.
BIC penalizes terms more heavily than AIC.
Minimizing BIC is asymptotically equivalent to leave-v-out cross-validation when v = T[1 − 1/(log(T) − 1)].
- We don’t use BIC because it's not optimizing any predictive property of the mode
To calculate MSE, we use CV too!
Cross-validation
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F66d2fb9a-e454-45ad-8288-ce7245f3cf50%2FUntitled.png%3Ftable%3Dblock%26id%3D6e1bb86b-c108-4e7b-84a8-59bcc868ee8e%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DE5XZTLL9D4Vde0_6c33Z1Bzi_nvYFjXtMzJB536kAE8?table=block&id=6e1bb86b-c108-4e7b-84a8-59bcc868ee8e&cache=v2)
Traditionally you've got training sets and test sets time series cross
validation is where you fit lots of training sets and you're predicting one step ahead.
Leave-one-out cross-validation
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F78c3bb09-3bed-498a-a8a0-d7ae3c1262ab%2FUntitled.png%3Ftable%3Dblock%26id%3D5d4af41e-8e05-4271-894a-6855f68aacb4%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3Dxfkc5Opc5g8FFQ2ZsKWOEON_e5wizlBied1co1uLdno?table=block&id=5d4af41e-8e05-4271-894a-6855f68aacb4&cache=v2)
We use all of the data, except for one on one points; we predict that one point.
Then, we use all of the data except for a different point to predict that point and so on.
So the test set is always one observation in the data, and we got t possible test sets, where t is the length of the data set.
What are the step of LOOCV?
- Remove observation t from the data set, and fit the model using the remaining data. Then compute the error (e∗t=yt−^yt) for the omitted observation. (This is not the same as the residual because the tth observation was not used in estimating the value of ^yt.)
t
et∗=yt−y^t
t
y^t
- Repeat step 1 for t=1,…,T.
t=1,…,T
- Compute the MSE from e∗1,…,e∗T. We shall call this the CV.
e1∗,…,eT∗
Choosing regression variables (Subset selection)
Best Subset Selection
Fit all possible regression models using one or more of the predictors.
The overall best model is chosen from the remaining models.
The best model is chosen through cross-validation or some other method that chooses the model with the lowest measure of test error. ETC3550, we use CV, AIC, AICc
In this final step, a model cannot be chosen based on R-squared, because R-squared always increases when more predictors are added. The model with the lowest K-Fold CV test errors is the best model.
It is computationally expensive and as the # of predictors increases, the combination grows exponentially.
- For example, 44 predictors leads to 18 trillion possible models!
Backward selection (or backward elimination),
Start with a model containing all variables.
Try subtracting one variable at a time.
Keep the model if it has lower CV or AICc. Iterate until no further improvement.
In another words, Starts with all predictors in the model (full model), iteratively removes the least contributive predictors and stops when you have a model where all predictors are statistically significant.
improvement is determined by metrics like RSS,CV or adjusted R square; ETC3550 uses CV or AICc.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fe0d76f5e-fb5c-414c-a876-402f67f31ab8%2F1_FrZouYQpASK0YJ1x81dNWw.png%3Ftable%3Dblock%26id%3D3df07fd4-fbab-4bad-95e5-d2e5076d895f%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DF53gyZa1iKrXtTybYE4MObt_5fgaBK6ejPvI8SUz7Ps?table=block&id=3df07fd4-fbab-4bad-95e5-d2e5076d895f&cache=v2)
Notes:
- Computational power is very similar to forwarding Selection.
- Stepwise regression is not guaranteed to lead to the best possible model.
- Inference on coefficients of final model will be wrong.
Forecasting with regression
When using regression models for time series data, we have the different types of forecasts that can be produced, depending on what is assumed to be known when the forecasts are computed.
A comparative evaluation of ex-ante forecasts and ex-post forecasts can help to separate out the sources of forecast uncertainty. This will show whether forecast errors have arisen due to poor forecasts of the predictor or due to a poor forecasting model.
Ex-ante forecasts
Those that are made using only the information that is available in advance.
- For example, ex-ante forecasts for the percentage change in US consumption for quarters following the end of the sample, should only use information that was available up to and including 2019 Q2.
- These are genuine forecasts, made in advance using whatever information is available at the time. Therefore in order to generate ex-ante forecasts, the model requires forecasts of the predictors.
Ex-post forecasts
Those that are made using later information on the predictors.
- For example, ex-post forecasts of consumption may use the actual observations of the predictors, once these have been observed.
- These are NOT genuine forecasts, but are useful for studying the behaviour of forecasting models.
- The model from which ex-post forecasts are produced should not be estimated using data from the forecast period.
- That is, ex-post forecasts can assume knowledge of the predictor variables (the xx variables), but should not assume knowledge of the data that are to be forecast (the yy variable).
Scenario based forecasting
- When we don’t know the information that is available in advance, we assumes possible scenarios for the predictor variables known in advance.
- For example, a US policy maker may be interested in comparing the predicted change in consumption when there is a constant growth of 1% and 0.5% respectively for income and savings with no change in the employment rate, versus a respective decline of 1% and 0.5%, for each of the four quarters following the end of the sample.
- Prediction intervals for scenario based forecasts do NOT include the uncertainty associated with the future values of the predictor variables.
- The resulting forecasts are calculated below and shown in Figure 7.18.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F979fee11-5c46-47ae-a555-ee61a39f4f0b%2FUntitled.png%3Ftable%3Dblock%26id%3D148ca00e-6346-49a6-86f1-2c9f1c5a31c8%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3D7Bo8sOoLWEJZzLOvaFhRUneKrZ88JbHE_5uWRTSyNI8?table=block&id=148ca00e-6346-49a6-86f1-2c9f1c5a31c8&cache=v2)
R code for Scenario based forecasting
#1. make future_scenarios future_scenarios <- scenarios( Increase = new_data(us_change, 4) %>% ## we set up 4 peroids ahead # assuming income increase 1%, Savings by .5%, Unemployment by 0%, Production by 0%) mutate(Income = 1, Savings = 0.5, Unemployment = 0, Production = 0), Decrease = new_data(us_change, 4) %>% mutate(Income = -1, Savings = -0.5, Unemployment = 0, Production = 0), names_to = "Scenario" ) #2. Make predictions fc <- forecast(fit_consBest, new_data = future_scenarios)
Building a predictive regression model
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F47024a54-2ca0-4740-b71e-2c59009182d1%2FUntitled.png%3Ftable%3Dblock%26id%3Dc306f365-cce9-4f73-aedb-8d06ff50c641%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725825600000%26signature%3DxTTTI_jnPhu1atmm24nGKYO0jAzxtGc4_T_LaClrRyg?table=block&id=c306f365-cce9-4f73-aedb-8d06ff50c641&cache=v2)
Correlation, causation and forecasting
Correlation is not causation
- When x is useful for predicting y, it is not necessarily causing y. e.g., predict number of drownings y using number of ice-creams sold x.
- Correlations are useful for forecasting, even when there is no causality.
- Better models usually involve causal relationships (e.g., temperature x and people z to predict drownings y)
Multicollinearity
It occurs when :
- Two predictors are highly correlated (i.e., the correlation between them is close to ±1).
- A linear combination of some of the predictors is highly correlated with another predictor.
- A linear combination of one subset of predictors is highly correlated with a linear combination of another subset of predictors
FAQ
Math
- Author:Jason Siu
- URL:https://jason-siu.com/fbbf5c5302c04a13a445c3cfb7eb7c5c
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts