I have a dataset from the German Weather Service, consisting of daily temperature measurements, which can be downloaded using the rdwd
-package.
I want to decompose this time series using the STL method.
I have previously converted the weather dataset into a tsibble
time-series object.
library(tidyverse)
library(rdwd)
library(seasonal)
library(tsibble)
df <-
readDWD(dataDWD(
selectDWD(
name = "Jena (Sternwarte)",
res = "daily",
var = "kl",
per = "historical"
),
read = FALSE
), varnames = TRUE)
df<-df%>%tibble()%>%
mutate(MESS_DATUM = as.Date(MESS_DATUM))%>%
filter(MESS_DATUM>=as.Date("2005-01-01"))%>%
rename(Temperatur = TMK.Lufttemperatur)
as_tsibble(df, index= MESS_DATUM)%>%
select(MESS_DATUM,Temperatur)%>%
stl(s.window = "periodic", robust = T)%>%
autoplot()
However, I don't really know if the dataset in its current format is suitable for STL decomposition or what parameters I need to set in the stl
function for this daily dataset.
The trend series should be rather a straighter line and seasonal component is totally distorted.
Can anyone help me with the programming?
Many thanks in advance!
CodePudding user response:
I don't speak tidyverse. Your issue looks like the periodicity of your time series is wrong.
df$MESS_DATUM <- as.Date(df$MESS_DATUM)
df <- df[df$MESS_DATUM >= as.Date("2005-01-01"),]
temps <- ts(df$TMK.Lufttemperatur, start = c(2005, 01), frequency = 365)
plot(stl(temps, s.window = "periodic"))
This ignores the existence of leap years (which I don't know how to deal with correctly).