SADC Course in Statistics Trends in time series (Session 02)
Mar 28, 2015
SADC Course in Statistics
Trends in time series
(Session 02)
2To put your footer here go to View > Header and Footer
Learning ObjectivesBy the end of this session, you will be able to
• explain the main components of a time series
• use graphical procedures to examine a time series for possible trends
• describe the trend in the series– using a moving average– by fitting a line to the trend
• use the trend to do simple forms of forecasting
3To put your footer here go to View > Header and Footer
General approach to analysis
Step 1: Plot the data with time on x-axis
Step 2: Study the pattern over time– Is there a trend? – Is there a seasonality effect? – Are there any long term cycles?– Are there any sharp changes in behaviour?– Can such changes be explained?– Are there any outliers, i.e. observations that
differ greatly from the general pattern
4To put your footer here go to View > Header and Footer
General approach to analysis
Step 3: State clearly your objectives for study of the time series
Step 4: Paying attention to the objectives, analyse the data, using descriptive analyses first, and moving later to other forms of analyses
Step 5: Write a report giving the key results and the main findings and conclusions
5To put your footer here go to View > Header and Footer
Main components of a time series
Trend: the general direction in which the series is running during a long period
Seasonal effects: Short-term fluctuations that occur regularly – often associated with months or quarters
Cyclical effects: Long-term fluctuations that occur regularly in the series
Residual: Whatever remains after the above have been taken into account, i.e. the unexplained (random) components of variation
6To put your footer here go to View > Header and Footer
Examining trends
Following slides include:
• Identifying if there appears to be a trend
• Describing and examining the trend using– Moving averages– Fitting a straight line to the data
• Simple approaches to forecasts, and likely dangers
Note: Cyclical effects will not be covered since theyare usually difficult to identify and need long series
7To put your footer here go to View > Header and Footer
An ExampleData below show the number of unemployed school leavers in the UK (in ‘000)Source: Employment Gazette
Year Jan-Mar Apr-Jun Jul-Sep Oct-Dec
1979 22 12 110 31
1980 21 26 150 70
1981 50 36 146 110
Graphing the data is needed, but first need to put data in list format
8To put your footer here go to View > Header and Footer
Putting the data in list formatYear Quarter Leavers
1 1979.00 22
1 1979.25 12
1 1979.50 110
1 1979.75 31
2 1980.00 21
2 1980.25 26
2 1980.50 150
2 1980.75 70
3 1981.00 50
3 1981.25 36
3 1981.50 146
3 1981.75 110
The decimals for the quarters are only intended to give a rough approximation of the time point
9To put your footer here go to View > Header and Footer
Clear seasonal and trend effects:
10To put your footer here go to View > Header and Footer
Estimating trend - moving average
We will ignore the seasonal pattern for now, and concentrate on estimating the trend…
• Purpose: to ‘smooth’ out the local variation and possibly seasonal effects
• Method: Replace each observation by a weighted average of observations around (and including) the particular observation.
• Results will depend on– number of observations used– weights used
11To put your footer here go to View > Header and Footer
An example
Suppose we have the series
Y1, Y2, ……….. , Yn
Then a moving average with weights1/8 , ¼ , ¼ , ¼ , 1/8
Would have the ith value equal to
Yi* = (1/8)Yi-2 + (¼)Yi-1 + (¼)Yi
+ (¼)Yi+1 + (1/8)Yi+2
12To put your footer here go to View > Header and Footer
Points to note…
• Weights should always add to 1.
• To find a moving average, need to decide what order to use, i.e. how many to average. For data in quarters, sensible to use order=4
• Where order=r, and r is odd, moving average (m.a.) values cannot be defined for the first (r-1)/2 and last (r-1)/2 obsns in the series
• If r is even, m.a. values will lie midway between times of observation - nicer to have it coinciding with the time points of observed data
13To put your footer here go to View > Header and Footer
Possible action when r is even If data are in quarters (say) could use a 4-point moving average first with equal weights,
i.e. ¼, ¼, ¼, ¼
Then use a further moving average of order 2 on the first computed moving average, again with equal weights, i.e. ½, ½
This is equivalent to using weights1/8 , ¼ , ¼ , ¼ , 1/8 on the original data
series! i.e. it is equivalent to a 5-point m.a. See next slide last column for an example…
14To put your footer here go to View > Header and Footer
Calculating the moving average
Year Quarter Leavers Three-point meanFive-point
moving average
1 1979.00 22
1 1979.25 12 48.00
1 1979.50 110 51.00 43.63
1 1979.75 31 54.00 45.25
2 1980.00 21 26.00 52.00
2 1980.25 26 65.7 61.88
2 1980.50 150 82.0 70.38
2 1980.75 70 90.0 75.25
3 1981.00 50 52.0 76.00
3 1981.25 36 77.3 80.50
3 1981.50 146 97.3
3 1981.75 110
Verify a few of the values in the last 2 columns…
15To put your footer here go to View > Header and Footer
Time Series & the fitted trend
0
40
80
120
160
1 2 3 4 5 6 7 8 9 10 11 12
Time (quarters)
Un
emp
loye
d S
cho
ol
Lea
vers
('0
00)
leavers maverage
The increasing trend is now clearly visible
16To put your footer here go to View > Header and Footer
Estimating trend – fitting a line
A second method for estimating trend is to find an equation giving the “best fit” to the trend.
The simplest is a straight line, i.e.
Y =a + bX
Here “a” is called an intercept and “b” is called the slope of the line.
Formulae for a and b, which minimise the squared distances of each data point from the line, are given on the final slide.
17To put your footer here go to View > Header and Footer
Interpreting the line
020406080100120140160
1979 1980 1981 1982
Time (Years)
Un
emp
loye
d S
cho
ol
Lea
vers
('0
00)
pq
a
The intercept “a” is shown on the graph.
The slope “b” is given by
b = p/q
18To put your footer here go to View > Header and Footer
Equation of the line
0
40
80
120
160
0 4 8 12
Time (quarters)
Un
em
plo
ye
d S
ch
oo
l Le
av
ers
('
00
0)
Equation of line is y = 19.4 + 7.07x
19To put your footer here go to View > Header and Footer
Forecasting – simple approach
Return to the equation of the line of “best fit” to the data, i.e.
y = 19.4 + 7.07x
For a future value of x, say at quarter 13, we may find y as
y = 19.4 + 7.07 (13) = 111.3
However, there are many dangers involved with doing this – and it is not advisable to do without recognising these
20To put your footer here go to View > Header and Footer
Some dangers in predictionsFitting a straight line as done here is part of a larger topic called “Regression Analysis” (contents of Module H8)
One basic assumption is that repeat observations taken in time are assumed to be independent. This is rarely the case.
Another is that the validity of the prediction becomes poorer as the value of x used (in the prediction) moves away from the time values used in finding the equation.
DO NOT MAKE FORECASTS without further knowledge of many statistical and other practical issues involved in doing so.
21To put your footer here go to View > Header and Footer
Practical work• Use data on temperature records, to find a
moving average, study its pattern, and write a short report of the results and conclusions
• Go through parts of Section 2 of
CAST for SADC : Higher Level
for improving your knowledge of the basic ideas of this session.
Details of both exercises are given in thehandout entitled “Estimating Trend in a TimeSeries” (Practical 02).
22To put your footer here go to View > Header and Footer
Calculations for “best fit” line
• Let the equation of line be: Y = a + b*i, where i refers to the time points, incrementing by 1.
• Then
• and
n(n+1)a Y - × b
2
2
( )i n i=n i n
i ii 1 i=1 i 1
i=n i n2
i=1 i 1
1 i Y - i ) ( Y
nb1
i - ( i)n
23To put your footer here go to View > Header and Footer
Some practical work follows…