Q-Q plot

Problem

You want to compare the distribution of your data to another distribution. This is often used to check whether a sample follows a normal distribution, to check whether two samples are drawn from the same distribution.

Solution

Suppose this is your data:

  1. set.seed(183)
  2. # Normally distributed numbers
  3. x <- rnorm(80, mean=50, sd=5)
  4. # Uniformly distributed numbers
  5. z <- runif(80)
  1. # Compare the numbers sampled with rnorm() against normal distribution
  2. qqnorm(x)
  3. qqline(x)
  4. # The same numbers to the 4th power, compared to the normal distribution
  5. qqnorm(x^4)
  6. qqline(x^4)
  7. # Numbers sampled from the flat distribution, compared to normal
  8. qqnorm(z)
  9. qqline(z)

plot of chunk unnamed-chunk-3plot of chunk unnamed-chunk-3plot of chunk unnamed-chunk-3