kb:qq_plots

This is an old revision of the document!


QQ plots

A quantile-quantile plot, or QQ plot, is a visual goodness-of-fit test. It checks if two distributions $F$ (distribution we're testing against) and $F_n$ (empirical distribution) are close. This is done by plotting $F^{-1}$ on the x-axis against $F_n^{-1}$ on the y-axis. If the points are close to the line $y=x$, the two distributions are close.

To plot a QQ plot:

  1. Reorder the samples in increasing order. Denote the samples $X_i$ such that $X_i$ is the $i$th smallest sample.
  2. Plot the points

$$(F^{-1}(\frac{1}{n}),X_{(1)}), (F^{-1}(\frac{2}{n}),X_{(2)}), \ldots , (F^{-1}(\frac{i}{n}),X_{(i)}), \ldots , (F^{-1}(\frac{n-1}{n}),X_{(n-1)})$$

($(F^{-1}(\frac{n}{n}),X_{(n)})$ is skipped because for a Gaussian cdf $F$, $F^{-1}(1) = \infty$. If $F^{-1}(1)$ is defined, the point can be included.)

To plot a QQ plot in MATLAB, use the qqplot command.

pd = makedist(distname, Name1, Value1, Name2, Value2, ...)
qqplot(x, pd)

distname can be any family of distributions, including Normal, Gamma, Binomial, Beta, Uniform, Poisson, etc. Parameters of the distribution can be specified with the name/value pairs. See the MATLAB help page for makedist for more details.

x is the array of sample data.

There are four recognizable patterns in QQ plots that gives information about the distribution of the sample. These plots were generated with this MATLAB code.

  • kb/qq_plots.1620176639.txt.gz
  • Last modified: 2024-04-30 04:03
  • (external edit)