//find bound on tail probability using mgf, cutoff point returned to *cx REAL8 errbound(qfvars *vars, REAL8 u, REAL8* cx) { REAL8 sum1, x, y, xconst; (vars->count)++; //Increase counter xconst = u * vars->sigsq; //xconst = u * sigma**2 + sum{ } sum1 = u * xconst; //sum1 = u**2 * sigma**2 + sum{ } this is almost the equation after eq 9 in Davies 1973 //without the factor of 1/2 (applied at the end of this function) u *= 2.0; for (INT4 ii=vars->weights->length-1; ii>=0; ii--) { x = u * vars->weights->data[ii]; //x=2*u*lambda_j y = 1.0 - x; //y=1-2*u*lambda_j xconst += vars->weights->data[ii] * (vars->noncentrality->data[ii] / y + vars->dofs->data[ii]) / y; sum1 += vars->noncentrality->data[ii] * (x*x/(y*y)) + vars->dofs->data[ii] * (x*x / y + gsl_sf_log_1plusx_mx(-x)); } *cx = xconst; return exp1(-0.5 * sum1); }/* errbound() */
static VALUE Log_log_1px_mx(VALUE self, VALUE x) { return rb_float_new(gsl_sf_log_1plusx_mx(NUM2DBL(x))); }