📄 ocn_g08.h
字号:
}
nag_mann_whitney(n1, x, n2, y, Nag_LowerTail, Nag_CompProbApprox, &u, &z, &p);
printf("\n\n");
printf("Test statistics =%8.4f\n", u);
printf("Normal statistics =%8.4f\n", z);
printf("Approximate tail probability =%8.4f\n", p);
nag_mann_whitney(n1, x, n2, y, Nag_LowerTail, Nag_CompProbExact, &u, &z, &p);
printf("Exact tail probability =%8.4f\n",p);
}
The output is following:
Sample size of group 1 = 16
Sample size of group 2 = 23
Mann-Whitney U test
Data values
Group 1 13.0 6.0 12.0 7.0 12.0 7.0 10.0 7.0
10.0 7.0 16.0 7.0 10.0 8.0 9.0 8.0
Group 2 17.0 6.0 10.0 8.0 15.0 8.0 15.0 10.0
15.0 10.0 14.0 10.0 14.0 11.0 14.0 11.0
13.0 12.0 13.0 12.0 13.0 12.0 12.0
Test statistics = 86.0000
Normal statistics = -2.8039
Approximate tail probability = 0.0025
Exact tail probability = 0.0020
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_mann_whitney(
int n1, // The number of non-tied pairs, n1>=1.
const double x[], // The first vector of observations.
int n2, // The size of the second sample, n2>=1.
const double y[], // The second vector of observations.
Nag_TailProbability tail, // Indicates choice of tail probability and hence the alternative hypothesis.
Nag_CompProb exact, // Indicates if exact probability is to be computed
double *u, // The returned Mann-Whitney rank sum statistic, U.
double *z, // The returned approximate Normal test statistic, z.
double *p // The returned exact tail probability, p, as specified by the parameter tail.
); // Performs the Mann-Whitney U test on two independent samples.
/** g08cbc
Performs the one-sample Kolmogorov-Smirnov test for standard distributions.
Example:
void test_nag_1_sample_ks_test()
{
double d, p, z;
int i, n, np, ntype;
Nag_TestStatistics ntype_enum;
n = 30;
double x[] ={0.01, 0.30, 0.20, 0.90, 1.20, 0.09, 1.30, 0.18, 0.90, 0.48,
1.98, 0.03, 0.50, 0.70, 0.07, 0.60, 0.95, 1.00, 0.31, 1.45,
1.04, 1.25, 0.15, 0.75, 0.85, 0.22, 1.56, 0.81, 0.57, 0.55};
np =2;
double par[] ={0.0, 2.0};
ntype = 1;
ntype_enum = Nag_TestStatisticsDAbs;
nag_1_sample_ks_test(n, x, Nag_Uniform, par, Nag_ParaSupplied, ntype_enum, &d, &z, &p);
printf("Test against uniform distribution on(0, 2)\n");
printf("Test statistics D = %8.4f\n", d);
printf("Z statistic = %8.4f\n", z);
printf("Tail probability = %8.4f\n", p);
np = 2;
par[0] = 0.0;
par[1] = 1.0;
ntype = 1;
ntype_enum = Nag_TestStatisticsDAbs;
nag_1_sample_ks_test(n, x, Nag_Normal, par, Nag_ParaEstimated, ntype_enum, &d, &z, &p);
printf("Test against Normal distribution with parameters estimated from the data\n");
printf("\n");
printf("Mean = %6.4f and varaince = %6.4f\n",par[0],par[1]);
printf("Test statistics D = %8.4f\n", d);
printf("Z statistic = %8.4f\n", z);
printf("Tail probability = %8.4f\n", p);
}
The output is following:
Test against uniform distribution on(0, 2)
Test statistics D = 0.2800
Z statistic = 1.5336
Tail probability = 0.0143
Test against Normal distribution with parameters estimated from the data
Mean = 0.6967 and varaince = 0.2564
Test statistics D = 0.1108
Z statistic = 0.6068
Tail probability = 0.8925
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_1_sample_ks_test(
int n, // The number of observations in the sample, n >= 3.
const double x[], // The sample observations x1, x2,...,xN.
Nag_Distributions dist, // The NAG distribution.
double par[], // Contains the known values of the parameter(s) of the null distribution.
Nag_ParaEstimates estima, // Specifies whether the values of the parameter(s) are known or estimated from data.
Nag_TestStatistics dtype, // The test statistic to be calculated...i.e. the choice of alternative hypothesis.
double *d, // The Kolmogorov-Smirnov test statistic.
double *z, // A standardized value, Z, of the test statistic, D, without correction for continuity.
double *p // The probability, P, associated with the observerd value of D.
); // Performs the one-sample Kolmogorov-Smirnov test for standard distributions.
/** g08cdc
Performs the two-sample Kolmogorov-Smirnov distribution test.
Example:
void test_nag_2_sample_ks_test()
{
double d, enda, endb, p, z;
int init, i, m, n, ntype;
Nag_TestStatistics ntype_enum;
double x[100], y[50];
n = 100;
m = 50;
init = 0;
enda = 0.0;
endb = 2.0;
for(i = 0; i < n; i++)
x[i] = enda +(endb -enda) * ran(init);
enda = 0.25;
endb = 2.25;
for(i = 0; i < m; i++)
y[i] = enda + (endb - enda) * ran(init);
ntype = 1;
ntype_enum = Nag_TestStatisticsDAbs;
nag_2_sample_ks_test(n, x, m, y, ntype_enum, &d, &z, &p);
printf("Test statistics D = %8.4f\n", d);
printf("Z statistic = %8.4f\n", z);
printf("Tail probability = %8.4f\n", p);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_2_sample_ks_test(
int n1, // The number of observations in the first sample, n1>=1.
const double x[], // The observations from the first sample.
int n2, // The number of observations in the second sample, n2>=1.
const double y[], // The observations from the second sample.
Nag_TestStatistics ntype, // The statistic to be computed or the choice of alternative hypothesis.
double *d, // The returned Kolmogorov-Smirnov test statistic according to the value of ntype.
double *z, // The returned standardized value, Z, of the test statistic, D, without correction for continuity.
double *p // The returned tail probability, P, associated with the observerd value of D.
); // Performs the two-sample Kolmogorov-Smirnov distribution test.
/** g08cgc
Performs the chi^2 goodness of fit test, for standard continuous distributions and for data
with a chosen number of class intervals.
Example:
void test_nag_chi_sq_goodness_of_fit_test()
{
double chisq, p, xmax, xmin;
int i, iclass, init, n, nclass, ndf, npest;
double x[100], cint[4], par[2] = {0.0, 1.0};
int ifreq[5];
double chisqi[5], eval[5], prob[5];
Nag_Distributions cdist_enum;
Nag_ClassBoundary class_enum;
n = 100;
nclass = 5;
cdist_enum = Nag_Uniform;
npest = 0;
init = 0;
for( i =0; i < n; i++)
x[i] = ran(init); //generate random variable from 0 to 1.
iclass = 1;
cint[0] = par[0] + (par[1] -par[0])/nclass;
for(i = 1; i < nclass -1; i++)
cint[i] = cint[i - 1] +(par[1] - par[0])/nclass;
class_enum = Nag_ClassBoundaryUser;
nag_frequency_table(n, x, nclass, class_enum, cint, ifreq, &xmin, &xmax);
nag_chi_sq_goodness_of_fit_test(nclass, ifreq, cint, cdist_enum, par, npest, prob, &chisq, &p, &ndf, eval, chisqi);
printf("\n");
printf("Chi-squared test statistic =%10.4f\n",chisq);
printf("Degrees of freedom. =%5ld\n", ndf);
printf("Significance level =%10.4f\n", p);
printf("\n");
printf("The contributions to the test statistic are :");
for(i = 0; i < nclass; i++)
printf("%10.4f\n", chisqi[i]);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_chi_sq_goodness_of_fit_test(
int k2, // The number of clsses, k2, into which the data is divided.
const int ifreq[], // ifreq[i-1] specifies the frequency of the ith class.
const double cint[], // cint[i-1] specifies the upper boundary value for the ith class, cint[i]<cint[i+1]. For exponential, gamma, and chi^2 cint[0]>=0..
Nag_Distributions dist, // The NAG distribution.
const double par[], // par[] specifies the parameters of the distribution being tested.
int iparam, // The number of estimated parameters of the distribution.
const double prob[], // If the user is supplying the probability distribution then prob[i-1] contains the probability that X lies in the ith class.
double *chisq, // The returned test statistic, chi^2, for the chi^2 goodness of fit test.
double *p, // The returned upper tail probability from the chi^2 distribution.
int *ndf, // Returns the degrees of freedom associated with test.
double eval[], // eval[i-1] contains the returned expected frequency for the ith class.
double chisqi[] // chisqi[i-1] contains the returned contribution from the ith class to the test statistic.
); // Performs the chi^2 goodness of fit test, for standard continuous distributions.
/** g08eac
Performs the runs up or runs down test on a sequence of observations.
Example:
void test_nag_runs_test()
{
double chi, df, p;
int i, init, max_run, n, nruns;
n = 10000;
double x[10000];
init =0;
for(i = 0; i < n; i++)
x[i] = ran(init); //generate random variable from 0 to 1.
max_run = 6;
nag_runs_test(n, x, max_run, &nruns, &chi, &df, &p);
printf("\n");
printf("Total number of runs found =%10ld\n" , nruns);
printf("chisq = %10.4f\n",chi);
printf("df = %10,4f\n",df);
printf("Prob = %10.4f\n", p);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_runs_test(
int n, // The length of the current sequence of observations, n>=3.
const double x[], // The sequence of observations.
int maxr, // The length of the longest run for which tabulation is desired, r. That is, all runs with length greater than or equal to r are counted together.
int *nruns, // The returned number of runs actually found.
double *chi, // The returned approximate chi^2 test statistic.
double *df, // The returned number of degrees of freedom of the chi^2 statistic.
double *prob // The returned upper tail probability corresponding to the chi^2 test statistic (i.e. significance level).
); // Performs the runs up or runs down test for randomness.
/** g08ebc
Performs the pairs (serial) test for randomness on a sequence of observations in the interval [0,1].
Example:
void test_nag_pairs_test()
{
double chi, df, p;
int i, max_count, n, init, lag;
init = 0;
n = 10000;
double x[10000];
for(i = 0; i < n; i++)
x[i] = ran(init); //generate random variable from 0 to 1.
max_count = 10;
lag =1;
nag_pairs_test(n, x, max_count, lag, &chi, &df, &p);
printf("\n\n");
printf("CHISQ = %10.4f\n",chi);
printf("DF = %8.2f\n", df);
printf("Probabitlity =%10.4f",p);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_pairs_test(
int n, // The number of observations, n>=2.
const double x[], // The sequence of observations in the interval [0,1].
int msize, // The size of the matrix of counts, m>=2.
int lag, // The lag, l, to be used in choosing pairs.
double *chi, // The returned chi^2 test statistic for testing the null hypothesis of randomness.
double *df, // The returned degrees of freedom for the chi^2 test statistic.
double *p // The returned upper tail probability associated with the chi^2 test statistic (i.e. significance level).
); // Performs the pairs (serial) test for randomness.
/** g08ecc
Performs the triplets test for randomness on a sequence of observations from the interval [0,1]..
Example:
void test_nag_triplets_test()
{
double chi, df, p;
int i, init, max_count, n;
n = 10000;
double x[10000];
for(i = 0; i < n; i++)
x[i] = ran(init); //generate random variable from 0 to 1.
max_count = 5;
nag_triplets_test(n, x, max_count, &chi, &df, &p);
printf("\n");
printf("CHISQ = %10.4f\n",chi);
printf("DF = %8.2f\n", df);
printf("Prob =%10.4f",p);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_triplets_test(
int n, // The number of observations, n>=3.
const double x[], // The sequence of observations in the interval [0,1].
int msize, // The size of the matrix of counts, m>=2.
double *chi, // The returned chi^2 test statistic for testing the null hypothesis of randomness.
double *df, // The returned degrees of freedom for the chi^2 test statistic.
double *p // The returned upper tail probability associated with the chi^2 test statistic (i.e. significance level).
); // Performs the triplets test for randomness.
/** g08edc
Performs the gaps test for randomness
Example:
void test_nag_gaps_test()
{
int i, init, max_gap, n, num_gaps;
double chi, df, lower, length, p, upper;
init = 0;
n = 5000;
double x[5000];
for(i = 0; i < n; i++)
x[i] = ran(init); //generate random variable from 0 to 1.
num_gaps = 0;
max_gap = 10;
length = 1.0;
lower = 0.4;
upper = 0.6;
nag_gaps_test(n, x, num_gaps, max_gap, lower, upper, length, &chi, &df, &p);
printf("\n");
printf("CHISQ = %10.4f\n",chi);
printf("DF = %8.2f\n", df);
printf("Prob =%10.4f",p);
}
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_gaps_test(
int n, // The length of the current sequence of observations, n>=1.
const double x[], // The sequence of observations.
int m, // The maximum number of gaps to be sought. If m<=0 then there is no limit placed on the number of gaps that are found.
int k, // The length of the longest gap for which tabulation is desired.
double rl, // The lower limit of the interval to be used to define the gaps (rl<ru and ru-rl<til).
double ru, // The upper limit of the interval to be used to define the gaps (ru>rl and ru-rl<til).
double til, // The total lengeth of the interval which contains all possible numbers that may arise in the sequence (til>0 and ru-rl<til).
double *chi, // The returned chi^2 test statistic for testing the null hypothesis of randomness.
double *df, // The returned degrees of freedom for the chi^2 test statistic.
double *prob // The returned upper tail probability associated with the chi^2 test statistic (i.e. significance level).
); // Performs the gaps test for randomness.
/* end proto */
#endif //!_O_NAG_G08_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -