Next we compute the quantiles 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9 and 1 of the above data X:X = rnorm(20, mean=24, sd=3)
Let us compute the same set of quantiles in the unit Gaussian doitribution:Q_sample = quantile(X, probs=seq(0.1,0.9,0.1))
The scatter plot between Q_sample and Q_Guassian generates the Q-Q plot:Q_Guassian = qnorm(seq(0.1, 0.9, 0.1))
The following Q-Q plot is created: Since the data sampled from a Gaussi distribution is compared with that of Unit Gaussin distribution, the Q-Q plot in Figure-1 above almost lies along the diagonal line. We will now see how a bad Q-Q plot looks like. We will generate data from two different Gaussians and merge them to crete a non-normal data set and create a Q-Q plot for this data with Gaussian as reference. This is shown in the script lines below:plot(Q_Guassian, Q_sample, pch=19, col="blue",xlab="Q_Guassian", ylab="Q_sample", font.lab=2, cex.lab=1.2, main="Q-Q plot")
Executing the above lines of R-script creates the following plot: As expected, the above Q-Q plot does not show a linear correlation since the sample data points are not drawn from a gaussian distribution.X = c(rnorm(10, mean=20, sd=3), rnorm(20, mean=40, sd=3)) Q_sample = quantile(X, probs=seq(0.1,0.9,0.1)) Q_Gaussian = qnorm(seq(0.1, 0.9, 0.1)) plot(Q_Gaussian, Q_sample, pch=19, col="blue",xlab="Q_Guassian", ylab="Q_sample", font.lab=2, cex.lab=1.2, main="Q-Q plot")