0
$\begingroup$

I have a time series. Data points are available for each year from 1966 to 2000. Using R, I want to decompose this time series into trend, seasonal and random components. When I run the decompose command, I get the error "time series has no or less than 2 periods". Since my data is annual I have specified a frequency of 1. What am I doing wrong?

Here is the R code that I am using:

dat=c(37.2,37,37.4,37.5,37.7,37.7,37.4,37.2,37.3,37.2,36.9,36.7,36.7,36.5,
      36.3,35.9, 35.8,35.9,36,35.7,35.6, 35.2, 34.8, 35.3,35.6,35.6, 35.6,
      35.9,36,35.7, 35.7, 35.5, 35.6, 36.3, 36.5)

whts <- ts(dat, frequency = 1, start=1966, end=2000)  
is.ts(whts)  
plot.ts(whts)  
whtimeseriescomponents <- decompose(whts)  
$\endgroup$

1 Answer 1

2
$\begingroup$

Seasonal decomposition doesn't make sense in this situation. You're sampling frequency needs to be greater than 1 for this to work! I know this changes your model, but just for the sake of example:

> dat=c(37.2,37,37.4,37.5,37.7,37.7,37.4,37.2,37.3,37.2,36.9,36.7,36.7,36.5, 36.3,35.9, 35.8,35.9,36,35.7,35.6, 35.2, 34.8, 35.3,35.6,35.6, 35.6, 35.9,36,35.7, 35.7, 35.5, 35.6, 36.3, 36.5)
> whts <- ts(dat, frequency=2, start=1966, end=2000)
> decompose(whts)
$x
Time Series:
Start = c(1966, 1) 
End = c(2000, 1) 
Frequency = 2 
 [1] 37.2 37.0 37.4 37.5 37.7 37.7 37.4 37.2 37.3 37.2 36.9 36.7 36.7 36.5 36.3 35.9 35.8 35.9 36.0 35.7 35.6
[22] 35.2 34.8 35.3 35.6 35.6 35.6 35.9 36.0 35.7 35.7 35.5 35.6 36.3 36.5 37.2 37.0 37.4 37.5 37.7 37.7 37.4
[43] 37.2 37.3 37.2 36.9 36.7 36.7 36.5 36.3 35.9 35.8 35.9 36.0 35.7 35.6 35.2 34.8 35.3 35.6 35.6 35.6 35.9
[64] 36.0 35.7 35.7 35.5 35.6 36.3

$seasonal
Time Series:
Start = c(1966, 1) 
End = c(2000, 1) 
Frequency = 2 
 [1] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
 [9] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[17] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[25] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[33] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[41] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[49] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[57] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266  0.007141266
[65] -0.007141266  0.007141266 -0.007141266  0.007141266 -0.007141266

$trend
Time Series:
Start = c(1966, 1) 
End = c(2000, 1) 
Frequency = 2 
 [1]     NA 37.150 37.325 37.525 37.650 37.625 37.425 37.275 37.250 37.150 36.925 36.750 36.650 36.500 36.250
[16] 35.975 35.850 35.900 35.900 35.750 35.525 35.200 35.025 35.250 35.525 35.600 35.675 35.850 35.900 35.775
[31] 35.650 35.575 35.750 36.175 36.625 36.975 37.150 37.325 37.525 37.650 37.625 37.425 37.275 37.250 37.150
[46] 36.925 36.750 36.650 36.500 36.250 35.975 35.850 35.900 35.900 35.750 35.525 35.200 35.025 35.250 35.525
[61] 35.600 35.675 35.850 35.900 35.775 35.650 35.575 35.750     NA

$random
Time Series:
Start = c(1966, 1) 
End = c(2000, 1) 
Frequency = 2 
 [1]           NA -0.157141266  0.082141266 -0.032141266  0.057141266  0.067858734 -0.017858734 -0.082141266
 [9]  0.057141266  0.042858734 -0.017858734 -0.057141266  0.057141266 -0.007141266  0.057141266 -0.082141266
[17] -0.042858734 -0.007141266  0.107141266 -0.057141266  0.082141266 -0.007141266 -0.217858734  0.042858734
[25]  0.082141266 -0.007141266 -0.067858734  0.042858734  0.107141266 -0.082141266  0.057141266 -0.082141266
[33] -0.142858734  0.117858734 -0.117858734  0.217858734 -0.142858734  0.067858734 -0.017858734  0.042858734
[41]  0.082141266 -0.032141266 -0.067858734  0.042858734  0.057141266 -0.032141266 -0.042858734  0.042858734
[49]  0.007141266  0.042858734 -0.067858734 -0.057141266  0.007141266  0.092858734 -0.042858734  0.067858734
[57]  0.007141266 -0.232141266  0.057141266  0.067858734  0.007141266 -0.082141266  0.057141266  0.092858734
[65] -0.067858734  0.042858734 -0.067858734 -0.157141266           NA

$figure
[1] -0.007141266  0.007141266

$type
[1] "additive"

attr(,"class")
[1] "decomposed.ts"
$\endgroup$
1
  • $\begingroup$ What does the sampling freq of 2 mean in this case? How would you interpret the decomp? $\endgroup$
    – dca
    Commented Sep 19, 2020 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.