R - Putting time series with frequency of 20 min into the function stl()
r, stl, time-series
Solution
The error message tells you that in order to estimate a seasonal component of your time series, you need data for at least two seasons. If you have 4 days worth of temperature data, you probably want to have the seasonal component to be in days. Therefore you should set-up your time-series accordingly. You have 24*3 observations a day, so that should be the frequency.
timeseries[[1]] <- ts(stations[[1]]$Temp, frequency=24*3)
Then `stl(timeseries[[1]], "periodic")` should work, altough I cannot test it, since it requires data for at least 2 days, i.e. 2 hours isn't enough.
Problem
I am trying to use the function stl() in R to smooth a data set that stores time vs. temperature from a sensor. The main goal is to remove noise from the function, in order to find the ambient temperature (baseline curve). I have loaded my data in time series format, and when I tried to use stl(), it gave me this error: ``` Error in stl(timeseries[[1]]) : series is not periodic or has less than two periods ``` here is my data: ``` > head(stations[[1]]) Date Unit Temp 1 0013-06-30 10:00:01 C 32.5 2 0013-06-30 10:20:01 C 32.5 3 0013-06-30 10:40:01 C 33.5 4 0013-06-30 11:00:01 C 34.5 5 0013-06-30 11:20:01 C 37.0 6 0013-06-30 11:40:01 C 35.5 ``` which i have converted to time series class: ``` timeseries[[1]] = as.ts(stations[[1]]$Temp,freq=26280) ``` note : frequency is high as data is taken every 20 minutes Is the error with stl() due to a disagreement of the frequency? I have a feeling that I may have done something wrong when making my data a time series and that this has thrown off the ability to calculate the period of the series I do need all this data, as the entire set only covers 4 days worth of data (hence the high frequency) Thank you for your help!