Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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