if (FALSE) {
##-- simulation
set.seed(1)
num = 500
t = 1:num
w = 2*pi/25
d = 2*pi/150
x1 = 2*cos(w*t)*cos(d*t) + rnorm(num)
x2 = cos(w*t) + rnorm(num)
x = c(x1,x2)
##-- plot and periodogram (all action below 0.1)
tsplot(x, main='not easy to see the change')
mvspec(x)
##-- run procedure
autoSpec(x, max.freq=.1)
##-- output (yours will be slightly different -
##-- the nature of GA)
# returned breakpoints include the endpoints
# $breakpoints
# [1] 1 503 1000
#
# $number_of_segments
# [1] 2
#
# $segment_kernel_orders_m
# [1] 2 4
##-- plot everything
par(mfrow=c(3,1))
tsplot(x, col=4)
abline(v=503, col=6, lty=2, lwd=2)
mvspec(x[1:502], kernel=bart(2), taper=.5, main='segment 1', col=4, xlim=c(0,.25))
mvspec(x[503:1000], kernel=bart(4), taper=.5, main='segment 2', col=4, xlim=c(0,.25))
}
Run the code above in your browser using DataLab