if (FALSE) {
##
## Example: Applying BDP-DW method to a multi-peaked heavy-tailed tvMA(1) process
##
# set seed
set.seed(2)
# set the length of time series
len_d <- 1500
# generate data from DGP LS2b defined in Section 4.2.2 of Tang et al. (2023).
# see also ?sim_tvarma12
sim_data <- sim_tvarma12(len_d = 1500, dgp = "LS2", innov_distribution = "b")
set.seed(NULL)
# specify grid-points at which the tv-PSD is evaluated
res_time <- seq(0, 1, by = 0.005); freq <- pi * seq(0, 1, by = 0.01)
# calculate the true tv-PSD of DGP LS2b at the pre-specified grid
true_tvPSD <- psd_tvarma12(rescaled_time = res_time, freq = freq, dgp = "LS2")
# plot the true tv-PSD
# type ?plot.bdp_dw_tv_psd for more info
plot(true_tvPSD)
# If you run the example be aware that this may take several minutes
print("This example may take some time to run")
result <- gibbs_bdp_dw(data = sim_data,
m = 50,
likelihood_thinning = 2,
rescaled_time = res_time,
freq = freq)
# extract bayes factor and examine posterior summary
bayes_factor(result)
summary(result)
# compare estimate with true function
# type ?plot.bdp_dw_result for more info
par(mfrow = c(1,2))
plot(result, which = 1,
zlim = range(result$tvpsd.mean, true_tvPSD$tv_psd)
)
plot(true_tvPSD,
zlim = range(result$tvpsd.mean, true_tvPSD$tv_psd),
main = "true tv-PSD")
par(mfrow = c(1,1))
}
Run the code above in your browser using DataLab