Skip to content

Instantly share code, notes, and snippets.

@jasonsahl
Last active April 27, 2016 23:28
Show Gist options
  • Save jasonsahl/569e502a66dcab5c643f to your computer and use it in GitHub Desktop.
Save jasonsahl/569e502a66dcab5c643f to your computer and use it in GitHub Desktop.
plot outliers in X and Y data
#The input is two colums: x and corresponding y values
require(MASS) ## for mvrnorm()
set.seed(1)
mine <- read.table("xy.txt")
mine <- data.frame(mine)
names(mine) <- c("X","Y")
plot(mine)
res <- resid(mod <- lm(Y ~ X, data = mine))
res.qt <- quantile(res, probs = c(0.001,0.999))
want <- which(res >= res.qt[1] & res <= res.qt[2])
pdf("out.pdf")
plot(mine, type = "n")
#mine[-want,]
points(mine[-want,], col = "black", pch = 21, bg = "black", cex = 0.8)
points(mine[want,], col = "red", pch = 21, bg = "red", cex = 0.8)
abline(mod, col = "blue", lwd = 2)
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment