[Numpy-discussion] QQ Plot in Python and Noncentral Chisquare

josef.pktd@gmai... josef.pktd@gmai...
Thu Aug 16 08:55:08 CDT 2012


On Thu, Aug 16, 2012 at 9:05 AM, Yi, Chuang <chuang.yi@bankofamerica.com> wrote:
> Thank you Josef, df can be less than 1 as long as it is nonnegative:
>
> http://stat.ethz.ch/R-manual/R-patched/library/stats/html/Chisquare.html
>
> Here is an example in R:
>
>> Z0<-rchisq(2,df=0.5,ncp =2)
>> Z0
> [1] 0.5056454 2.0427540
>
> Thanks, Chuang
>
> -----Original Message-----
> From: numpy-discussion-bounces@scipy.org [mailto:numpy-discussion-bounces@scipy.org] On Behalf Of josef.pktd@gmail.com
> Sent: Wednesday, August 15, 2012 9:59 PM
> To: Discussion of Numerical Python
> Subject: Re: [Numpy-discussion] QQ Plot in Python and Noncentral Chisquare
>
> On Wed, Aug 15, 2012 at 10:59 AM, Yi, Chuang
> <chuang.yi@bankofamerica.com> wrote:
>> Hello,
>>
>>
>>
>> I am a new user of Python. I have a couple of questions that would
>> appreciate your guidance!
>>
>>
>>
>> QQ Plot in Python: I could not find any functions in either Numpy or Scipy
>> to do QQ Plot of two vectors of data. For example, in Matlab, one could just
>> call qqplot(X,Y), which will generate the QQ plot of vector X against vector
>> Y. Would you please let me know which python package has similar
>> functionality?
>> Noncentral Chisquare: it looks to me that in Numpy and Scipy, the noncentral
>> chisquare distribution only allows Integer degree of freedom. For example,
>> the following code will produce an error message. In R, however, it also
>> allows non-integer degree of freedom. Would you please let me know which
>> python package has similar functionality?
>>
>> data = numpy.random.noncentral_chisquare(0.5, 2, 100)
>> ValueError: df <= 0
>
> restriction is >1 not integer
>
>>>> np.random.noncentral_chisquare(1, 2, 100)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "mtrand.pyx", line 1957, in
> mtrand.RandomState.noncentral_chisquare
> (numpy\random\mtrand\mtrand.c:9847)
> ValueError: df <= 0
>
>>>> np.random.noncentral_chisquare(1.0001, 2, 100)
> array([  5.75083221,   1.08050491,   0.69267684,   1.37806056,
>          2.39899   ,   0.31415666,   2.9202386
>
>
> I don't know if the >1 restriction is justified or could be dropped.

A quick look at numpy\random\mtrand\distributions.c :

double rk_noncentral_chisquare(rk_state *state, double df, double nonc)
{
    double Chi2, N;

    Chi2 = rk_chisquare(state, df-1);
    N = rk_gauss(state) + sqrt(nonc);
    return Chi2 + N*N;
}

It uses df-1 for chisquare, which means df>1 for non-central is required here.

So there needs to be another way of generating non-central chisquare
for 0<df<=1.

rk_noncentral_f uses rk_noncentral_chisquare so it will have the same
limitation.

(I don't have the time to look into this.)

Josef

>
> Josef
>
>>
>>
>>
>> Thank you very much,
>>
>>
>>
>> Regards,
>>
>> Chuang
>>
>> ________________________________
>> This message w/attachments (message) is intended solely for the use of the
>> intended recipient(s) and may contain information that is privileged,
>> confidential or proprietary. If you are not an intended recipient, please
>> notify the sender, and then please delete and destroy all copies and
>> attachments, and be advised that any review or dissemination of, or the
>> taking of any action in reliance on, the information contained in or
>> attached to this message is prohibited.
>> Unless specifically indicated, this message is not an offer to sell or a
>> solicitation of any investment products or other financial product or
>> service, an official confirmation of any transaction, or an official
>> statement of Sender. Subject to applicable law, Sender may intercept,
>> monitor, review and retain e-communications (EC) traveling through its
>> networks/systems and may produce any such EC to regulators, law enforcement,
>> in litigation and as required by law.
>> The laws of the country of each sender/recipient may impact the handling of
>> EC, and EC may be archived, supervised and produced in countries other than
>> the country in which you are located. This message cannot be guaranteed to
>> be secure or free of errors or viruses.
>>
>> References to "Sender" are references to any subsidiary of Bank of America
>> Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are
>> Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a
>> Condition to Any Banking Service or Activity * Are Not Insured by Any
>> Federal Government Agency. Attachments that are part of this EC may have
>> additional important disclosures and disclaimers, which you should read.
>> This message is subject to terms available at the following link:
>> http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you
>> consent to the foregoing.
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
> ----------------------------------------------------------------------
> This message w/attachments (message) is intended solely for the use of the intended recipient(s) and may contain information that is privileged, confidential or proprietary. If you are not an intended recipient, please notify the sender, and then please delete and destroy all copies and attachments, and be advised that any review or dissemination of, or the taking of any action in reliance on, the information contained in or attached to this message is prohibited.
> Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Sender. Subject to applicable law, Sender may intercept, monitor, review and retain e-communications (EC) traveling through its networks/systems and may produce any such EC to regulators, law enforcement, in litigation and as required by law.
> The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or free of errors or viruses.
>
> References to "Sender" are references to any subsidiary of Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this EC may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link:
> http://www.bankofamerica.com/emaildisclaimer. By messaging with Sender you consent to the foregoing.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


More information about the NumPy-Discussion mailing list