x <- seq(-20, 20, 0.1)
y <- sin(x)/x + rnorm(length(x), sd=0.03)
p <- which(y == "NaN")
y <- y[-p]
r <- poly.regression(y, ci=TRUE, s=0.30)
plot(y,type="l", lwd=0.5, main="s = 0.10")
y.polygon <- c((r$lower.ci)[1:length(y)], (r$upper.ci)[rev(1:length(y))])
x.polygon <- c(1:length(y), rev(1:length(y)))
polygon(x.polygon, y.polygon, col="#00009933", border=NA)
lines(r$loess, lwd=1.5, col="red")
# Impute NA values, replacing only NA's
y.na <- y
y.na[c(100,200,300)] <- NA
p.y <- poly.regression(y.na, s=0.10, impute = TRUE, na.only = TRUE)
y - p.y
plot(p.y,type="l", lwd=1.5, col="blue", main="s = 0.10")
lines(y, lwd=1.5, col="red")
Run the code above in your browser using DataLab