set.seed(200)
signal = c(rep(0, 50), rep(10, 50))
noise = rep(1, 100)
noise_var = rep(1, 100)
for (k in 2:100){
noise_var[k] = exp(0.9*log(noise_var[k-1]) + rnorm(1, 0, 0.5))
noise[k] = rnorm(1, 0, sqrt(noise_var[k])) }
y = signal + noise
model_spec = dsp_spec(family = "gaussian", model = "changepoint",
D = 1, useAnom = TRUE, obsSV = "SV")
mcmc_output = dsp_fit(y, model_spec = model_spec, nsave = 500, nburn = 500)
# Estimated posterior mean vs ground truth
plot(mcmc_output, type = "mu", true_values = signal)
# Estimated innovation variance vs ground truth for illustration only
plot(mcmc_output, type = "obs_sigma_t2", true_values = noise^2)
Run the code above in your browser using DataLab