# 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)
fit <- samias(y, kmax = 5)
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)
fit <- samias(y, D_type = "tfq", q = 1, kmax = 5)
print(fit)
##------ Piecewise constant trend filtering example in Wen et al.(2018).-----
set.seed(1)
data <- SimuBlocks(2048)
fit <- samias(data$y, kmax = 15) # With default input argument
plot(fit, type="coef", main = "Blocks") # Plot the optimal estimate
lines(data$x, data$y0, type="s") # Add the true signal for reference
plot(fit, type= "vpath", main = "Blocks") # Plot the solution path
##------ Piecewise linear trend filtering example in Wen et al.(2018).-----
set.seed(1)
data <- SimuWave(512)
# samias With adjustment
fit <- samias(data$y, q = 1, D_type = "tfq", kmax = 15, adjust = TRUE, delta = 20)
plot(fit, main = "Wave", k = 10) # Plot the estimate with user-specified k
lines(data$x, data$y0, type="l") # Add the true signal for reference
plot(fit, type= "vpath", main = "Wave") # Plot the solution path
##------ Doppler example in Wen et al.(2018).-----
set.seed(1)
data <- SimuDoppler(1024)
op <- par(mfrow=c(1,2))
fit1 <- samias(data$y, q = 2, D_type = "tfq", kmax = 30) # piecewise quadratic
plot(fit1, main = "Doppler: q = 2")
fit2 <- samias(data$y, q = 3, D_type = "tfq", kmax = 30) # piecewise Cubic polynomial
plot(fit2, main = "Doppler: q = 3")
par(op)
# }
Run the code above in your browser using DataLab