Aggregating XTS by Week Commencing Sunday in R - datetime

I have a multivariate xts object containing daily time series for different marketing channels (about 4 years worth), and want to aggregate this into weekly data starting on Sunday.
I know I can use the following to get aggregate by weekly
sp_weekly_input <-apply.weekly(sp_xts, function(x){ c(ppc= sum(x$ppc_brand),
tv= sum(x$tv),
radio= sum(x$radio),
display= sum(x$display),
social= sum(x$social))})
But this will default to a Monday start, how can I override this and get a new multivariate xts for weekly channel spends starting on Sundays?

Related

Time Series & Forecast - Daily Data for 7.5 months

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.

Calculate rolling yearly differences in R with xts

I would like to calculate rolling yearly differences based on a daily time series in R with a xts object. However, I see currently two issues:
The number of trading days per year is not constant.
There could be holes in the time series, e.g. one year could be missing in-between.
Are there functions available in the library to take such rolling differences without constant lags (e.g. a lag of 260 days could be off by 10 days sometimes)? Or would the correct approach here to search for each date the same date one year before (minus one or two days to account for weekends)?

Loading time series data with weekly seasonality

I have a data set for couple of years for prices wherein the prices are very low over the weekends as compared to weekdays.I want to load this as time series object in R. What could be the best approach so that I can capture the weekly seasonality (weekends price dips) of the data.
Thanks!
Use the ts function with frequency=7.

weekly time series in r, arima

I have a data frame with the following column names.
"week" "demand" "product-id"
The problem is to convert it into a time series object.
week is a number like 3,4,5,6,7,8,9 etc., and demand is in units and product-id is unique.
I want to convert the week column into time series, so as to prepare for modeling.
I want to predict weeks 10 and 11 demand by using an ARIMA model. How do I do that?
myTS <- ts(mydataframe[-1], frequency = 52)
will convert your demand and productId to a timeseries of 52 observations per year. For more elaborate timeseries, check package xts. Also compare this post on weekly data with ts.

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