[BioC] qqplot: theoretical Quantiles

stefano iacus stefano.iacus at unimi.it
Mon Oct 23 03:35:53 CEST 2006


why not just use the true quantitles of the target distribution?
R (base) has almost all q* functions available for that (qnorm, qt,  
qchisq, etc).
and plot empirical quantiles against theoretical quantiles.

You can cut and paste directly from email to R console the following:

# generate 1000 pseudo r.v. from t, df=10
x <- rt(n=1000, df=10)

# vector of probabilities
p <- seq(0,1,length=20)

# calculate sample quantiles
qtl <- quantile(x, p=p)

# obtain quantiles from a theoretical distribution t, df=10
t.qtl <- qt(p, df=10)

# draw a q-q plot
plot(qtl,t.qtl)

# the following is
# equivalent to qqline but for t, df=10
# if points are aligned against red line, then they have the
# same quantiles as the t distribution with df=10

lines(t.qtl,t.qtl,col="red")

# here is an example of q-q plot against wrong theoretical
# distribution: t, df=1


# obtain quantiles from a theoretical distribution t, df=1
f.qtl <- qt(p, df=1)

# qq plot of sample quantiles against
# theoretical quantiles of a t with 1 df

points(qtl,f.qtl, col="blue")


# Other possibilities are available: for example you first
# estimate the degrees of freedom and then draw a qq-plot against
# qt(p, df="estimated df")

# e.g., given that if X is distributed as a "t" with "g" d.f.
# then:   Var(X) = g/(g-1)
# a raw estimate of g is then
#  2*Var(X)/(Var(X)-1)

# the following is an example of application of such approach
est.df <- 2*var(x)/(var(x)-1)
est.qtl <- qt(p, df=est.df)
points(qtl,est.qtl, col="green") # qq plot of sample quantiles against


the same holds for almost all other theoretical distributions but, of  
course,
as in Chi-Squared of Kolmogorov-Smirnov test, either you estimate  
from the
sample the parameters of the theorecial distribution or you explicilty
assume them and do several tries to see for which distribution you get
the best fit

Anyway, if you can use a Chi-Squared or Kolmogorov-Smirnov test, this  
is probably more
appropriate then just graphical inspection of quantiles. At least you  
have a p-value.
stefano





On 23/ott/06, at 00:50, Naomi Altman wrote:

> Limma has a qqt plot for checking against a t-distribution.
>
> Some packages do have the quantiles for F, etc, but I cannot see  
> one in R.
>
> However, it is readily done in any of several ways:
>
> 1) Use the quantiles, just as with the Normal
> 2) Generate several samples of the required size;
> sort each; take the means of the smallest, 2nd smallest, etc
>
> --Naomi
>
> At 06:12 AM 10/22/2006, shahrgol at web.de wrote:
>
>> Hi Noami,
>> Thanks for your explanation.
>> I understood qqnorm function in such a way:
>> The theoretical quantiles is computed by standard normal  
>> distribution.
>>
>> x = µ + z&#963; (and/ or: z = x- mean/SD)
>>
>> Is also the other theoretical distributions
>> (e.g. F-Distribution or t-Distribution) in R used?
>>
>> Thanks,
>> Mohammad
>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Naomi Altman <naomi at stat.psu.edu>
>>> Gesendet: 22.10.06 04:24:24
>>> An: Mohammad Esad-Djou <shahrgol at web.de>
>>> Betreff: Re: [BioC] qqplot: theoretical Quantiles
>>
>>
>>> In theory, the idea is that if
>>>
>>> y1 ... yn are i.i.d. F, we sort them into
>>>
>>> y(1)<y(2)< ..<y(n)  and plot these against the expected value of the
>>> smallest, 2nd smallest, etc from a sample of size n generated  
>>> from F.
>>>
>>> Taking such an expectation is difficult, so usually an approximation
>>> is given based on the quantiles of the proposed distribution:
>>>
>>> F(1/(n+1)), F(2/(n+1) ) ... F(n/(n+1))
>>>
>>> I have not looked at the R documentation to see the exact
>>> approximation used, but you can probably find it if you dig a bit.
>>>
>>> --Naomi
>>>
>>>
>>>
>>> At 01:10 PM 10/21/2006, you wrote:
>>>> Hello,
>>>>
>>>> I use qqplot and would like to know, how
>> theoretical quantiles is computed.
>>>> Is there source about it?
>>>>
>>>> Thanks,
>>>> Mohammad Esad-Djou
>>>>
>>>> IZBI- Uni-Leipzig
>>>>
>>>> _______________________________________________
>>>> Bioconductor mailing list
>>>> Bioconductor at stat.math.ethz.ch
>>>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>>>> Search the archives:
>>>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>>>
>>> Naomi S. Altman                                814-865-3791 (voice)
>>> Associate Professor
>>> Dept. of Statistics                              814-863-7114 (fax)
>>> Penn State University                         814-865-1348  
>>> (Statistics)
>>> University Park, PA 16802-2111
>>>
>>
>> _______________________________________________
>> Bioconductor mailing list
>> Bioconductor at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/bioconductor
>> Search the archives:
>> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
> Naomi S. Altman                                814-865-3791 (voice)
> Associate Professor
> Dept. of Statistics                              814-863-7114 (fax)
> Penn State University                         814-865-1348  
> (Statistics)
> University Park, PA 16802-2111
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/ 
> gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list