[R] time series has no or less than 2 periods

1,561 views
Skip to first unread message

Daniel Hickman

unread,
Oct 3, 2013, 11:32:26 AM10/3/13
to r-h...@r-project.org
Hello,



I have been tasked with taking an excel file that my colleague had implemented Triple Exponential Smoothing and recreate using R.

The following image shows the before and after of smoothing out a fixed interval time series data using Triple Exponential Smoothing inside of Excel.

enter image description here

I am trying to perform the same triple exponential smoothing in R. I created a csv file with the before smoothing data. The csv file is attached and can also be found here.

I found the HoltWinters method but I keep getting an error when I try to apply HoltWinters against the csv.
setwd("C:/temp")
data <- read.table("TripleExpSmoothingXLS.csv", header=TRUE, sep=",")
ts <- ts(data$QtyPerWeek, frequency=52)
HoltWinters(ts,0.46924,0.05,0.2)

This results in the following error. "Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods"

In case it helps, excel file with the triple exponential smoothing formulas and original data can be found here.

Any advice?

Thanks, Dan

David Winsemius

unread,
Oct 3, 2013, 3:39:01 PM10/3/13
to Daniel Hickman, r-h...@r-project.org

On Oct 3, 2013, at 8:32 AM, Daniel Hickman wrote:

> Hello,
>
>
>
> I have been tasked with taking an excel file that my colleague had implemented Triple Exponential Smoothing and recreate using R.
>
> The following image shows the before and after of smoothing out a fixed interval time series data using Triple Exponential Smoothing inside of Excel.
>
> enter image description here

The image file formats that I know are acceptable are .ps, .pdf or .png. Not sure about jpeg.

>
> I am trying to perform the same triple exponential smoothing in R. I created a csv file with the before smoothing data. The csv file is attached and can also be found here.

Need to send with .txt extension.

>
> I found the HoltWinters method but I keep getting an error when I try to apply HoltWinters against the csv.
> setwd("C:/temp")
> data <- read.table("TripleExpSmoothingXLS.csv", header=TRUE, sep=",")
> ts <- ts(data$QtyPerWeek, frequency=52)
> HoltWinters(ts,0.46924,0.05,0.2)
>
> This results in the following error. "Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) : time series has no or less than 2 periods"

Perhaps a data entry problem. We would need to see either the file or output of str(data).
>
> In case it helps, excel file with the triple exponential smoothing formulas and original data can be found here.

Again.... there is no here here.

>
> Any advice?
>
> Thanks, Dan______________________________________________
> R-h...@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

William Dunlap

unread,
Oct 3, 2013, 3:57:14 PM10/3/13
to David Winsemius, Daniel Hickman, r-h...@r-project.org
> > ts <- ts(data$QtyPerWeek, frequency=52)
> > HoltWinters(ts,0.46924,0.05,0.2)
> >
> > This results in the following error. "Error in decompose(ts(x[1L:wind], start = start(x),
> frequency = f), seasonal) : time series has no or less than 2 periods"

Since you have set the frequency of the time series to 52, you need
to have 104 observations to get the initial estimate of the seasonal
pattern. How many observations are in 'ts'? If you don't have enough
you can omit the seaonal component (HoltWinters(gamma=FALSE,...)),
change start.periods from the default 2 to 1, or supply a 52-long vector
of the initial seasonal pattern as the s.start argument.

If you do have more than 104 observations then you will have to tell
us more about the data.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
Message has been deleted

Rajaraman V

unread,
Jan 6, 2014, 12:42:46 PM1/6/14
to r-help-...@googlegroups.com, r-h...@r-project.org, daniel....@live.com
For decomposing a time series into seasonal components, you need at least 2
seasons worth of data. If you have even one data point less, you will see
this error message.

blockLength <- 52
ts1 <- ts(rnorm(2*blockLength-1), frequency=blockLength)
decompose(ts1) # error

ts2 <- ts(rnorm(2*blockLength), frequency=blockLength)
decompose(ts2) # OK
Reply all
Reply to author
Forward
0 new messages