Bug 16475 - non-central t quantile function returns NaN when df = Inf
Summary: non-central t quantile function returns NaN when df = Inf
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: R 3.2.1
Hardware: x86_64/x64/amd64 (64-bit) OS X Yosemite
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-07-17 13:28 UTC by Benjamin
Modified: 2015-07-19 11:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin 2015-07-17 13:28:19 UTC
Let my.ncp be greater 0. Then, for any my.p in [0, 1] qt(my.p, Inf, my.ncp) results in NaN (including a warning message).
Based on the line
 if (!R_FINITE(df)) ML_ERR_return_NAN;
in qnt.c it appears that this behavior is intended. But according to the manual df = Inf should be allowed. Because for increasing degrees of freedom the non-central t distribution approaches the normal distribution with mean = my.ncp and sd = 1, I would have expected to get qnorm(my.p, mean = my.ncp, sd = 1) for the limiting case df = Inf.

My question therefore is: Wouldn’t it make sense to generally return the result from qnorm in case df exceeds some large value, say 10^10?

Thank you,
Benjamin
Comment 1 Martin Maechler 2015-07-17 16:32:52 UTC
Thank you, Benjamin,

your suggestion makes sense ('cum grano salis' in any case).

Instead of an arbitrary cutoff (which should depend on "my.p" and "my.ncp")
it seems much easier -- and to work correctly -- I'll have to check more thoroughly --
to just replace  'Inf' by something like 1e300.

Thank you for the good observation and suggestion!

Martin Maechler,
ETH Zurich
Comment 2 Martin Maechler 2015-07-18 19:40:11 UTC
Fix --- only for the case  df = Inf  --- now commited to R-devel and R-patched,
i.e., will be in  R 3.2.2, due in mid August.

There are many numerical problems if you look in the hairy details of the 
non-central t  distribution and hence also quantile function.
For finite df,  the distrib and inverse (i.e. the quantile) depend on three parameters, and cutoffs should depend on all three parameters.
Comment 3 Benjamin 2015-07-19 11:36:46 UTC
I agree; Thank you for taking this up!