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 11-vector
And the remaining elements are
AddMonthlyAnnualCycle(state.specification,
y,
date.of.first.observation = NULL,
sigma.prior = NULL,
initial.state.prior = NULL,
sdy)
A list of state components, to which the monthly annual cycle will be added. If omitted, an empty list will be assumed.
The time series to be modeled, as a numeric vector.
An object created by SdPrior
describing the prior distribution for the standard deviation of the
random walk increments.
An object created using
NormalPrior
, describing the prior distribution
of the the initial state vector (at time 1).
The standard deviation of the series to be modeled. This
will be ignored if y
is provided, or if all the required
prior distributions are supplied directly.
# NOT RUN {
## Let's simulate some fake daily data with a monthly cycle.
# }
# NOT RUN {
residuals <- rnorm(365 * 5)
# }
# NOT RUN {
n <- length(residuals)
dates <- seq.Date(from = as.Date("2014-01-01"),
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)
# }
# NOT RUN {
<!-- %% 12 -->
# }
# NOT RUN {
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 = 250)
plot(model)
plot(model, "monthly")
# }
Run the code above in your browser using DataLab