📄 dcdflib.c
字号:
if(!(*pr < 0.0e0 || *pr > 1.0e0)) goto S200; if(!(*pr < 0.0e0)) goto S180; *bound = 0.0e0; goto S190;S180: *bound = 1.0e0;S190: *status = -6; return;S210:S200: if(*which == 4) goto S250;//// OMPR// if(!(*ompr < 0.0e0 || *ompr > 1.0e0)) goto S240; if(!(*ompr < 0.0e0)) goto S220; *bound = 0.0e0; goto S230;S220: *bound = 1.0e0;S230: *status = -7; return;S250:S240: if(*which == 1) goto S290;//// P + Q// pq = *p+*q; if(!(fabs(pq-0.5e0-0.5e0) > 3.0e0 * dpmpar ( &K1 ) ) ) goto S280; if(!(pq < 0.0e0)) goto S260; *bound = 0.0e0; goto S270;S260: *bound = 1.0e0;S270: *status = 3; return;S290:S280: if(*which == 4) goto S330;//// PR + OMPR// prompr = *pr+*ompr; if(!(fabs(prompr-0.5e0-0.5e0) > 3.0e0 * dpmpar ( &K1 ) ) ) goto S320; if(!(prompr < 0.0e0)) goto S300; *bound = 0.0e0; goto S310;S300: *bound = 1.0e0;S310: *status = 4; return;S330:S320: if(!(*which == 1)) qporq = *p <= *q;//// Select the minimum of P or Q// Calculate ANSWERS// if(1 == *which) {//// Calculating P// cumbin(s,xn,pr,ompr,p,q); *status = 0; } else if(2 == *which) {//// Calculating S// *s = 5.0e0; T5 = atol; T6 = tol; dstinv(&K2,xn,&K3,&K3,&K4,&T5,&T6); *status = 0; dinvr(status,s,&fx,&qleft,&qhi);S340: if(!(*status == 1)) goto S370; cumbin(s,xn,pr,ompr,&cum,&ccum); if(!qporq) goto S350; fx = cum-*p; goto S360;S350: fx = ccum-*q;S360: dinvr(status,s,&fx,&qleft,&qhi); goto S340;S370: if(!(*status == -1)) goto S400; if(!qleft) goto S380; *status = 1; *bound = 0.0e0; goto S390;S380: *status = 2; *bound = *xn;S400:S390: ; } else if(3 == *which) {//// Calculating XN// *xn = 5.0e0; T7 = zero; T8 = inf; T9 = atol; T10 = tol; dstinv(&T7,&T8,&K3,&K3,&K4,&T9,&T10); *status = 0; dinvr(status,xn,&fx,&qleft,&qhi);S410: if(!(*status == 1)) goto S440; cumbin(s,xn,pr,ompr,&cum,&ccum); if(!qporq) goto S420; fx = cum-*p; goto S430;S420: fx = ccum-*q;S430: dinvr(status,xn,&fx,&qleft,&qhi); goto S410;S440: if(!(*status == -1)) goto S470; if(!qleft) goto S450; *status = 1; *bound = zero; goto S460;S450: *status = 2; *bound = inf;S470:S460: ; } else if(4 == *which) {//// Calculating PR and OMPR// T12 = atol; T13 = tol; dstzr(&K2,&K11,&T12,&T13); if(!qporq) goto S500; *status = 0; dzror(status,pr,&fx,&xlo,&xhi,&qleft,&qhi); *ompr = one-*pr;S480: if(!(*status == 1)) goto S490; cumbin(s,xn,pr,ompr,&cum,&ccum); fx = cum-*p; dzror(status,pr,&fx,&xlo,&xhi,&qleft,&qhi); *ompr = one-*pr; goto S480;S490: goto S530;S500: *status = 0; dzror(status,ompr,&fx,&xlo,&xhi,&qleft,&qhi); *pr = one-*ompr;S510: if(!(*status == 1)) goto S520; cumbin(s,xn,pr,ompr,&cum,&ccum); fx = ccum-*q; dzror(status,ompr,&fx,&xlo,&xhi,&qleft,&qhi); *pr = one-*ompr; goto S510;S530:S520: if(!(*status == -1)) goto S560; if(!qleft) goto S540; *status = 1; *bound = 0.0e0; goto S550;S540: *status = 2; *bound = 1.0e0;S550: ; }S560: return;# undef atol# undef tol# undef zero# undef inf# undef one}//****************************************************************************80void cdfchi ( int *which, double *p, double *q, double *x, double *df, int *status, double *bound )//****************************************************************************80//// Purpose:// // CDFCHI evaluates the CDF of the chi square distribution.//// Discussion://// This routine calculates any one parameter of the chi square distribution // given the others.//// The value P of the cumulative distribution function is calculated // directly.//// Computation of the other parameters involves a seach for a value that// produces the desired value of P. The search relies on the// monotonicity of P with respect to the other parameters.//// The CDF of the chi square distribution can be evaluated // within Mathematica by commands such as://// Needs["Statistics`ContinuousDistributions`"]// CDF [ ChiSquareDistribution [ DF ], X ]//// Reference://// Milton Abramowitz and Irene Stegun,// Handbook of Mathematical Functions // 1966, Formula 26.4.19.//// Stephen Wolfram,// The Mathematica Book,// Fourth Edition,// Wolfram Media / Cambridge University Press, 1999.//// Parameters://// Input, int *WHICH, indicates which argument is to be calculated// from the others.// 1: Calculate P and Q from X and DF;// 2: Calculate X from P, Q and DF;// 3: Calculate DF from P, Q and X.//// Input/output, double *P, the integral from 0 to X of // the chi-square distribution. If this is an input value, it should// lie in the range [0,1].//// Input/output, double *Q, equal to 1-P. If Q is an input// value, it should lie in the range [0,1]. If Q is an output value,// it will lie in the range [0,1].//// Input/output, double *X, the upper limit of integration // of the chi-square distribution. If this is an input // value, it should lie in the range: [0, +infinity). If it is an output// value, it will be searched for in the range: [0,1.0D+300].//// Input/output, double *DF, the degrees of freedom of the// chi-square distribution. If this is an input value, it should lie// in the range: (0, +infinity). If it is an output value, it will be// searched for in the range: [ 1.0D-300, 1.0D+300].//// Output, int *STATUS, reports the status of the computation.// 0, if the calculation completed correctly;// -I, if the input parameter number I is out of range;// +1, if the answer appears to be lower than lowest search bound;// +2, if the answer appears to be higher than greatest search bound;// +3, if P + Q /= 1;// +10, an error was returned from CUMGAM.//// Output, double *BOUND, is only defined if STATUS is nonzero.// If STATUS is negative, then this is the value exceeded by parameter I.// if STATUS is 1 or 2, this is the search bound that was exceeded.//{# define tol (1.0e-8)# define atol (1.0e-50)# define zero (1.0e-300)# define inf 1.0e300 static int K1 = 1; static double K2 = 0.0e0; static double K4 = 0.5e0; static double K5 = 5.0e0; static double fx,cum,ccum,pq,porq; static unsigned long qhi,qleft,qporq; static double T3,T6,T7,T8,T9,T10,T11;//// Check arguments// if(!(*which < 1 || *which > 3)) goto S30; if(!(*which < 1)) goto S10; *bound = 1.0e0; goto S20;S10: *bound = 3.0e0;S20: *status = -1; return;S30: if(*which == 1) goto S70;//// P// if(!(*p < 0.0e0 || *p > 1.0e0)) goto S60; if(!(*p < 0.0e0)) goto S40; *bound = 0.0e0; goto S50;S40: *bound = 1.0e0;S50: *status = -2; return;S70:S60: if(*which == 1) goto S110;//// Q// if(!(*q <= 0.0e0 || *q > 1.0e0)) goto S100; if(!(*q <= 0.0e0)) goto S80; *bound = 0.0e0; goto S90;S80: *bound = 1.0e0;S90: *status = -3; return;S110:S100: if(*which == 2) goto S130;//// X// if(!(*x < 0.0e0)) goto S120; *bound = 0.0e0; *status = -4; return;S130:S120: if(*which == 3) goto S150;//// DF// if(!(*df <= 0.0e0)) goto S140; *bound = 0.0e0; *status = -5; return;S150:S140: if(*which == 1) goto S190;//// P + Q// pq = *p+*q; if(!(fabs(pq-0.5e0-0.5e0) > 3.0e0 * dpmpar ( &K1 ) ) ) goto S180; if(!(pq < 0.0e0)) goto S160; *bound = 0.0e0; goto S170;S160: *bound = 1.0e0;S170: *status = 3; return;S190:S180: if(*which == 1) goto S220;//// Select the minimum of P or Q// qporq = *p <= *q; if(!qporq) goto S200; porq = *p; goto S210;S200: porq = *q;S220:S210://// Calculate ANSWERS// if(1 == *which) {//// Calculating P and Q// *status = 0; cumchi(x,df,p,q); if(porq > 1.5e0) { *status = 10; return; } } else if(2 == *which) {//// Calculating X// *x = 5.0e0; T3 = inf; T6 = atol; T7 = tol; dstinv(&K2,&T3,&K4,&K4,&K5,&T6,&T7); *status = 0; dinvr(status,x,&fx,&qleft,&qhi);S230: if(!(*status == 1)) goto S270; cumchi(x,df,&cum,&ccum); if(!qporq) goto S240; fx = cum-*p; goto S250;S240: fx = ccum-*q;S250: if(!(fx+porq > 1.5e0)) goto S260; *status = 10; return;S260: dinvr(status,x,&fx,&qleft,&qhi); goto S230;S270: if(!(*status == -1)) goto S300; if(!qleft) goto S280; *status = 1; *bound = 0.0e0; goto S290;S280: *status = 2; *bound = inf;S300:S290: ; } else if(3 == *which) {//// Calculating DF// *df = 5.0e0; T8 = zero; T9 = inf; T10 = atol; T11 = tol; dstinv(&T8,&T9,&K4,&K4,&K5,&T10,&T11); *status = 0; dinvr(status,df,&fx,&qleft,&qhi);S310: if(!(*status == 1)) goto S350; cumchi(x,df,&cum,&ccum); if(!qporq) goto S320; fx = cum-*p; goto S330;S320: fx = ccum-*q;S330: if(!(fx+porq > 1.5e0)) goto S340; *status = 10; return;S340: dinvr(status,df,&fx,&qleft,&qhi); goto S310;S350: if(!(*status == -1)) goto S380; if(!qleft) goto S360; *status = 1; *bound = zero; goto S370;S360: *status = 2; *bound = inf;S370: ; }S380: return;# undef tol# undef atol# undef zero# undef inf}//****************************************************************************80void cdfchn ( int *which, double *p, double *q, double *x, double *df, double *pnonc, int *status, double *bound )//****************************************************************************80//// Purpose:// // CDFCHN evaluates the CDF of the Noncentral Chi-Square.//// Discussion://// This routine calculates any one parameter of the noncentral chi-square// distribution given values for the others.//// The value P of the cumulative distribution function is calculated // directly.//// Computation of the other parameters involves a seach for a value that// produces the desired value of P. The search relies on the// monotonicity of P with respect to the other parameters.//// The computation time required for this routine is proportional// to the noncentrality parameter (PNONC). Very large values of// this parameter can consume immense computer resources. This is// why the search range is bounded by 10,000.//// The CDF of the noncentral chi square distribution can be evaluated // within Mathematica by commands such as://// Needs["Statistics`ContinuousDistributions`"]// CDF[ NoncentralChiSquareDistribution [ DF, LAMBDA ], X ]//// Reference://// Milton Abramowitz and Irene Stegun,// Handbook of Mathematical Functions // 1966, Formula 26.5.25.//// Stephen Wolfram,// The Mathematica Book,// Fourth Edition,// Wolfram Media / Cambridge University Press, 1999.//// Parameters://// Input, int *WHICH, indicates which argument is to be calculated// from the others.// 1: Calculate P and Q from X, DF and PNONC;// 2: Calculate X from P, DF and PNONC;// 3: Calculate DF from P, X and PNONC;// 4: Calculate PNONC from P, X and DF.//// Input/output, double *P, the integral from 0 to X of // the noncentral chi-square distribution. If this is an input// value, it should lie in the range: [0, 1.0-1.0D-16).//// Input/output, double *Q, is generally not used by this // subroutine and is only included for similarity with other routines.// However, if P is to be computed, then a value will also be computed// for Q.//// Input, double *X, the upper limit of integration of the // noncentral chi-square distribution. If this is an input value, it// should lie in the range: [0, +infinity). If it is an output value,// it will be sought in the range: [0,1.0D+300].//// Input/output, double *DF, the number of degrees of freedom // of the noncentral chi-square distribution. If this is an input value,// it should lie in the range: (0, +infinity). If it is an output value,// it will be searched for in the range: [ 1.0D-300, 1.0D+300].//// Input/output, double *PNONC, the noncentrality parameter of // the noncentral chi-square distribution. If this is an input value, it// should lie in the range: [0, +infinity). If it is an output value,// it will be searched for in the range: [0,1.0D+4]//// Output, int *STATUS, reports on the calculation.// 0, if calculation completed correctly;// -I, if input parameter number I is out of range;// 1, if the answer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -