35#ifndef IS_RTKPP_LIBRARY
37#include "../include/STK_Funct_betaRatio.h"
38#include "../include/STK_Funct_gammaRatio.h"
39#include "../include/STK_Funct_raw.h"
43#define d2(z) (z/8. - 0.05)
44#define d3(z) (z*(z/48.-1./40.)+1./105.)
45#define d4(z) (z*(z*(z/384.-1./160.)+101./16800.)-3./1400.)
46#define d5(z) (z*(z*(z*(z/3840.-1./960.)+61./33600.)-13./8400.) \
48#define d6(z) (z*(z*(z*(z*(z/46080.-1./7680.)+143./403200.) \
49 -59./112000.)+7999./19404000.)-691./5255250.)
50#define d7(z) (z*(z*(z*(z*(z*(z/645120.-1./76800.)+41./806400.) \
51 -11./96000.)+5941./38808000.)-2357./21021000.)+6./175175.)
52#define d8(z) (z*(z*(z*(z*(z*(z*(z/10321920.-1./921600.)+37./6451200.) \
53 -73./4032000.)+224137./6209280000.)-449747./10090080000.) \
54 +52037./1681680000.)-10851./1191190000.)
79#ifdef STK_BETARATIO_DEBUG
80 stk_cout <<
_T(
"BetaRatio_ae(") << a <<
_T(
", ") << b <<
_T(
", ") << x <<
_T(
")\n");
184#ifdef STK_BETARATIO_DEBUG
185 stk_cout <<
_T(
"BetaRatio_sr(") << a <<
_T(
", ") << b <<
_T(
", ") << x <<
_T(
")\n");
188 Real s = a+b,
sx = s*x,
sy = s*(1-x);
190 Real bt = ( Const::_1_SQRT2PI_*sqrt((a*b)/s)
197 Real y = (0.5 - x) + 0.5;
198 if (
xm1) std::swap(x,
y);
206 sum += (
term = (
c *= (1.-b/n)*x) / (a+n));
232 if (n==1)
return b1(a, b, x,
xm1)/a;
237 int l = std::min(std::max(0, (
int)
round(
xm1 ? (
sy-a+1)/x : (
sx-a+1)/
x0)), n-1);
245 for (
int k=1; k<l; ++k) { sum1 = 1.+ sum1*(a+k)/((s+k-1)*x0);}
249 return b1(a+l, b, x, xm1) *(sum2/a0 + sum1);
268#ifdef STK_BETARATIO_DEBUG
269 stk_cout <<
_T(
"BetaRatio_up(") << a <<
_T(
", ") << b <<
_T(
", ") << x <<
_T(
")\n");
276 if (!
a0) { --n;
a0=1.;}
306#ifdef STK_BETARATIO_DEBUG
307 stk_cout <<
_T(
"BetaRatio_cf(") << a <<
_T(
", ") << b <<
_T(
", ") << x <<
_T(
")\n");
323 if (std::abs(
Dcur) > 4294967296.)
330 const Real x_4 =
xm1 ? (0.125 - x/4.) + 0.125 : x/4.;
332 const Real cte_b2 =
xm1 ? (a-1.)*(b+s-1.)*((0.25-x/2.)+0.25) : (a-1.)*(b+s-1.)*x/2.;
357 if (std::abs(
Dcur) > 4294967296.)
365 if (std::abs(
Ncur) > 4294967296.)
373 if (std::abs(
Dcur) != 0)
394static Real coefs_odd_se(std::vector<Real> &
A)
402 for (
int k=2; k<
l; k++)
408 Real res = -( A[2]*A[n]*(n-1.)
409 + 2* U2lp1 + (n+2.) * T2lp1
410 + A[l]*A[l] + (l+1.) * A[l+1]*A[l+1]
428static Real coefs_even_se( std::vector<Real> &A)
434 Real U2l =A[1]*A[n-1], T2l =0;
436 for (
int k=2; k<l; k++)
439 T2l += A[k+1] *A[n+1-k];
442 Real res = -(A[2]*A[n]*(n-1.) + 2.*U2l + (n+2.) * T2l ) / ((n+2.) * A[1]);
490#ifdef STK_BETARATIO_DEBUG
491 stk_cout <<
_T(
"BetaRatio_se(") << a <<
_T(
", ") << b <<
_T(
", ") << x <<
_T(
")\n");
494 Real s = a+b,
p = a/s, q = b/s,
sx = s*x,
sy = s-
sx;
509 std::vector<Real>
A,
B;
519 + (
A[4] * 4. * (2+
z2)
520 + (coefs_odd_se(
A) * 5. *
z * (3 +
z2)
521 + (coefs_even_se(
A) * 6. * (2*4 +
z2 * (4. +
z2))
522 + (coefs_odd_se(
A) * 7. *
z *(5*3 +
z2*(5 +
z2))
523 + (coefs_even_se(
A) * 8. * (2*4*6 +
z2 * (4*6 +
z2 *(6 +
z2)))
524 + (coefs_odd_se(
A) * 9. *
z * (7*5*3 +
z2 * (7*5 +
z2 * (7+
z2)))
525 + (coefs_even_se(
A) * 10. * (2*4*6*8 +
z2 * (4*6*8 +
z2 *(6*8 +
z2 * (8 +
z2))))
526 + (coefs_odd_se(
A) * 11. *
z * (9*7*5*3 +
z2 * (9*7*5 +
z2 * (9*7+
z2 * (9 +
z2))))
528 Real den =
a1 + (
A[3] + (
A[5] + (
A[7] + (
A[9] +
A[11] * 11./s) * 9./s)*7./s)*5./s)*3./s;
564 if (std::max(a,b)<=15)
580 if (std::min(a,b)<=1)
590 if ((std::min(a,b)<=60))
597 if ((x<0.97*
p)||(x>1.03*
p))
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Real dev0(Real const &a, Real const &b)
compute the partial deviance .
Real betaRatio_se(Real const &a, Real const &b, Real const &x, bool xm1, bool lower_tail)
Compute the incomplete beta function ratio I_x(a,b) using the serie expansion method.
Real betaRatio_ae(Real const &a, Real const &b, Real const &x, bool xm1, bool lower_tail)
Compute the incomplete beta function ratio I_x(a,b) using the asymptotic expansion method.
Real log1p(Real const &x)
compute the function .
Real betaRatio(Real const &a, Real const &b, Real const &x, bool lower_tail=true)
Compute the incomplete beta function ratio Compute the beta ratio function.
Real betaRatio_cf(Real const &a, Real const &b, Real x, bool xm1, bool lower_tail=true)
Compute the incomplete beta function ratio using the continued fraction method.
Real betaRatio_up(Real const &a, Real const &b, Real const &x, bool xm1, bool lower_tail)
Compute the incomplete beta function ratio I_x(a,b) using its recurrence formula and its asymptotic e...
Real betaRatio_sr(Real const &a, Real const &b, Real x, bool xm1, bool lower_tail)
Compute the incomplete beta function ratio I_x(a,b) using its series representation.
Real poisson_pdf_raw(Real const &x, Real const &lambda)
Compute the Poisson density.
Real lgammaStirlingError(Real const &z)
Compute the error when we compute using the Stirling's formula.
Real normal_cdf_raw(Real const &x)
Compute the cumulative distribution function of the normal density.
Real gammaRatioQ(Real const &a, Real const &x)
Compute the incomplete gamma function ratio Q(a,x).
Real gammaRatioP(Real const &a, Real const &x)
Compute the incomplete gamma function ratio P(a,x).
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
double Real
STK fundamental type of Real values.
Real betaRatio_raw(Real const &a, Real const &b, Real const &x, bool lower_tail)
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.
static Type NA()
Adding a Non Available (NA) special number.