inline double dcdflib_chi_n_quantile(double p, double df, double nc) { int what = 2; int status = 0; double x, bound, q(1 - p); cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound); return x; }
inline double dcdflib_chi_n_cdf(double x, double df, double nc) { int what = 1; int status = 0; double p, q, bound; cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound); return p; }
void V_cdfchn(int *which, double *p, double *q, double *x, double *df, double *pnonc, int *status, double *bound, int *len) { int i; for (i = 0; i < *len; i++) { cdfchn((int *)which, &p[i], &q[i], &x[i], &df[i], &pnonc[i], (int *)&status[i], &bound[i]); } }
static int cdf_pchisq (lua_State *L) { /* stack should contain x, df and opt. pnonc */ lua_Number x = luaL_checknumber(L, 1); lua_Number df = luaL_checknumber(L, 2); lua_Number pnonc = luaL_optnumber(L, 3, 0); lua_Number p, q, bound; int which = 1; int status; check_chisq(L, 1, x, df, pnonc); if (pnonc==0) /* central? */ cdfchi(&which, &p, &q, &x, &df, &status, &bound); else /* non-central */ cdfchn(&which, &p, &q, &x, &df, &pnonc, &status, &bound); check_status(status, bound); lua_pushnumber(L, p); return 1; }
static int cdf_qchisq (lua_State *L) { /* stack should contain p, df and opt. pnonc */ lua_Number p = luaL_checknumber(L, 1); lua_Number df = luaL_checknumber(L, 2); lua_Number pnonc = luaL_optnumber(L, 3, 0); lua_Number x; check_chisq(L, 2, p, df, pnonc); if (p==0 || p==1) x = (p==0) ? 0 : HUGE_VAL; else { lua_Number q = 1-p; lua_Number bound; int which = 2; int status; if (pnonc==0) /* central? */ cdfchi(&which, &p, &q, &x, &df, &status, &bound); else /* non-central */ cdfchn(&which, &p, &q, &x, &df, &pnonc, &status, &bound); check_status(status, bound); } lua_pushnumber(L, x); return 1; }