# This figure shows an example of local regression for the function # f(x) = sin(x) + 2*exp(-30 x^2) n.observations <- 101 x.values <- seq(from = -2, to = 2, length.out = n.observations) y.values <- sin(x.values) + 2*exp(-30 * (x.values^2)) y.standard.deviation <- sd(y.values) scaling <- 1/6 noise.standard.deviation <- y.standard.deviation * scaling added.noise <- rnorm(n.observations, 0, noise.standard.deviation) observations <- y.values + added.noise smth<-ksmooth(x.values, observations, kernel = "normal", bandwidth = 0.5)$y plot(x.values, observations, xlim = c(-2, 2), ylim = c(-1.2, 2.2), xaxt = "n", yaxt = "n", main = "", xlab = "x", ylab = "y", cex.lab = 1.5, pch = 16) lines(x.values, y.values, col = 153, lwd = 2) #lines(x.values, smth) # Add vertical lines. abline(v = 1.4, lty = 2, lwd = 2) abline(v = 1.6, lty = 2, lwd = 2) # Fix plot axes. axis.size <- 1.4 x.axis <- seq(from = -2, to = 2, by = 1) y.axis <- seq(from = -1, to = 2, by = 1) axis(1, at = x.axis, labels = x.axis, cex.axis = axis.size) axis(2, at = y.axis, labels = y.axis, cex.axis = axis.size) # Close graphics device. dev.print(device = postscript, "15.11.eps", horizontal = TRUE)