-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUC.m
112 lines (110 loc) · 5.38 KB
/
UC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function m = UC(y,frequency,varargin)
% UC - Runs all relevant functions for UC modelling
%
% See help of UCsetup
%
% m = UC(y,frequency)
% m = UC(y,frequency,'optionalvar1',optvar1,...,'optionalvarN',optvarN)
%
% Inputs:
% y: a time series to forecast.
% frequency: fundamental period, number of observations per year.
% periods: (opt) vector of fundamental period and harmonics. If not entered as input,
% it will be calculated from frequency.
% u: (opt) a matrix of external regressors included only in the observation equation.
% If the output wanted to be forecast, matrix \code{u} should contain future values
% for inputs. Default: []
% model: (opt) the model to estimate. It is a single string indicating the
% type of model for each component. It allows two formats
% 'trend/seasonal/irregular' or 'trend/cycle/seasonal/irregular'. The
% possibilities available for each component are:
% - Trend: ? / none / rw / irw / llt / dt
% - Seasonal: ? / none / equal / different
% - Irregular: ? / none / arma(0,0) / arma(p,q) - with p and q
% integer positive orders
% - Cycles: ? / none / combination of positive or negative numbers.
% Positive numbers fix the period of the cycle while negative
% values estimate the period taking as initial condition the
% absolute value of the period supplied.
% Several cycles with positive or negative values are possible
% and if a question mark is included, the model test for the
% existence of the cycles specified (check the examples below).
% The following are valid cyckle models examples with different
% meanings: 48, 48?, -48, -48?, 48+60, -48+60, -48-60, 48-60,
% 48+60?, -48+60?, -48-60?, 48-60?.
% Default: '?/none/?/?'
% outlier: (opt) critical level of outlier tests. If NaN it does not
% carry out any outlier detection (default). A negative value
% indicates critical minimum t test for one run of outlier detection after
% identification. A positive value indicates the critical
% minimum t test for outlier detection in any model during identification.
% Default: NaN
% stepwise: (opt) stepwise identification procedure (true,false).
% Default: false.
% tTest: (opt) augmented Dickey Fuller test for unit roots (true/false).
% The number of models to search for is reduced, depending on the
% result of this test. Default: false
% p0: (opt) initial condition for parameter estimates. Default: NaN
% h: (opt) forecast horizon. If the model includes inputs h is not used,
% the length of u is used instead. Default: NaN
% criterion: (opt) information criterion for identification ('aic','bic' or
% 'aicc'). Default: 'aic'
% verbose: (opt) intermediate results shown about progress of estimation
% (true/false). Default: false.
% arma: (opt) check for arma models for irregular components (true/false).
% Default: true
%
% Output:
% An object of class UComp. It is a structure with fields including all
% the inputs and the fields listed below as outputs. All the
% functions in this package fill in part of the fields of any UComp
% object as specified in what follows (function UC fills in all of
% them at once):
% After running UCmodel or UCestim:
% p: Estimated parameters
% v: Estimated innovations (white noise correctly specified
% models)
% yFor: Forecasted values of output
% yForV: Variance of forecasted values of output
% criteria: Value of criteria for estimated model
% iter: Number of iterations in estimation
% grad: Gradient at estimated parameters
% covp: Covariance matrix of parameters
%
% After running UCvalidate:
% table: Estimation and validation table
% v: Estimated innovations (white noise correctly specified models)
%
% After running UCcomponents:
% comp: Estimated components in table form
% compV: Estimated components variance in table form
%
% After running UCfilter, UCsmooth or UCdisturb:
% yFit: Fitted values of output
% yFitV: Variance of fitted values of output
% a: State estimates
% P: Variance of state estimates
%
% After running UCdisturb:
% eta: State perturbations estimates
% eps: Observed perturbations estimates
%
% Authors: Diego J. Pedregal, Nerea Urbina
%
% Examples:
% load 'airpassengers' - contains 2 variables: y, frequency
% m = UC(log(y),frequency)
% m = UC(log(y),frequency,'model','llt/equal/arma(0,0)')
%
% See also UCsmooth, UCcomponents, UCdisturb, UCestim, UCfilter, UCmodel,
% UCsetup, UCvalidate
m = UCsetup(y,frequency,varargin{:});
m = UCestim(m);
if m.model == "error"
return;
end
m = UCvalidate(m, m.verbose);
m = UCsmooth(m);
m = UCdisturb(m);
m = UCcomponents(m);
end