Skip to content

Instantly share code, notes, and snippets.

@schnellp
Created April 28, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schnellp/53fa4f2d75191a1a81f7 to your computer and use it in GitHub Desktop.
Save schnellp/53fa4f2d75191a1a81f7 to your computer and use it in GitHub Desktop.
Which normal Q-Q plot is of the real data?
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