Time Series & Forecast - Daily Data for 7.5 months - r

I have daily sales data between 1/1/2017 and 10/15/2017. My first question is that I was trying to set the time series with the following command:
marketing = ts(df$Total_Sales_Spend, start=c(2017,1,1), frequency = 365)
However, when I try to decompose the TS, I am getting the following error:
time-series has no or less than 2 periods
I understand that it's because I don't have at least two years of data. So in this case what can I do?
Also, I'd like to forecast the daily sales numbers for the second half of October (16 days). How may I do that in this case? I wasn't able to set it up with zoo and arima.
Thank you.

Related

timeseries object frequency

Hi I'm new to timeseries so excuse I'm asking trivial questions, I have two questions:
I have hourly dataset (solar radiation) 7am - 7pm (12 hours for each day) what can I choose frequency for ts object?
I did this xts_2014.ts <- ts(xts_2014, frequency=12) but I think it recognize my data as monthly I know it's wrong but I don't know if 24 works when I don't have full 24 hours just daylight hours.
I have the raw data in black (which exhibits seasonal daily pattern and as far as I can tell yearly pattern), I tried moving average for removing noise of order 13 (hours) I don't know if I can proceed in trying to make data stationary?
plot

Create time series in R with data for week days only

I have a data set containing the energy usage by day (date) from 01 Jan 2016 through to 07 Nov 2017 on a daily basis. One of the fields therein is a flag for non working day (nwd) with values of 0 and 1 indicating whether or not this is a working day.
The structure of the data looks like this :-
Date,usage,avgtemp,nwd
2016-01-01,28.5,105986,1
2016-01-02,29.2,105548,1
.
.
.
2017-11-07,98457,23.5,0
I created a data frame with these values - no problems. I then created 2 other data frames, one with nwd = 1 and other with nwd = 1 for the data set for non working and working days respectively.
I am trying to generate a time series (using zoo or xts package - I am open to either) for each of these 2 data frames so that I can then do the non stationarity tests (adf/pp) on them and then do the arima modelling to build a forecast model of the usage.
Can I use a time series for such data sets where the data is not quite regular because each of these series will have gaps - the work day series may have less than 5 continuous days in a week if there are holidays in between. The same would apply to the non working day series.
I cannot summarize this at a weekly level as I need to forecast them at a daily level and possibly at the half hourly level subsequently. I might even want to do 'ardl' modelling later using 'avgtemp' as one of the regressors.
P.S.
Found a post which to some extent is similar to mine but I can't seem to get it going based on the responses there :-
how to convert data frame into time series in R

Check Seasonality in time series

I have 2 years of hourly data.I want to check seasonality .
1.Decomposing the series shows seasonality.But since Decomposition is not enough
what else can i use to check seasonality in R?
2.I tried hourly seasonality , I am not sure on the period of seasonality.How to determine the frequency in R?
Frequency is the number of observations per unit of time. But, in my short experience, the unit of time depends on the event you are studying. For example, if you have monthly data of a yearly seasonal event (like the flowering of some plants) and you sampled 5 times each month, frequency will be 5*12. I suggest you decompose your time series and and check for seasonality there. You can use ts, stl and plot.stl. Try to adjust the parameters as best as you can but also try to check what happens when you change them.
Please read through below link, if you feel to keep multiple seasonal periods in data, you can also paste sample of your data here for further suggestions
https://robjhyndman.com/hyndsight/seasonal-periods/

Decompose fails because time-series period is set incorrectly

I am trying to plot a decomposed time series, but running into an error:
Error in decompose(ts_ret) : time series has no or less than 2 periods`.
I am forcing the time series to a fixed period that is higher than 2.
Why does the ts think the period is less than 2?
Shouldn't the period be set automatically based on the time intervals in the data? (which are daily)
rm(list=ls())
library(jsonlite)
library(xts)
item.id<-18
eve.url<-paste0("http://eve-marketdata.com/api/item_history2.json?char_name=demo&region_ids=10000002&type_ids=",item.id,"&days=100")
eve.data<-data.frame(fromJSON(txt=eve.url))$emd.row
eve.data$date<-as.POSIXct(eve.data$date,format="%Y-%m-%d",tz="EST")
xxx<-xts(as.numeric(eve.data[,"avgPrice"]),eve.data$date)
colnames(xxx)<-"trit"
ts_ret<-ts(xxx,frequency=52) #but Im setting the periods here.....
plot(decompose(ts_ret))
As #ufelder pointed out my dataset was too small to look at seasonal decomposition because I only had a few months of data (measured hourly), but not an entire seasons worth (which is 4 months). To fix this I had to modify the period of the dataset to once per day by using ts(xxx,frequency=365) so decompose would compare across days, not seasons.

Time Series for Periods Over One Year

I'm having trouble doing time series for my data set. Most examples have quarterly or monthly frequencies but my issue comes with data that is collect annually or every two years. Consider my code:
data<-data.frame(year=seq(1978,2012,2), number=runif(18,100,500))
time<-ts(data$number, start=1978, frequency=.5)
decomp<-decompose(time)
Error in decompose(time) : time series has no or less than 2 periods
How do I make R recognize time series values from data that is collected over an annual basis? Thanks!
Seasonal decomposition only makes sense with intra-yearly data, because you have seasons within years. So, trying to calculate seasonal effects with decompose on data collected every two years you get the error.

Resources