/src/r-source/src/nmath/pnf.c
Line | Count | Source |
1 | | /* |
2 | | * Mathlib : A C Library of Special Functions |
3 | | * Copyright (C) 1998 Ross Ihaka |
4 | | * Copyright (C) 2000-8 The R Core Team |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, a copy is available at |
18 | | * https://www.R-project.org/Licenses/ |
19 | | * |
20 | | * DESCRIPTION |
21 | | * |
22 | | * The distribution function of the non-central F distribution. |
23 | | */ |
24 | | |
25 | | #include "nmath.h" |
26 | | #include "dpq.h" |
27 | | |
28 | | double pnf(double x, double df1, double df2, double ncp, |
29 | | int lower_tail, int log_p) |
30 | 0 | { |
31 | 0 | double y; |
32 | 0 | #ifdef IEEE_754 |
33 | 0 | if (ISNAN(x) || ISNAN(df1) || ISNAN(df2) || ISNAN(ncp)) |
34 | 0 | return x + df2 + df1 + ncp; |
35 | 0 | #endif |
36 | 0 | if (df1 <= 0. || df2 <= 0. || ncp < 0) ML_WARN_return_NAN; |
37 | 0 | if (!R_FINITE(ncp)) ML_WARN_return_NAN; |
38 | 0 | if (!R_FINITE(df1) && !R_FINITE(df2)) /* both +Inf */ |
39 | 0 | ML_WARN_return_NAN; |
40 | |
|
41 | 0 | R_P_bounds_01(x, 0., ML_POSINF); |
42 | | |
43 | 0 | if (df2 > 1e8) /* avoid problems with +Inf and loss of accuracy */ |
44 | 0 | return pnchisq(x * df1, df1, ncp, lower_tail, log_p); |
45 | | |
46 | 0 | y = (df1 / df2) * x; |
47 | 0 | return pnbeta2(y/(1. + y), 1./(1. + y), df1 / 2., df2 / 2., |
48 | 0 | ncp, lower_tail, log_p); |
49 | 0 | } |