Season.nb
Author
Ekkehart Schlicht
Title
Season.nb
Description
This package implements Schlicht's (1984) seasonal adjustment method
Category
Academic Articles & Supplements
Keywords
seasonal adjustment method, non-parametric splines, HP-Filter, seasonal filter, orthogonal parametrization
URL
http://www.notebookarchive.org/2021-04-c068cgy/
DOI
https://notebookarchive.org/2021-04-c068cgy
Date Added
2021-04-26
Date Last Modified
2021-04-26
File Size
1.59 megabytes
Supplements
Rights
Redistribution rights reserved
Download
Open in Wolfram Cloud
The Season Package (by Ekkehart Schlicht)
The Season Package (by Ekkehart Schlicht)
Revision 4 of November 2020. Works with Mathematica 6 and up.
The package implements Schlicht's (1984) seasonal adjustment method. It decomposes a time series,t∈{1,...,T}into a trend ,t∈{1,...,T}, a seasonal component ,t∈{1,...,T}, and an irregular component ,t∈{1,...,T}such that =++forallt.The method uses non-parametric splines. It combines the trend filter proposed by Leser (1961), known as the HP-Filter filter, the seasonal filter proposed by Schlicht and Pauly (1983) and the orthogonal parametrization proposed by Schlicht (1984, 2005). For the treatment of missing observations and structural breaks, see Schlicht(2009). In contrast to prevailing methods, the method used here is based on an explicit statistical model (state-space).
Season is appropriate for smoothing time series with higher than annual frequency. Season is inappropriate for smoothing annual data or deseasonalized time series; for this, use the HPFilter package by Johannes Ludsteck.
This package provides the following functions for seasonal adjustment:
The package implements Schlicht's (1984) seasonal adjustment method. It decomposes a time series
x
t
y
t
z
t
u
t
x
t
y
t
z
t
u
t
Season is appropriate for smoothing time series with higher than annual frequency. Season is inappropriate for smoothing annual data or deseasonalized time series; for this, use the HPFilter package by Johannes Ludsteck.
This package provides the following functions for seasonal adjustment:
Season[x,s] splits the series x into trend, seasonal component, and irregular component, using estimated optimum smoothing parameters.
Season[x,s,α,γ] splits the series x into trend, seasonal component, and irregular component, using the smoothing parameters α and γ.
Both versions of Season[ ] return a list {{x,y,z,u},{α,γ},} where x is the input series, y is the trend, z is the seasonal component, u is the irregular component, α and γ are the smoothing parameters used and is the variance of the irregular component..
LL[x,s,α,γ] give the log likelihood of the constellation {x,s,α,γ}.
LLPlot[x,s, {, },{ , }] plots the log likelihood for the range {α,γ}∈[, ]×[, ].
Season[x,s,α,γ] splits the series x into trend, seasonal component, and irregular component, using the smoothing parameters α and γ.
Both versions of Season[ ] return a list {{x,y,z,u},{α,γ},
2
σ
2
σ
LL[x,s,α,γ] give the log likelihood of the constellation {x,s,α,γ}.
LLPlot[x,s, {
α
min
α
max
γ
min
γ
max
α
min
α
max
γ
min
γ
max
The method needs the time series x and the length of the season s as an input (e.g. s=4 for quarterly data or s=12 for monthly data). The function Season[x,s] computes smoothing parameters α and γ by a maximum likelihood method and splits the time series, using these weights. Alternatively, the parameters can be provided in Season[x,s,α,γ]. The parameter α controls the smoothness of the trend - the larger α, the smoother the trend. The parameter γ controls the rigidity of the seasonal pattern - the larger γ, the more time-invariant is the seasonal pattern. Both parameters interact: Increasing α while keeping γ constant will shift some variabilty from the trend to the seasonal component, for example (and the rest to the irregular component).
The method assumes that trend, season and irregular component are additive components of the time series. For some time series, such as trended time series, a multiplicative formulation is preferable. In this case, take the logarithms of the original data as the input.
Instructions: Place the package season6.m in $UserBaseDirectory\Applications\ (usuallyMathematica\ Applications\) and successively evaluate the cells.
To obtain information of the available functions, such as Season[], evaluate it with a question mark, like ?Season. The list of of functions in the package season6.m can be obtained by opening it oin Mathematica and click on “Functions”.
The method assumes that trend, season and irregular component are additive components of the time series. For some time series, such as trended time series, a multiplicative formulation is preferable. In this case, take the logarithms of the original data as the input.
Instructions: Place the package season6.m in $UserBaseDirectory\Applications\ (usually
C:\Users\<username>\AppData\Roaming\
To obtain information of the available functions, such as Season[], evaluate it with a question mark, like ?Season. The list of of functions in the package season6.m can be obtained by opening it oin Mathematica and click on “Functions”.
Initialization
Initialization
Content
Content
Here is a series with 358 elements - the time series of monthly German unemployment rates for 1991:01 through 2020:10.
In[]:=
x={7.4`,7.5`,7.1`,7,6.9`,6.8`,7.7`,7.7`,7.4`,7.4`,7.4`,7.8`,8.3`,8.2`,7.7`,7.6`,7.4`,7.3`,7.8`,7.7`,7.5`,7.6`,7.7`,8.1`,9,9,8.7`,8.6`,8.4`,8.5`,9.1`,9.1`,8.9`,9.1`,9.2`,9.6`,10.5`,10.5`,10.1`,9.9`,9.5`,9.3`,9.6`,9.4`,9.1`,8.9`,8.9`,9.2`,10,10,9.6`,9.4`,9,9,9.4`,9.3`,9.2`,9.2`,9.3`,9.9`,10.8`,11.1`,10.8`,10.4`,10,9.9`,10.2`,10.2`,10.1`,10.1`,10.3`,10.8`,12.2`,12.2`,11.7`,11.3`,11.1`,11,11.4`,11.4`,11.2`,11.2`,11.3`,11.8`,12.6`,12.6`,12.1`,11.4`,10.9`,10.5`,10.7`,10.6`,10.3`,10.1`,10.2`,10.9`,11.5`,11.6`,11.1`,10.7`,10.2`,10.1`,10.3`,10.3`,10.1`,9.9`,10,10.3`,11,10.9`,10.6`,9.8`,9.3`,9.1`,9.3`,9.3`,9,8.9`,8.9`,9.3`,10,10.1`,9.8`,9.5`,9,8.9`,9.2`,9.2`,9,9,9.2`,9.6`,10.4`,10.4`,10,9.7`,9.5`,9.5`,9.7`,9.6`,9.5`,9.4`,9.7`,10.1`,11.1`,11.3`,11.1`,10.8`,10.4`,10.2`,10.4`,10.4`,10.1`,10,10,10.4`,11,11.1`,10.9`,10.7`,10.3`,10.2`,10.5`,10.5`,10.3`,10.1`,10.3`,10.8`,12.3`,12.7`,12.7`,12.2`,11.8`,11.5`,11.7`,11.6`,11.2`,11,10.9`,11.1`,12.1`,12.2`,12,11.5`,10.9`,10.5`,10.5`,10.5`,10.1`,9.8`,9.6`,9.6`,10.2`,10.1`,9.8`,9.5`,9.1`,8.8`,8.8`,8.8`,8.4`,8.2`,8,8.1`,8.7`,8.6`,8.3`,8.1`,7.8`,7.5`,7.6`,7.6`,7.3`,7.1`,7.1`,7.4`,8.3`,8.5`,8.5`,8.5`,8.2`,8.1`,8.2`,8.2`,7.9`,7.7`,7.6`,7.8`,8.6`,8.6`,8.5`,8.1`,7.7`,7.5`,7.6`,7.6`,7.2`,7,6.9`,7.1`,7.9`,7.9`,7.6`,7.3`,7,6.9`,7,7,6.6`,6.5`,6.4`,6.6`,7.3`,7.4`,7.2`,7,6.7`,6.6`,6.8`,6.8`,6.5`,6.5`,6.5`,6.7`,7.4`,7.4`,7.3`,7.1`,6.8`,6.6`,6.8`,6.8`,6.6`,6.5`,6.5`,6.7`,7.3`,7.3`,7.1`,6.8`,6.6`,6.5`,6.6`,6.7`,6.5`,6.3`,6.3`,6.4`,7,6.9`,6.8`,6.5`,6.3`,6.2`,6.3`,6.4`,6.2`,6,6,6.1`,6.7`,6.6`,6.5`,6.3`,6,5.9`,6,6.1`,5.9`,5.8`,5.7`,5.8`,6.3`,6.3`,6,5.8`,5.6`,5.5`,5.6`,5.7`,5.5`,5.4`,5.3`,5.3`,5.8`,5.7`,5.5`,5.3`,5.1`,5,5.1`,5.2`,5,4.9`,4.8`,4.9`,5.3`,5.3`,5.1`,4.9`,4.9`,4.9`,5,5.1`,4.9`,4.8`,4.8`,4.9`,5.3`,5.3`,5.1`,5.8`,6.1`,6.2`,6.3`,6.4`,6.2`,6};startdate=DateList[{1991,1}][[1;;2]];
The following code calls the decomposition routine for monthly data with smoothing parameter values α=100 and γ=100 and returns the list {{x,y,z,u},{α,γ}}.
In[]:=
{{x,y,z,u},{α,γ},varU}=Season[x,12,100,100];
Here is a plot of the original time series x (red), the trend y (blue), and the seasonal component z (green).
In[]:=
DateListPlot[{x,y,z},startdate,JoinedTrue,PlotStyle{Red,Blue,Green}]
Out[]=
To view the effect of the choice of the smoothing parameters α and γ over the ranges (,) and (,)evaluate the following. It uses =10, =.1, =100, =10, =.1, =100.
α
min
α
max
γ
min
γ
max
α
init
α
min
α
max
γ
init
γ
min
γ
max
In[]:=
Manipulate[{{x,y,z,u},{α,γ},varU}=Season[x,12,α,γ];Show[DateListPlot[{x,y,z},startdate,JoinedTrue,PlotStyle{Red,Blue,Green}],Graphics[Text[Style["α = "<>ToString[α]<>" γ = "<>ToString[γ]<>"\nLogLikelihood = "<>ToString[LL[x,12,α,γ]],12,TextAlignmentLeft],{80,5.5}]]],{{α,10},.1,100},{{γ,10},.1,100},SaveDefinitionsTrue]
Out[]=
If Season is called without smoothing parameters, it computes the optimum smoothing parameters by a maximum-likelihood method and returns the list {{x,y,z,u},{α,γ},}.
2
σ
In[]:=
{{x,y,z,u},{α,γ},varU}=Season[x,12];
Here is a plot of the original time series x (red), the trend y (blue), and the seasonal component z (green). It can be seen that the smoothing parameters are estimated smaller than the parameters used in the previous example. In particular, the parameter α for the trend is estimated as being quite small, entailing a rougher trend.
In[]:=
DateListPlot[{x,y,z},startdate,JoinedTrue,PlotStyle{Red,Blue,Green}]Print["Smoothing parameters: α = ",α,", γ = ",γ];Print["Estimated variances: = ",varU,", = ",varUα,", = ",varUγ];
2
σ
u
2
σ
v
2
σ
w
Out[]=
Smoothing parameters: α = 0.183031, γ = 0.654727
Estimated variances: = 0.00109191, = 0.00596571, = 0.00166773
2
σ
u
2
σ
v
2
σ
w
The option SearchRange {{, }, {, }} permits to select a range over which Season searches for a solution, where α is restricted to the interval [, ] and γ is restricted to the interval [, ]. If a parameter is estimated close to the boundary of the relevant interval, a warning is issued.
The option may be used estimate one smoothing parameter while keeping the other fixed.
The standard option for the search range is: SearchRange {{0.1, 1000}, {0.1, 1000}}.
α
min
α
max
γ
min
γ
max
α
min
α
max
γ
min
γ
max
The option may be used estimate one smoothing parameter while keeping the other fixed.
The standard option for the search range is: SearchRange {{0.1, 1000}, {0.1, 1000}}.
Here is an example:
In[]:=
{{x,y,z,u},{α,γ},var}=Season[x,12,SearchRange{{1,10},{1,10}}];
::cornera
Season calls NMaximize to determine the optimum smoothing parameter. NMaximize options can be given to Season to cope with convergency problems and other issues. They are handed over to NMaximize. If NMaximize does not find a solution, a warning is issued.
Standard options for NMaximize in Season are: Method {"NelderMead", PostProcess False }. To speed up calculation, use AccuracyGoal 3.
Standard options for NMaximize in Season are: Method {"NelderMead", PostProcess False }. To speed up calculation, use AccuracyGoal 3.
Here is an example:
In[]:=
{{x,y,z,u},{α,γ},var}=Season[x,12,AccuracyGoal8,MaxIterations5];
::maxfail
Out[]=
$Aborted
The function LL[x,s,] returns the log likelihood of the constellation {x,s,}.
α,
γ
α,
γ
Here is an example:
In[]:=
LL[x,12,2,3]
Out[]=
1741.28
The function LLPlot[x,s,{, }, {, }] returns a plot of the log likelihood over the range {α,γ}∈[, ]×[, ].
LLPlot calls Plot3D and hands any options over to Plot3D. Be aware that the system matrix becomes near-singular for very large or very small values of the smoothing parameters, and that irregularities in these regions may be computational artifacts.
α
min
α
max
γ
min
γ
max
α
min
α
max
γ
min
γ
max
LLPlot calls Plot3D and hands any options over to Plot3D. Be aware that the system matrix becomes near-singular for very large or very small values of the smoothing parameters, and that irregularities in these regions may be computational artifacts.
Here is an example:
In[]:=
LLPlot[x,12,{0.1,0.3},{0.5,1.4},PlotPoints20]
Out[]=
References
Leser, C. E. V. (1961): 'A Simple Method of Trend Construction.' Journal of the Royal Statistical Society Series B (Methodological) Vol. 23, pp. 91-107.
(Online at https://www.jstor.org/stable/2983845).
Ludsteck, Johannes (2005) HPFilter, Mathematica package, Wolfram Library Archive Mathsource
(Online at http://library.wolfram.com/infocenter/Demos/5161/)
Schlicht, Ekkehart and Pauly, Ralf (1983): 'Descriptive Seasonal Adjustment by Minimizing Perturbations.' Empirica No. 1, pp. 15-28.
(Online at http://www.semverteilung.vwl.uni-muenchen.de/mitarbeiter/es/paper/schlicht-pauly-perturbations.pdf)
Schlicht, Ekkehart (1984): 'Seasonal Adjustment in a Stochastic Model.' Statistical Papers Vol. 25, pp. 1-12.
(Online at http://www.semverteilung.vwl.uni-muenchen.de/mitarbeiter/es/paper/schlicht_seasonal-adjustment-in-a-stochastic-model.pdf)
Schlicht, Ekkehart (2005): ‘ Estimating the Smoothing Parameter in the So-called Hodrick-Prescott Filter’, Journal of the Japan Statistical Society, 35(1), 2005, pp. 99-119.
(Online at http://www.scipress.org/journals/jjss/pdf/3501/35010099.pdf)
Schlicht, Ekkehart (2009): ‘Trend Extraction from Time Series With Missing Observations and Structural Breaks, Journal of the Japan Statistical Society 2009, 38(2), 285-92.
(Online at https://doi.org/10.14490/jjss.38.285)
Acknowledgement
I thank Johannes Ludsteck for helping me with expert advice in preparing this package.
Ekkehart Schlicht,
Department of Economics
University of Munich,
Germany
www.semverteilung.vwl.uni-muenchen.de/ekkehart
October 2005
revised July 2006, February 2017, November 2020.
Leser, C. E. V. (1961): 'A Simple Method of Trend Construction.' Journal of the Royal Statistical Society Series B (Methodological) Vol. 23, pp. 91-107.
(Online at https://www.jstor.org/stable/2983845).
Ludsteck, Johannes (2005) HPFilter, Mathematica package, Wolfram Library Archive Mathsource
(Online at http://library.wolfram.com/infocenter/Demos/5161/)
Schlicht, Ekkehart and Pauly, Ralf (1983): 'Descriptive Seasonal Adjustment by Minimizing Perturbations.' Empirica No. 1, pp. 15-28.
(Online at http://www.semverteilung.vwl.uni-muenchen.de/mitarbeiter/es/paper/schlicht-pauly-perturbations.pdf)
Schlicht, Ekkehart (1984): 'Seasonal Adjustment in a Stochastic Model.' Statistical Papers Vol. 25, pp. 1-12.
(Online at http://www.semverteilung.vwl.uni-muenchen.de/mitarbeiter/es/paper/schlicht_seasonal-adjustment-in-a-stochastic-model.pdf)
Schlicht, Ekkehart (2005): ‘ Estimating the Smoothing Parameter in the So-called Hodrick-Prescott Filter’, Journal of the Japan Statistical Society, 35(1), 2005, pp. 99-119.
(Online at http://www.scipress.org/journals/jjss/pdf/3501/35010099.pdf)
Schlicht, Ekkehart (2009): ‘Trend Extraction from Time Series With Missing Observations and Structural Breaks, Journal of the Japan Statistical Society 2009, 38(2), 285-92.
(Online at https://doi.org/10.14490/jjss.38.285)
Acknowledgement
I thank Johannes Ludsteck for helping me with expert advice in preparing this package.
Ekkehart Schlicht,
Department of Economics
University of Munich,
Germany
www.semverteilung.vwl.uni-muenchen.de/ekkehart
October 2005
revised July 2006, February 2017, November 2020.
Cite this as: Ekkehart Schlicht, "Season.nb" from the Notebook Archive (2021), https://notebookarchive.org/2021-04-c068cgy
Download