In R, I'm wondering how to get qqnorm
to number its outliers (I've circled these in red, below).
Here is an example. I do a linear regression:
lm1 <- lm (y ~ x)
I then plot the model:
plot(lm1)
This produces a very nice QQ plot. You can see that it numbers the outliers (I've circled this in red).
However, if I do my own qqnorm, the outliers are not numbered. How can I number these outliers, just like in the previous graph?
qqnorm(y)
qqline(y)
Another very simple way is the following:
QQ_y=qqnorm(y)
identify(QQ_y)
The code will pause here. Hover over your plot, click on the assumed outliers or other points of interest, then control click or escape to continue code.
qqline(y)
Learn to look at the code:
plot.lm
# snipping the rather long output top and bottom and showing hte relevant section
if (show[2L]) {
ylim <- range(rs, na.rm = TRUE)
ylim[2L] <- ylim[2L] + diff(ylim) * 0.075
dev.hold()
qq <- qqnorm(rs, main = main, ylab = ylab23, ylim = ylim,
...)
if (qqline)
qqline(rs, lty = 3, col = "gray50")
if (one.fig)
title(sub = sub.caption, ...)
mtext(getCaption(2), 3, 0.25, cex = cex.caption)
if (id.n > 0)
text.id(qq$x[show.rs], qq$y[show.rs], show.rs)
dev.flush()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With