nscosinor(data, response, cycles, niters=1000, burnin=500, tau, inits,
lambda=1/12, div=50, monthly=TRUE, alpha=0.05)
cycles=c(6,12)
.std.season
. Initial values should be given for each seasonal cycle.season
if there is only one seasonal cycle.mcmc
) of variance estimates: standard error for overall noise (std.error), standard error for season(s) (std.season), phase(s) and amplitude(s)cycle
.
The cycles should be specified in units of time.
If the data is monthly, then setting lambda=1/12
and cycles=12
will fit an annual seasonal pattern.
If the data is daily, then setting lambda=
1/365.25
and cycles=365.25
will fit an annual seasonal pattern.
Specifying cycles=
c(182.6,365.25)
will fit two seasonal patterns, one with a twice-annual cycle, and one with an annual cycle.
The estimates are made using a forward and backward sweep of the Kalman filter.
Repeated estimates are made using Markov chain Monte Carlo (MCMC).
For this reason the model can take a long time to run (we aim to improve this in the next version).
To give stable estimates a reasonably long sample should be used (niters
), and the possibly poor initial estimates should be discarded (burnin
).plot.nsCosinor
, summary.nsCosinor
data(CVD)
# model to fit an annual pattern to the monthly cardiovascular disease data
f = c(12)
inits = c(1)
tau = c(130,10)
res12 = nscosinor(data=CVD, response=adj, cycles=f, niters=5000,
burnin=1000, tau=tau, inits=inits)
summary(res12)
plot(res12)
plot(res12$chains$amp)
res12 = nscosinor(data=CVD, response=adj, cycles=f, niters=50, burnin=10, tau=tau, inits=inits)
Run the code above in your browser using DataLab