Created
April 4, 2016 04:13
-
-
Save seankross/7a47d8ee6871f626cc2d947dfbb04919 to your computer and use it in GitHub Desktop.
Plot Predicted Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(splines) | |
set.seed(3-29-2016) | |
X <- rnorm(1000) | |
Y <- rnorm(1000) | |
model <- lm(Y ~ ns(X, 6)) | |
lo <- loess(Y ~ X, span = .75) | |
Y_hat <- predict(model, data.frame(X = X)) | |
plot(X, Y) | |
lines(X[order(X)], Y_hat[order(X)], col = "red", lwd = 2) | |
lines(X[order(X)], predict(lo)[order(X)], col = "blue", lwd = 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment