## Completes in 15 seconds
set.seed(12345)
n <- 100
x <- 1:n
f <- matrix(rep(c(-2,5,0,-10), each=n/4), ncol=1)
y <- y0 <- f + rnorm(length(f))
## Clean Data
plot(x, y, pch=16, cex.lab=1.5, cex.axis=1.5, cex.sub=1.5, col='gray')
lines(x, f, lwd=3)
D <- myGetDkn(1, n)
k <- c(4,3,2)
rho <- 10^8
# (not run)
# sol <- L2E_TF_dist(y=y, D=D, kSeq=k, rhoSeq=rho)
# plot(x, y, pch=16, cex.lab=1.5, cex.axis=1.5, cex.sub=1.5, col='gray')
# lines(x, f, lwd=3)
# lines(x, sol$Beta[,3], col='blue', lwd=3) ## k=2
# lines(x, sol$Beta[,2], col='red', lwd=3) ## k=3
# lines(x, sol$Beta[,1], col='dark green', lwd=3) ## k=4
## Contaminated Data
ix <- sample(1:n, 10)
y[ix] <- y0[ix] + 2
plot(x, y, pch=16, cex.lab=1.5, cex.axis=1.5, cex.sub=1.5, col='gray')
lines(x, f, lwd=3)
# (not run)
# sol <- L2E_TF_dist(y=y, D=D, kSeq=k, rhoSeq=rho)
# plot(x, y, pch=16, cex.lab=1.5, cex.axis=1.5, cex.sub=1.5, col='gray')
# lines(x, f, lwd=3)
# lines(x, sol$Beta[,3], col='blue', lwd=3) ## k=2
# lines(x, sol$Beta[,2], col='red', lwd=3) ## k=3
# lines(x, sol$Beta[,1], col='dark green', lwd=3) ## k=4
Run the code above in your browser using DataLab