Created
April 28, 2015 13:38
-
-
Save schnellp/53fa4f2d75191a1a81f7 to your computer and use it in GitHub Desktop.
Which normal Q-Q plot is of the real data?
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
qqfind <- function(x) { | |
# Generates the normal Q-Q plot for the given data | |
# as well as for three samples of the same size | |
# from a normal distribution with matching | |
# mean and variance. | |
# | |
# If it's obvious which one is the real data, | |
# it might not be normally distributed. | |
# | |
# Return value is the index of the plot | |
# of the real data. | |
mean <- mean(x) | |
sd <- sd(x) | |
par(mfrow=c(2, 2)) | |
real <- sample(1:4, 1) | |
for (i in 1:4) { | |
if (i == real) { | |
qqnorm(x) | |
qqline(x) | |
} else { | |
y <- rnorm(length(x), mean, sd) | |
qqnorm(y) | |
qqline(y) | |
} | |
} | |
par(mfrow=c(1, 1)) | |
return(real) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment