Read daily data in R

r, time-series

Solution

For daily data with an annual seasonal pattern, use `frequency=365`. But if you want to model the weekly pattern, you will need `frequency=7`. If you sum every 7 observations to form weekly data, then you need `frequency=52`.

Of course, the real seasonal periods are not whole numbers, but most functions that use `ts` objects assume that the frequency is integer. You can handle these data more generally using the `msts` function from the `forecast` package. Then you could specify both weekly and annual seasonality for the daily data using

daily <- msts(consumption, seasonal.periods=c(7,365.25))

and annual seasonality for the weekly data using

weekly <- msts(wconsumption, seasonal=365.25/7)

where `wconsumption` contains the sum from each block of 7 consecutive observations.

Forecasts can be obtained using the `tbats` function:

fit <- tbats(daily)
fc <- forecast(tbats)

Problem

I am trying to forecast electricity consumption on daily basis based on historical data for each day from 1st january 2010 to 31st december 2011 i.e. I hve a total of 365*2 = 730 past data points. I am using `ts` to read the data. I am defining it as follows: ``` ts(consumption, start=1, frequency=365) ``` Is this correct? I am mainly doubtful over the "frequency" : should it be 365? Or should I use ``` ts(consumption, start=1,frequency=1) ``` For another approach, if I want to consolidate the data on weekly basis (by summing up every 7 observations) and then want to run forecast model, how should I read the data using `ts` ? What should be the value of `frequency`?

Original source