add.monthly.annual.cycle  R Documentation 
A seasonal state component for daily data, representing the contribution of each month to the annual seasonal cycle. I.e. this is the "January, February, March, ..." effect, with 12 seasons. There is a step change at the start of each month, and then the contribution of that month is constant over the course of the month.
Note that if you have anything other than daily data, then you're
probably looking for AddSeasonal
instead.
The state of this model is an 11vector gamma[t, ] where the first element is the contribution to the mean for the current month, and the remaining elements are the values for the 10 most recent months. When t is the first day in the month then
gamma[t+1, 1] = 1 * sum(gamma[t, 1]) + rnorm(1, 0, sigma)
And the remaining elements are gamma[t, ] shifted down one. When t is any other day then gamma[t+1, ] == gamma[t, ].
AddMonthlyAnnualCycle(state.specification, y, date.of.first.observation = NULL, sigma.prior = NULL, initial.state.prior = NULL, sdy)
state.specification 
A list of state components, to which the monthly annual cycle will be added. If omitted, an empty list will be assumed. 
y 
The time series to be modeled, as a numeric vector. 
date.of.first.observation 
The time stamp of the first
observation in 
sigma.prior 
An object created by 
initial.state.prior 
An object created using

sdy 
The standard deviation of the series to be modeled. This
will be ignored if 
## Let's simulate some fake daily data with a monthly cycle. ## Not run: residuals < rnorm(365 * 5) ## End(Not run) n < length(residuals) dates < seq.Date(from = as.Date("20140101"), len = n, by = 1) monthly.cycle < rnorm(12) monthly.cycle < monthly.cycle  mean(monthly.cycle) timestamps < as.POSIXlt(dates) month < timestamps$mon + 1 new.month < c(TRUE, diff(timestamps$mon) != 0) month.effect < cumsum(new.month) month.effect[month.effect == 0] < 12 response < monthly.cycle[month] + residuals response < zoo(response, timestamps) ## Now let's fit a bsts model to the daily data with a monthly annual ## cycle. ss < AddLocalLevel(list(), response) ss < AddMonthlyAnnualCycle(ss, response) ## In real life you'll probably want more iterations. model < bsts(response, state.specification = ss, niter = 200) plot(model) plot(model, "monthly")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.