Created
April 6, 2018 00:21
-
-
Save trinker/926026fb60836f563c2e36503e55248a to your computer and use it in GitHub Desktop.
QQplots explained
This file contains hidden or 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
## My understanding of a qqplot was it was the sorted values for a variable on the | |
## y against the theoretical values from a normal (or whatever distribution) | |
## distribution on the x. We can get the y values from our sample and the x values | |
## from looking up the p value in a given distribution and getting the | |
## corresponding nromal value. Now to get the p value I thought we divide the 1 | |
## through length of the sample by n + 1. I have never actually tried to do this | |
## and used qqplot or the same geom_qq from ggplot. But today I tried to make the | |
## qqplot by hand and I don't get the same scale for the theoretical values and am | |
## unsure why. The points look the same but the scale is different. Why? | |
## This is wrong (almost right) | |
x <- c(3.89, 4.75, 4.75, 5.2, 5.78, 5.8, 6.33, 7.21, 7.9) | |
par(mfrow = c(2, 1)) | |
plot(qnorm((1:length(x))/(1 + length(x))), sort(x)) | |
qqnorm(x) | |
## R uses | |
x <- c(3.89, 4.75, 4.75, 5.2, 5.78, 5.8, 6.33, 7.21, 7.9) | |
par(mfrow = c(2, 1)) | |
plot(qnorm((1:length(x))/(1 + length(x))), sort(x)) | |
qqnorm(x) | |
## See: https://www.youtube.com/watch?v=X9_ISJ0YpGw | |
## http://www.talkstats.com/threads/quantile-quantile-plot-qqplot-in-r-by-hand-ish.71391/#post-206769 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment