0

I want to know how to make 'seasonal' in stl function.

I guess 'trend' is diff time series. and how to make seasonal??

in R 'stl' description is

which.cycle <- cycle(x)
z$seasonal <- tapply(z$seasonal, which.cycle, mean)[which.cycle]

and R documentation

fdrfourier  Calculation of the false discovery rates (FDR) for periodic expression
backgroundData  Generation of background expression set
ar1analysis     Performs AR1 fitting
fourierscore    Calculation of the Fourier score

AR and Fourier transform ??

h-y-jp
  • 199
  • 1
  • 8
  • 1
    Where do you use `stl`, could you please share more code? I wrote a detailed description of the STL algorithm in this paper: https://www.hydrol-earth-syst-sci.net/24/115/2020/hess-24-115-2020.html (section 3.2). You also have link to the git of the source code in the paper, where I use STL. If you specify more your question, and give us some data (see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) I can help you – Chelmy88 Jan 30 '20 at 10:11

1 Answers1

1

A time series cannot be made seasonal, strictly speaking. I suspect you mean extracting the seasonality pattern using the stl() function in R.

Let's consider an example of a time series measuring the maximum recorded air temperature in Dublin, Ireland from 1941 to 2019.

Here is a graph of the original time series:

weatherarima <- ts(mydata$maxtp, start = c(1941,11), frequency = 12)
plot(weatherarima,type="l",ylab="Temperature in Celsius")
title("Maximum Air Temperature - Dublin")

maximum air temperature

The seasonal, trend, and random components can be extracted with stl() as follows:

stl_weather = stl(weatherarima, "periodic")
seasonal_stl_weather   <- stl_weather$time.series[,1]
trend_stl_weather     <- stl_weather$time.series[,2]
random_stl_weather  <- stl_weather$time.series[,3]

plot(as.ts(seasonal_stl_weather))
title("Seasonal")
plot(trend_stl_weather)
title("Trend")
plot(random_stl_weather)
title("Random")

Seasonal

seasonal

Trend

trend

Random

random

As can be observed, there is clear seasonality in the weather data - given the change in temperature across seasons - but this was merely extracted from the series by using stl() - not created as such.

You might find the following to be informative: Extracting Seasonality and Trend from Data: Decomposition Using R

Michael Grogan
  • 973
  • 5
  • 10