Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
vuoi
o PayPal
tutte le volte che vuoi
MAPE
This observation led to the use of the so-called “symmetric” (sMAPE) proposed by Armstrong
which was used in the M3 forecasting competition. It is defined by
However, if is close to zero, is also likely to be
close to zero. Thus, the measure still involves
division by a number close to zero, making the calculation unstable. Also, the value of sMAPE can be
negative, so it is not really a measure of “absolute percentage errors” at all.
Hyndman & Koehler recommend that the sMAPE not be used. It is included here only because it is widely
used, although we will not use it in this book.
Examples
accuracy() function
The will automatically extract the relevant periods from the data (recent_production in
this example) to match the forecasts when computing the various accuracy measures.
It is obvious from the graph that the seasonal naïve method is best for these data, although it can still be
improved, as we will discover later. Sometimes, different accuracy measures will lead to different results as
to which forecast method is best. However, in this case, all of the results point to the seasonal naïve method
as the best of these four methods for this data set.
To take a non-seasonal example, consider the Google stock price. The following graph shows the closing
stock prices from 2015, along with forecasts for January 2016 obtained from three different methods.
Already by watching at the plot we see
that the Naïve approach is the best-
working one
Actually, in this case neither naïve nor
we have to find
drift are really accurate
a matehood that gives us some more
objective approximation
5.10 Time series cross-validation
series of test sets, each consisting of a single observation.
In this procedure, there are a
The corresponding training set consists only of observations that occurred prior to the observation that forms
no future observations can be used in constructing the forecast.
the test set. Thus,
Since it is not possible to obtain a reliable forecast based on a small training set, the earliest observations are
not considered as test sets.
The diagram illustrates the series of
training and test sets, where the blue
observations form the training sets,
and the orange observations form
the test sets.
The forecast accuracy is computed by averaging over the test sets. This procedure is sometimes known as
on a rolling forecasting origin”
“evaluation because the “origin” at which the forecast is based rolls forward
in time.
Much more stable than the training-test set procedure multi-step forecasts.
With time series forecasting, one-step forecasts may not be as relevant as
In this case, the cross-validation procedure based on a rolling forecasting origin can be modified to allow
multi-step errors to be used.
Suppose that we are interested in
models that produce good 4-
step-ahead forecasts. Then the
corresponding diagram is
shown.
In the following example, we compare the accuracy obtained via time series cross-validation with the residual
stretch_tsibble() create many training sets.
accuracy. The function is used to .init=3
In this example, we start with a training set of length (observations and increase
in the first training set),
.step=1
the size of successive training sets by (how many observations for any new training set).
The .id column provides a new key indicating the various training sets. The accuracy() function can be used
to evaluate the forecast accuracy across the training sets.
As expected, the accuracy measures from the residuals are smaller, as the corresponding “forecasts” are based
on a model fitted to the entire data set, rather than being true forecasts.
A good way to choose the best forecasting model is to find the model with the smallest RMSE computed using
time series cross-validation.
Example
The code below evaluates the forecasting performance of 1- to 8-step-ahead drift forecasts. The plot shows
that the forecast error increases as the forecast horizon increases, as we would expect.
Accuracy is weaker when you
increase the time-horizon.
If two methods have similar accuracy it means there are both okay, you can compute both or try to find
additional information.
7. Time series regression model
We forecast the time series of interest assuming that it has a linear relationship with other time series
.
For example, we might wish to forecast monthly sales using total advertising spend (x) as a predictor. Or
()
we might forecast daily electricity demand () using temperature (x ) and the day of week (x ) as predictors
1 2
(or explanatory variable).
forecast variable regressand,
The is sometimes also called the dependent or explained variable.
predictor variables regressors,
The are sometimes also called the independent or explanatory variables.
7.1. Linear model
Simple linear regression
In the simplest case, the regression model allows for a linear relationship between the forecast variable y and
single predictor variable x: = + +
→ ℎ , ℎ ℎ 1
The slope coefficient tells us how strong is the
= = ℎ = 0
relationship between the two variables
Notice that the observations do not lie on the straight line but are scattered around it. The “error” term does
not imply a mistake, but a deviation from the underlying straight-line model. It captures anything that may
affect y other than x .
t t
Example US consumption expenditure
Geom_smooth(): generic command that allows to add a line/curve to approx. regression from the plot it looks
there is a relation where the relationship is an increasing one not great fitting into the linear regression, but
the relationship is increasing, so it makes sense to add a straight line with positive inclination.
TSLM()
The equation is estimated using the function:
The fitted line has a positive slope (0.27), reflecting the positive relationship between income and consumption.
In this case when x=0 the predicted value of y is 0.54
Multiple linear regression
two or more predictor variables,
When there are the model is called a multiple regression model. The general
form of a multiple regression model is
= + + +⋯+
Each of the predictor variables must be numerical.
Here the coefficients measure the marginal effects of the predictor variables.
Example US consumption expenditure Different from the book’s one
These plots show additional predictors that may be useful for forecasting US consumption expenditure. These
are quarterly percentage changes in industrial production and personal savings, and quarterly changes in the
unemployment rate (as this is already a percentage). Building a multiple linear regression model can
potentially generate more accurate forecasts as we expect consumption expenditure to not only depend on
personal income but on other predictors as well. In the scatterplot matrix of five
variables. The first column shows
the relationships between the
forecast variable (consumption)
and each of the predictors. The
scatterplots show positive
relationships with income and
industrial production, and
negative relationships with
savings and unemployment. The
strength of these relationships is
shown by the correlation
coefficients across the first row.
The remaining scatterplots and
correlation coefficients show the
relationships between the
predictors.
Assumptions
When we use a linear regression model, we are implicitly making some assumptions about the variables in the
equation = + + + ⋯ +
First, we assume that the model is a reasonable approximation to reality; that is, the relationship between the
forecast variable and the predictor variables satisfies this linear equation.
errors
Second, we make the following assumptions about the ( , … , ).
They have mean zero; otherwise, the forecasts will be systematically biased.
they are not autocorrelated; otherwise, the forecasts will be inefficient, as there is more information in the
data that can be exploited.
they are unrelated to the predictor variables; otherwise, there would be more information that should be
included in the systematic part of the model.
normally distributed constant variance
It is also useful to have the errors being with a in order to easily
produce prediction intervals. linear regression model is that each predictor x is not a random
Another important assumption in the
variable.
If we were performing a controlled experiment in a laboratory, we could control the values of each x (so they
would not be random) and observe the resulting values of y. With observational data (including most data in
business and economics), it is not possible to control the value of x, we simply observe it.
7.2. Least squares estimation
In practice, of course, we have a collection of observations but we do not know the values of the coefficients
. These need to be estimated from the data.
, , … ,
The least squares principle provides a way of choosing the coefficients effectively by minimizing the sum of
the squared errors. That is, we choose the values of that minimize:
, , … ,
This is called least squares estimation because it gives the least value for the sum of squared errors. Finding
the best estimates of the coefficients is often called “fitting” the model to the data, or sometimes “learning”
or “training” the model.
TSLM() function
The fits a linear regression model to time series data.
lm() function
It is similar to the which is widely used for linear models, but TSLM() provides additional
facilities for handling time series.
Example US consumption expenditure
A multiple linear regression model for US consumption is
= + + + + +
, , , ,
Where is the percentage change in real personal consumption expenditure, is the percentage change in
real personal disposable income, is the percentage change in industrial production, is the percentage
change in personal savings and is the change in the unemployment rate.
The following output provides information about the fitted model. The first column of Coefficients gives an
estimate of each coefficient () and the second column gives its standard error.
to have summary of the significant information,
the most important column is "estima