This question already has an answer here:

According to the Matlab documentation for qqplot, the ith ordered value is plotted against the (1-0.5)/N th quantile of the specified distribution. I tried to see what values are computed from the qqplot function using the code:

% Sample data
data = [20.1356902600000,22.9968989300000,27.8533897000000,34.6339252300000,35.9040685800000,37.1956327500000,37.7866312200000,51.8297694800000,54.4870463000000,55.9331364700000,55.9442022600000,57.8593133700000,58.4149264500000,60.2702913000000,63.4486306400000,63.4486306400000,72.1816635900000,72.1816635900000,72.6987322200000,74.3357331500000,75.9363293000000,75.9363293000000,75.9363293000000,75.9363293000000,75.9363293000000,75.9363293000000,77.5225121300000,77.6878835100000,78.2241174600000,78.7961655500000,79.1008427300000,79.4293391500000,80.2392159200000,80.4032394000000,80.5065995800000,80.5608526300000,81.6286695600000,83.1438511500000,83.2355410900000,83.4033539900000,83.4291352300000,83.9948416400000,84.3049374900000,84.7920938400000,85.2741586700000,85.4844301700000,87.5935000200000,87.6738399200000,88.2772000900000,89.3328328700000,89.8733762200000,90,90,90,91.2300629900000,93.0954777400000,94.5155698300000,95.2079061600000,95.9303831900000,96.7973475600000,97.1230107200000,97.6290536100000,98.5358378400000,99.7607840800000,100.282401200000,100.853007300000,104.063670700000,104.877246400000,104.952311800000,105.664266900000,111.584437700000,112.086132400000,114.605495500000,114.888200000000,114.888200000000,115.241718100000,116.993923400000,120.813417400000,123.484955000000,123.998002500000,137.948493100000,142.466756700000,145.424388300000,146.713218300000,149.316582900000,149.762000400000,157.720284500000,163.781591600000,179.372353000000];

% QQPlot
H = qqplot(data); set(H, 'Visible', 'off'); title(' '); xlabel(''); ylabel('')
%Click on the axes that contains the child(ren) you are interested in. 
kids = get(gca,'Children');
%Extract X and Y Data by indexing into kids
xdata = get(kids,'XData');
ydata = get(kids,'YData');
xdata1 = xdata{1};  %empirical quantile for blue line 
ydata1 = ydata{1};  %sorted input data for blue line
xdata2 = xdata{3};  %theoritical (std. normal) quantile for red line 
ydata2 = ydata{3};  %empirical data for red dashed line

% Plot the data
plot(xdata1, ydata1, '.b', 'Linewidth', 2)
hold on;
plot(xdata2, ydata2, '-.r', 'Linewidth', 2)
ylabel('Quantiles of input samples', 'fontsize',8)
xlabel('standard normal quantiles', 'fontsize',8)

I am perplexed as to how the xdata1 and xdata2 values were obtained. For instance, the median of the distribution (or the 0.5 quantile) is the (n+1)/2 = 45th observation, which corresponds to ydata1 value of 85.2742. Similarly, the 75th percentile (or the 0.75 quantile) is the 67.5th observation – which corresponds to ydata1 value of 104.2671. How then did the qqplot function compute the corresponding xdata1 values of 0 and 0.6835 for the 0.5 and 0.75 quantiles?

Also, is there any appropriate reference material/publication where i can find the description of this algorithm?


marked as duplicate by whuber Apr 4 '18 at 17:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Not sure about Matlab, but R has good documentation for its sample quantile functions (under ?quantile). Matlab could use similar. $\endgroup$ – jwimberley Apr 4 '18 at 13:24
  • $\begingroup$ Thanks @jwimberley. I don't use nor know much about R. Can you please post me the link? $\endgroup$ – oma11 Apr 4 '18 at 13:25
  • $\begingroup$ No link (docs in code). R references a paper by Hyndman and Fan (1996) that presents 9 sample quantile algorithms; it's likely that Matlab uses one of these. $\endgroup$ – jwimberley Apr 4 '18 at 13:26
  • $\begingroup$ Ok. I would have a look at it. Thank you very much $\endgroup$ – oma11 Apr 4 '18 at 13:48
  • 1
    $\begingroup$ Now i know what it is. See here: stats.stackexchange.com/questions/245396/… $\endgroup$ – oma11 Apr 4 '18 at 15:31