R-distribution says that "full accuracy may not have been achieved"

I work with a problem that usually needs to calculate the distribution density t quite far in the tails in R.

For example, using the distribution function R t, dt(1.424781, 1486, -5)returns [1] 2.75818e-10. Some of my final outputs (using this density as input) do not correspond to the reference value from similar calculations performed by MATLAB by my colleague, which, in my opinion, may be due to inaccuracies in the t-tails of the distribution in R.

If I compare the distribution function of MATLAB t, it nctpdf(1.424781, 1486, -5)returns ans = 4.3932e-10, which is slightly different from the result of R.

edit: R prints two identical warning messages

In dt(1.424781, 1486, -5) : full precision may not have been achieved
in 'pnt{final}'

This is on Mac R version 3.3.1

+4
source share
2 answers

It seems that the problem comes from an algorithm that R implements for an off-center t-distribution for this case. The result is two factors:

  • the noncentrality parameter provided, -5, is an “extreme value”.

In the "Note" section of the help file ?pt,

The code for non-zero ncp is mainly intended for use with moderate ncp values: it will not be very accurate, especially in tails, for large values.

Thus, the algorithm that calculates these values ​​is not designed to calculate extreme values, such as -5. We can see this by reducing the ncp value to a more moderate level, say -1:

dt(1.424781, 1486, -1)
[1] 0.0211143
  1. :

"" ?pt

pt, C-

Lenth, R. V. (1989). AS 243 - t, 38, 185-189.

, , , .

, ncp, -5 x

dt(-1.424781, 1486, -5)
[1] 0.0006719519

.

+4

Boost ( BH-) Rcpp :

// [[Rcpp::depends(BH)]]

#include <Rcpp.h>
#include <boost/math/distributions/non_central_t.hpp> 

using namespace boost::math;

// [[Rcpp::export]]
double dnct(const double x, const double df, const double ncp) {
  non_central_t dist(df, ncp);
  return pdf(dist, x);
}


/*** R
dnct(1.424781, 1486, -5)
*/

:

[1] 4.393078e-10

, Boost Matlab , , , . boost .

+3

Source: https://habr.com/ru/post/1652707/


All Articles