2
$\begingroup$

I have a large dataset consisting of 13, 513 temperature observations for a given city. I am trying to forecast the following month's daily temperatures (in other words, my goal is to forecast the following 30 observations). When removing seasonality, should I choose this based on a frequency of 365 days or 30 days?

Code:

## Setting Up Data
dta <- read.csv("data.csv", header = F)
values <- seq(from = as.Date("1993-01-01"), to = as.Date("2029-12-30"), by = 'day')
values <- format(values, format = "%m-%d")
dta$Date <- values
colnames(dta) <- c("Temp", "Date")

## Calculating Moving Averages
dta$cnt_ma <- ma(dta$Temp, order = 7)      # Weekly
dta$cnt_ma30 <- ma(dta$Temp, order = 30)   # Monthly
dta$cnt_ma365 <- ma(dta$Temp, order = 365) # Yearly

## Entering means for NA's
dta2 <- replace(dta, TRUE, lapply(dta, na.aggregate))

##### Removing Seasonality #####
count_ma <- ts(na.omit(dta2$Temp), frequency = 365)
decomp <- stl(count_ma, "periodic")
deseasonal_cnt <- seasadj(decomp)
plot(decomp)

## Test for Stationarity
adf.test(count_ma, alternative = "stationary")

Acf(count_ma, main = '')
Pacf(count_ma, main = '')

## Fitting Model via auto.arima
fit <- auto.arima(deseasonal_cnt, seasonal = F)
tsdisplay(residuals(fit), main = "(0,1,5) Model Residuals")

par(mfrow = c(1,1))
fcast <- forecast(fit, h = 30)
plot(fcast)

Here's the plot of the data after removing seasonality: enter image description here

Here's the plot of the data with the forecasted values: enter image description here

$\endgroup$
9
  • $\begingroup$ You're not really asking the correct frequency for time series data. You're really asking how much historical data is needed to predict future data. In other words, I would recommend you change your title to reflect what you're really asking. $\endgroup$ Commented Apr 22, 2020 at 22:37
  • $\begingroup$ Generally speaking, the more data you have, the better! You say you have $13513$ temperature observations for a given city. How many channels is that? How many time slices is that? $\endgroup$ Commented Apr 22, 2020 at 22:38
  • $\begingroup$ @AdrianKeister I am quite new at this forecasting material. I'm not 100% sure what you mean by "channels" or "time slices". My dataset is composed of daily observations of a city for roughly 37 years. I this what you're referring to? $\endgroup$
    – Student
    Commented Apr 22, 2020 at 22:46
  • $\begingroup$ Channels would refer to the number of different locations in the city at which you recorded temperatures. Time slices refers to the snapshots at which you have data. In your case, it looks like you have one channel over a very long period of time. To answer your question, I would just use a model that can incorporate seasonality. You have plenty of data to feed it! The yearly seasonality is going to be much more prominent than the monthly (if there even is any). $\endgroup$ Commented Apr 22, 2020 at 22:53
  • $\begingroup$ @AdrianKeister Oh in that case yes! You are correct! The data is collected in one city over 37 years. I have created a model that takes in yearly seasonality, but it seems that my forecasts are way off since I get a flat curve when I plot... $\endgroup$
    – Student
    Commented Apr 22, 2020 at 23:00

1 Answer 1

1
$\begingroup$

Having experiebce with hourly temperature data , I can suggest that your data most likely has two-seasons ...24 and 7 and probable monthly effects to deal with lunar effects AND of course possible anomalies/level shifts/time trends AND possible non-constant error variance..

Optimal Lag Selection Indicates Lag 98 dicusses hourly data . For other reads you might look at the some of following https://stats.stackexchange.com/search?tab=newest&q=user%3a3382%20hourly .

The while idea is to develop and use pseudo-predictor series i.e. latent deterministic structure possibly useful to predict hourly activity.

$\endgroup$

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.