filter
Filter disturbances through regression model with ARIMA errors
Description
uses additional
options specified by one or more name-value arguments. For example, Y
= filter(Mdl
,Z
,Name=Value
)filter(Mdl,Z,X=Pred,Z0=PresampleErrors)
specifies the predictor data Pred
for the model regression component
and the observed errors in the presample period PresampleErrors
to
initialize the model.
Examples
Compute Impulse Response Function
Compute the impulse response function of an innovation shock to the regression model with ARMA(2,1) errors.
The impulse response assesses the dynamic behavior of a system to a one-time shock. Typically, the magnitude of the shock is 1. Alternatively, it might be more meaningful to examine an impulse response of an innovation shock with a magnitude of one standard deviation.
In regression models with ARIMA errors,
The impulse response function is invariant to the behavior of the predictors and the intercept.
The impulse response of the model is defined as the impulse response of the unconditional disturbances as governed by the ARIMA error component.
Specify the following regression model with ARMA(2,1) errors:
where is Gaussian with variance 0.1.
Mdl = regARIMA(Intercept=0,AR={0.5 -0.8},MA=-0.5, ...
Variance=0.1);
When you construct an impulse response function for a regression model with ARIMA errors, you must set Intercept
to 0.
Simulate the first 30 responses of the impulse response function by generating a error series with a one-time impulse with magnitude equal to one standard deviation, and then filter it. Also, use impulse
to compute the impulse response function.
z = [sqrt(Mdl.Variance); zeros(29,1)]; % Shock of 1 std
yFltr = filter(Mdl,z);
yImpls = impulse(Mdl,30);
When you construct an impulse response function for a regression model with ARIMA errors containing a regression component, do not specify the predictor matrix, X
, in filter
.
Plot the impulse response functions.
figure subplot(2,1,1) stem((0:numel(yFltr)-1)',yFltr,"filled") title("Impulse Response to Shock of One Standard Deviation") subplot(2,1,2) stem((0:numel(yImpls)-1)',yImpls,"filled") title("Impulse Response to Unit Shock")
The impulse response function given a shock of one standard deviation is a scaled version of the impulse response returned by impulse
.
Simulate a Step Response
Simulate the step response function of a regression model with ARMA(2,1) errors.
The step response assesses the dynamic behavior of a system to a persistent shock. Typically, the magnitude of the shock is 1. Alternatively, it might be more meaningful to examine a step response of a persistent innovation shock with a magnitude of one standard deviation. This example plots the step response of a persistent innovations shock in a model without an intercept and predictor matrix for regression. However, note that filter
is flexible in that it accepts a persistent innovations or predictor shock that you construct using any magnitude, then filters it through the model.
Specify the following regression model with ARMA(2,1) errors:
where is Gaussian with variance 0.1.
Mdl = regARIMA(Intercept=0,AR={0.5 -0.8},MA=-0.5, ...
Variance=0.1);
Simulate the first 30 responses to a sequence of unit errors by generating an error series of one standard deviation, and then filtering it.
z = sqrt(Mdl.Variance)*ones(30,1); % Persistent shock of one std y = filter(Mdl,z); y = y/y(1); % Normalize relative to y(1)
Plot the step response function.
figure stem((0:numel(y)-1)',y,"filled") title("Step Response for Persistent Shock of One STD")
The step response settles around 0.4.
Filter Error Paths Through Regression Model with SARIMA Errors
Simulate 100 independent paths of responses by filtering 100 independent paths of errors , where innovations , through the following regression model with SARIMA errors.
where follows a -distribution with 15 degrees of freedom.
Distribution = struct("Name","t","DoF",15); Mdl = regARIMA(AR={0.2 0.1},SAR=0.01,SARLags=12, ... MA=0.5,SMA=0.02,SMALags=12,D=1,Seasonality=12, ... Beta=[1.5; -2],Intercept=0,Variance=0.1, ... Distribution=Distribution)
Mdl = regARIMA with properties: Description: "Regression with ARIMA(2,1,1) Error Model Seasonally Integrated with Seasonal AR(12) and MA(12) (t Distribution)" Distribution: Name = "t", DoF = 15 Intercept: 0 Beta: [1.5 -2] P: 27 D: 1 Q: 13 AR: {0.2 0.1} at lags [1 2] SAR: {0.01} at lag [12] MA: {0.5} at lag [1] SMA: {0.02} at lag [12] Seasonality: 12 Variance: 0.1
Simulate a length 25 path of data from the standard bivariate normal distribution for the predictor variables in the regression component.
rng(1) % For reproducibility
numObs = 25;
Pred = randn(numObs,2);
Simulate 100 independent paths of errors of length 25 from the standard normal distribution.
numPaths = 100; Z = randn(numObs,numPaths);
Simulate 100 independent response paths from model by filtering the paths of errors through the model. Supply the predictor data for the regression component.
Y = filter(Mdl,Z,X=Pred);
figure
plot(Y)
title('{\bf Simulated Response Paths}')
Plot the 2.5th, 50th (median), and 97.5th percentiles of the simulated response paths.
lower = prctile(Y,2.5,2); middle = median(Y,2); upper = prctile(Y,97.5,2); figure plot(1:25,lower,"r:",1:25,middle,"k", ... 1:25,upper,"r:") title("Monte Carlo Summary of Responses") legend("95% Interval","Median",Location="best")
Compare Responses from filter
and simulate
Simulate responses using filter
and simulate
. Then compare the simulated responses.
Both filter
and simulate
filter a series of errors to produce output responses y
, innovations e
, and unconditional disturbances u
. The difference is that simulate
generates errors from Mdl.Distribution
, whereas filter
accepts a random array of errors that you generate from any distribution.
Specify the following regression model with ARMA(2,1) errors:
where is Gaussian with variance 0.1.
Mdl = regARIMA(Intercept=0,AR={0.5 -0.8},MA=-0.5, ...
Beta=[0.1 -0.2],Variance=0.1);
Mdl
is a fully specified regARIMA
object.
Simulate a one path of bivariate standard normal data for the predictor variables. Then, simulate a path of responses and innovations from the regression model with ARMA(2,1) errors. Supply the simulated predictor data to simulate
for the regression component.
rng(1) % For reproducibility Pred = randn(100,2); % Simulate predictor data [ySim,eSim] = simulate(Mdl,100,X=Pred);
ySim
and eSIM
are 100-by-1 vectors of simulated responses and innovations, respectively, from the model Mdl
.
Produce model errors by standardizing the simulated innovations. Filter the simulated errors through the model. Supply the predictor data to filter
.
z1 = eSim./sqrt(Mdl.Variance); yFlt1 = filter(Mdl,z1,X=Pred);
yFlt1
is a 100-by-1 vector of reponses resulting from filtering the simulated errors z1
through the model Mdl
.
Confirm that the simulated responses from simulate
and filter
are identical by plotting the two series.
figure h1 = plot(ySim); hold on h2 = plot(yFlt1,"."); title("Filtered and Simulated Responses") legend([h1 h2],["Simulate" "Filter"],Location="best") hold off
Alternatively, simulate responses by randomly generating your own errors and passing them into filter
.
rng(1) Pred = randn(100,2); z2 = randn(100,1); yFlt2 = filter(Mdl,z2,X=Pred); figure h1 = plot(ySim); hold on h2 = plot(yFlt2,"."); title("Filtered and Simulated Responses") legend([h1 h2],["Simulate" "Filter"],Location="best") hold off
This plot is the same as the previous plot, confirming that both simulation methods are equivalent.
filter
multiplies the error, Z
, by sqrt(Mdl.Variance)
before filtering Z
through the model. Therefore, if you want to specify a different distribution, set Mdl.Variance
to 1, and then generate your own errors using, for example, random("unif",a,b)
for the Uniform(a, b) distribution.
Input Arguments
Z
— Error series zt that drives the
innovations process εt
numeric column vector | numeric matrix
Error series zt that drives the
innovations process εt, specified as a length
numObs
numeric column vector or a
numObs
-by-numPaths
numeric matrix.
numObs
is the length of the time series (sample size).
numPaths
is the number of separate, independent disturbance paths.
The innovations process εt =
σzt, where σ =
sqrt(Mdl.Variance)
, the standard deviation of the
innovations.
Each row corresponds to a period. The last row contains the latest set of errors.
Each column corresponds to a separate, independent path of errors.
filter
assumes that errors across any row occur
simultaneously.
Z
is the continuation of the presample errors
Z0
.
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: filter(Mdl,Z,X=Pred,Z0=PresampleErrors)
specifies the
predictor data Pred
for the model regression component and the observed
errors in the presample period PresampleErrors
to initialize the
model.
X
— Predictor data
numeric matrix
Predictor data for the model regression component, specified as a
numObs
-by-numPreds
numeric matrix.
numPreds
is the number of predictor variables
(numel(Mdl.Beta)
).
Each row of X
corresponds to the corresponding period in
Z
(period for which filter
filters
errors; the period after the presample). The following conditions apply:
The last row contains the latest predictor data.
If
X
has more thennumObs
rows,filter
uses only the latestnumObs
rows.filter
does not apply the regression component during the presample period.
Columns of X
are separate predictor variables.
filter
applies X
to each filtered
path; that is, X
represents one path of observed predictors.
By default, filter
excludes the regression component,
regardless of its presence in Mdl
.
Data Types: double
Z0
— Presample error data
numeric column vector | numeric matrix
Presample error data providing initial values for the input error series
Z
, specified as a numeric column vector or a numeric
matrix.
Each row of Z0
corresponds to a period in the presample. The
following conditions apply:
The last row contains the latest presample errors.
To initialize the compound moving average (MA) component of the ARIMA error model,
Z0
must have at leastMdl.Q
rows.If
Z0
has more rows than is required to initialize the model,filter
uses only the latest required rows.
Columns of Z0
are separate, independent presample paths. The
following conditions apply:
If
Z0
is a column vector,filter
applies it to each path.If
Z0
is a matrix,filter
appliesZ0(:,
to initialize pathj
)j
.Z0
must have at leastnumPaths
columns;filter
uses only the firstnumPaths
columns ofU0
.
By default, filter
sets the necessary presample errors
to 0.
Data Types: double
U0
— Presample unconditional disturbances
numeric column vector | numeric matrix
Presample unconditional disturbances that provide initial values for the ARIMA error model, specified as a column vector or matrix.
Each row of U0
corresponds to a period in the presample. The
following conditions apply:
The last row contains the latest presample unconditional disturbances.
To initialize the compound autoregressive (AR) component of the ARIMA error model,
U0
must have at leastMdl.P
rows.If
U0
has more rows than is required to initialize the model,filter
uses only the latest required rows.
Columns of U0
are separate, independent presample paths. The
following conditions apply:
If
U0
is a column vector,filter
applies it to each path.If
U0
is a matrix,filter
appliesU0(:,
to initialize pathj
)j
.U0
must have at leastnumPaths
columns;filter
uses only the firstnumPaths
columns ofU0
.
By default, filter
sets the necessary presample
unconditional disturbances to 0.
Data Types: double
Note
NaN
s in input data indicate missing values.filter
uses listwise deletion to delete all sampled times (rows) in the input data containing at least one missing value. Specifically,filter
performs these steps:Synchronize, or merge, the presample data sets
Z0
andU0
to create the setPresample
, in other words,Presample
=[Z0 U0]
.Synchronize the filter data
Z
andX
to create the setData
, in other words,Data
=[Z X]
.Remove all rows from
Presample
andData
containing at least oneNaN
.
Listwise deletion applied to the filter data can reduce the sample size and create irregular time series.
filter
merges data sets that have a different number of rows according to the latest observation, and then pads the shorter series with enough default values to form proper matrices.filter
assumes that you synchronize the data sets so that the latest observations occur simultaneously. The software also assumes that you synchronize the presample series similarly.All predictor variables (columns) in
X
are associated with each error series inZ
to producenumPaths
response seriesY
.
Output Arguments
Y
— Simulated response paths yt
numeric column vector | numeric matrix
Simulated response paths yt, returned as a
length numObs
column vector or a
numObs
-by-numPaths
numeric matrix.
For each
= 1, …,
t
numObs
, the simulated responses at time
t
Y(
correspond to the filtered errors
at time t
,:)t
Z(
and response path
t
,:)j
Y(:,
corresponds to the filtered
disturbance path j
)j
Z(:,
when j
)Z
is a
matrix.
Y
represents the continuation of presample inputs.
E
— Simulated, mean-zero innovations paths εt
numeric column vector | numeric matrix
Simulated, mean-zero innovations paths εt
of the model unconditional disturbances ut,
returned as a length numObs
column vector or a
numObs
-by-numPaths
numeric matrix.
The dimensions of Y
and E
correspond.
Columns of E
are scaled disturbance paths (innovations) such
that, for a particular path, εt =
σzt.
U
— Simulated unconditional disturbance paths ut
numeric column vector | numeric matrix
Simulated unconditional disturbance paths
ut, returned as a length
numObs
column vector or a
numObs
-by-numPaths
numeric matrix.
The dimensions of Y
and U
correspond.
Alternative Functionality
filter
generalizes simulate
. Both filter a series of errors to produce responses
Y
, innovations E
, and unconditional disturbances
U
. However, simulate
autogenerates
a series of mean zero, unit variance, independent and identically distributed (iid) errors
according to the distribution in Mdl
. In contrast,
filter
requires that you specify your own errors, which can come
from any distribution.
References
[1] Box, G. E. P., G. M. Jenkins, and G. C. Reinsel. Time Series Analysis: Forecasting and Control. 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1994.
[2] Davidson, R., and J. G. MacKinnon. Econometric Theory and Methods. Oxford, UK: Oxford University Press, 2004.
[3] Enders, Walter. Applied Econometric Time Series. Hoboken, NJ: John Wiley & Sons, Inc., 1995.
[4] Hamilton, James D. Time Series Analysis. Princeton, NJ: Princeton University Press, 1994.
[5] Pankratz, A. Forecasting with Dynamic Regression Models. John Wiley & Sons, Inc., 1991.
[6] Tsay, R. S. Analysis of Financial Time Series. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 2005.
Version History
Introduced in R2013b
See Also
Objects
Functions
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)