# NOT RUN {
##----- A toy example of piecewise constant signal -------
set.seed(0)
n <- 100
x = seq(1/n, 1,length.out = n)
y0 = 0*x; y0[x>0.5] = 1
y = y0 + rnorm(n, sd = 0.1)
# For 'amias' object
fit <- amias(y, k = 1)
plot(fit)
# For 'samias' object
fit <- samias(y, kmax = 5)
plot(fit, type = "coef", main = "Piecewise Constant")
op <- par(mfrow=c(1,2))
plot(fit, type= "coef", add.knots = FALSE, main = "Piecewise Constant")
plot(fit, type = "vpath", main = "Piecewise Constant")
par(op)
##----- A toy example of piecewise linear trend -------
set.seed(0)
y0 = 2*(0.5-x); y0[x>0.5] = 2*(x[x>0.5]-0.5)
y = y0 + rnorm(n, sd = 0.1)
# For 'amias' object
fit <- amias(y, D_type = "tfq", q = 1, k = 1)
plot(fit, main = "Piecewise Linear")
# For 'samias' object
fit <- samias(y, D_type = "tfq", q = 1, kmax = 4)
op <- par(mfrow=c(1,2))
plot(fit, type = "coef", main = "Piecewise Linear")
plot(fit, type = "vpath", main = "Piecewise Linear")
par(op)
# }
Run the code above in your browser using DataLab