## Not run:
# ## The following example is adopted from Liu et al, 2007:
#
# series.length = 6*128*24
# x1 = periodic.series(start.period = 1*24, length = series.length)
# x2 = periodic.series(start.period = 8*24, length = series.length)
# x3 = periodic.series(start.period = 32*24, length = series.length)
# x4 = periodic.series(start.period = 128*24, length = series.length)
# x = x1 + x2 + x3 + x4
#
# plot(ts(x, start=0, frequency=24), type="l",
# xlab="time (days)",
# ylab="hourly data", main="a series of hourly data with periods of 1, 8, 32, and 128 days")
#
# my.data = data.frame(x=x)
#
# my.w = analyze.wavelet(my.data, "x",
# loess.span=0,
# dt=1/24, dj=1/20,
# lowerPeriod = 1/4,
# make.pval=T, n.sim=10)
#
# ## Plot of wavelet power spectrum (with equidistant color breakpoints):
# wt.image(my.w, color.key="interval", legend.params=list(lab="wavelet power levels"))
#
# ## Reconstruction of the time series, including significant components only:
# reconstruct(my.w, timelab="time (days)")
# ## The same reconstruction, but showing wave components first:
# reconstruct(my.w, timelab="time (days)", plot.waves=T)
#
# ## Reconstruction, including all components whether significant or not:
# reconstruct(my.w, timelab="time (days)", only.sig=F)
#
# ## Reconstruction, including significant components, but selected periods only:
# reconstruct(my.w, timelab="time (days)", sel.period=c(1,8,32,128))
#
# ## Reconstruction, including significant components, but the ridge only:
# reconstruct(my.w, timelab="time (days)", only.ridge=T)
#
# ## See the periods involved:
# my.rec = reconstruct(my.w, timelab="time (days)", only.ridge=T)
# print(my.rec$Period[my.rec$rnum.used])
# ## The original and reconstructed time series can be retrieved as well:
# plot(my.rec$series$x, type="l", xlab="time (days)", ylab="")
# lines(my.rec$series$x.r, col="red")
# legend("topleft", legend=c("original","reconstructed"), lty=1, col=c("black","red"))
# ## End(Not run)
Run the code above in your browser using DataLab