Skip to content

Instantly share code, notes, and snippets.

@erykml
Created June 3, 2019 16:38
Show Gist options
  • Select an option

  • Save erykml/252f0da6a024cad7f55a5e063f3fe024 to your computer and use it in GitHub Desktop.

Select an option

Save erykml/252f0da6a024cad7f55a5e063f3fe024 to your computer and use it in GitHub Desktop.
%%R -i y
p1 <- ggplot(lin_reg, aes(.fitted, .resid)) + geom_point()
p1 <- p1 + stat_smooth(method="loess") + geom_hline(yintercept=0, col="red", linetype="dashed")
p1 <- p1 + xlab("Predicted") + ylab("Residuals")
p1 <- p1 + ggtitle("Residuals vs. Predicted Values") + theme_bw()
df_plt <- data.frame("fitted" = fitted(lin_reg), "observed" = X$medv)
p2 <- ggplot(df_plt, aes(x=fitted, y=observed)) + geom_point()
p2 <- p2 + stat_smooth(method="loess") + geom_abline(intercept = 1, col="red", linetype="dashed")
p2 <- p2 + xlab("Predicted") + ylab("Observed")
p2 <- p2 + ggtitle("Observed vs. Predicted Values") + theme_bw()
grid.arrange(p2, p1, ncol=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment