📄 ocn_g01.h
字号:
/** g01blc
returns the lower tail, upper tail and point probabilities
associated with a hypergeometric distribution.
Example:
void test_nag_hypergeom_dist()
{
double plek, peqk, pgtk;
int sucess, i;
int n[4] = {10, 40, 155, 1000};
int l[4] = {2, 10, 35, 444};
int m[4] = {5, 3, 122, 500};
int k[4] = {1, 2, 22, 220};
printf(" the input data and results\n");
printf(" n l m k plek pgtk peqk\n");
for(i=0; i<4; i++)
{
sucess = nag_hypergeom_dist(n[i], l[i], m[i], k[i], &plek, &pgtk, &peqk);
if(sucess == 0)
printf("%4d %4d %4d %4d %6.5f %6.5f %6.5f \n",n[i], l[i], m[i], k[i], plek, pgtk, peqk);
else
break;
}
if(sucess != 0)
printf(" the function is not sucessfully called");
}
The ouput is following:
n l m k plek pgtk peqk
10 2 5 1 0.77778 0.22222 0.55556
40 10 3 2 0.98785 0.01215 0.13664
155 35 122 22 0.01101 0.98899 0.00779
1000 444 500 220 0.42429 0.57571 0.04913
Return:
The function returns NAG error code or 0 if no error.
NE_INT_ARG_LT(11): On entry, n, l, k, m must not be less than 0: n, l, k, m = _value_.
NE_2_INT_ARG_GT(19): On entry, l = _value_ while n = _value_. These parameters must satisfy l = n.
On entry, m = _value_ while n = _value_. These parameters must satisfy m = n.
On entry, k = _value_ while l = _value_. These parameters must satisfy k = l.
On entry, k = _value_ while m = _value_. These parameters must satisfy k = m.
NE_4_INT_ARG_CONS(30): On entry, k = _value_, l = _value_, m = _value_, n = _value_. These parameters must satisfy k = l + m - n.
NE_REAL_ARG_LT(5): On entry, n is too large to be represented exactly as a double precision number.
NE_VARIANCE_TOO_LARGE(411): On entry, the variance = lm(n - l)(n - m)/[(n^2)(n - 1)] exceeds 10^6.
NE_INTERNAL_ERROR(74): An internal error has occurred in this function. Check the function call and array sizes.
If the function call is correct, please consult NAG for assistance.
successfully call of the nag_hypergeom_dist function
*/
int nag_hypergeom_dist(
int n, // the parameter n of hypergeometric distribution
int l, // the parameter l of hypergeometric distribution
int m, // the parameter m of hypergeometric distribution
int k, // the integer k which defines the required probabilities
double *plek, // the lower tail probability
double *pgtk, // the upper tail probability
double *peqk // the point probability
); // Hypergeometric distribution function
/** g01cec
returns the deviate, xp, associated with the given lower tail
probability, p, of the standardized Normal distribution.
Example
The deviates corresponding to several lower tail probabilities from the
standard Normal distribution are calculated and printed.
void test_nag_deviates_normal_dist()
{
double x;
int i;
double p[5] = {0.950, 0.500, 0.995, 0.750, 0.001};
printf(" the input data and results\n");
printf("prob. Deviate\n");
for(i=0; i<5; i++)
{
x = nag_deviates_normal_dist(p[i]);
printf("%6.5f %6.5f\n",p[i], x);
}
}
The output is following:
prob. Deviate
0.95000 1.64485
0.50000 0.00000
0.99500 2.57583
0.75000 0.67449
0.00100 -3.09023
Return:
The function returns missing value (NANUM) if error occurs, 0 if no error.
NE_REAL_ARG_LE(6): On entry, p must not be less than or equal to 0.0: p = _value_.
NE_REAL_ARG_GE(8): On entry, p must not be greater than or equal to 1.0: p = _value_.
successfully call of the nag_deviates_normal_dist function.
*/
double nag_deviates_normal_dist(
double p, // the probablity, p, from the standardised Normal distribution
NagError* fail=NULL // NAG error structure
); // Deviate of Normal distribution function
/** g01ddc
calculates Shapiro and Wilk抯 W statistic and its significance level
for testing Normality.
Example:
A program to test the following 2 samples (each of size 20) for Normality.
void test_nag_shapiro_wilk_test()
{
double x[20];
double w, swap, minvalue, pw;
int i, j, k, sucess;
int min;
Boolean calwts;
double a[20] = {0.11, 7.87, 4.61, 10.14, 7.95, 3.14, 0.46, 4.43, 0.21, 4.75,
0.71, 1.52, 3.24, 0.93, 0.42, 4.97, 9.53, 4.55, 0.47, 6.66};
double b[20] = {1.36, 1.14, 2.92, 2.55, 1.46, 1.06, 5.27, -1.11, 3.48, 1.10,
0.88, -0.51, 1.46, 0.52, 6.20, 1.69, 0.08, 3.67, 2.81, 3.49};
// Sort the list.
test_sort(20,a);
printf("the input data \n");
printf("the first set\n");
for (i = 0; i < 20; i++)
{
printf("%3.2f ",a[i]);
if( (i+1) % 10 == 0)
printf("\n");
}
printf("the results as following \n");
calwts= true;
sucess = nag_shapiro_wilk_test(20, a, calwts, x, &w, &pw);
if(sucess == 0)
{
printf("value of W statistic = %5.4f\n",w);
printf("Significance level is %5.4f\n",pw);
}
else
{
printf("the function call is not sucessful");
}
// Sort the list.
test_sort(20,b);
printf("\n\n\nthe input data \n");
printf("the second set\n");
for (i = 0; i < 20; i++)
{
printf("%3.2f ",b[i]);
if( (i+1) % 10 == 0)
printf("\n");
}
printf("the results as following \n");
calwts= false;
sucess = nag_shapiro_wilk_test(20, b, calwts, x, &w, &pw);
if(sucess == 0)
{
printf("value of W statistic = %5.4f\n",w);
printf("Significance level is %5.4f\n",pw);
}
else
{
printf("the function call is not sucessful");
}
for(i = 0; i<20; i++)
printf("%4.2f\n",a[i]);
}
//This function is used to sort a list.
void test_sort(int n, double a[])
{
int i, j;
int min;
double swap, minvalue;
for(i = 0; i < n; i++)
{
min = i;
minvalue=a[i];
for(j = i+1; j < n; j++)
{
if(minvalue > a[j])
{
minvalue = a[j];
min = j;
}
}
if(min != i)
{
swap = a[i];
a[i] = a[min];
a[min] = swap;
}
}
}
The output is following:
For sample number 1, value of W statistic = 0.8992
Significance level is 0.0408
For sample number 2, value of W statistic = 0.9583
Significance level is 0.5171
Return:
The function returns NAG error code or 0 if no error.
NE_INT_ARG_LT(11): On entry, n must not be less than 3: n = _value_.
NE_REAL_ARG_GT(7): On entry, n must not be greater than 2000: n = _value_.
NE_NON_MONOTONIC(83): On entry, the sequence in array x is non-monotonic. First anomaly detected at x[_value_] = _value_.
NE_ALL_ELEMENTS_EQUAL(260): On entry, all the values in the array x must not be equal.
NE_INTERNAL_ERROR(74): An internal error has occurred in this function. Check the function call and array sizes.
If the function call is correct, please consult NAG for assistance.
successfully call of the nag_shapiro_wilk_test function.
*/
int nag_shapiro_wilk_test(
int n, // the sample size, 3 <= n <= 2000
const double x[], // the ordered sample values
Boolean calc_wts, // calculate weight or not
double a[], // weight
double* w, // the value of the statistics, W
double* pw // the significance level of W
); // Shapiro and Wilk's W test for Normality
/** g01dhc
computes the ranks, Normal scores, an approximation to the Normal
scores or the exponential scores as requested by the user.
Example:
void test_nag_ranks_and_scores()
{
int i;
double aa[5] = {2, 0, 2, 2, 0};
double bb[5];
nag_ranks_and_scores(Nag_SavageScores,Nag_AverageTies, 5, aa, bb);
printf("the input data\n");
for( i = 0; i < 5; i++)
printf("%4.0f ",aa[i]);
printf("\n\nthe results as following\n");
for(i = 0;i < 5;i++)
printf("%5.4f \n",bb[i]);
}
The output is following:
1.4500
0.3250
1.4500
1.4500
0.3250
Return:
The function returns NAG error code or 0 if no error.
NE_INT_ARG_LT(11): On entry, n must not be less than 1: n = _value_.
NE_BAD_PARAM(70): On entry, parameter scores has an illegal value. On entry, parameter ties has an illegal value.
NE_ALLOC_FAIL(73): Memory allocation failed.
NE_INTERNAL_ERROR(74): An internal error has occurred in this function. Check the function call and array sizes. If the function call is correct, please consult NAG for assistance.
successfully call of the nag_ranks_and_scores function
*/
int nag_ranks_and_scores(
Nag_Scores scores,
Nag_Ties ties,
int n, // the number of observations
const double x[], // the sample of observations, x[i]. i = 0,1,2,...,n
double r[] // output scores
); // Ranks, Normal scores, approximate Normal scores or exponential (Savage) scores
/** g01eac
returns a one or two tail probability for the standard distribution
Example:
Four values of tail and x are inputed and the probabilities are calculated and printed.
void test_nag_prob_normal()
{
double prob, x;
int i;
Nag_TailProbability tail;
char tail_char;
tail_char = 'L';
tail = Nag_LowerTail;
x = 1.96;
prob = nag_prob_normal(tail, x);
printf(" Tail X Probability\n");
printf(" %c %3.2f %5.4f\n",tail_char,x,prob);
tail_char = 'U';
tail = Nag_UpperTail;
prob = nag_prob_normal(tail, x);
printf(" %c %3.2f %5.4f\n",tail_char,x,prob);
tail_char = 'C';
tail = Nag_TwoTailConfid;
prob = nag_prob_normal(tail, x);
printf(" %c %3.2f %5.4f\n",tail_char,x,prob);
tail_char = 'S';
tail = Nag_TwoTailSignif;
prob = nag_prob_normal(tail, x);
printf(" %c %3.2f %5.4f\n",tail_char,x,prob);
}
The output is following:
Tail X Probability
L 1.96 0.9750
U 1.96 0.0250
C 1.96 0.9500
S 1.96 0.0500
Return:
The function returns missing value (NANUM) if error occurs, 0 if no error.
NE_BAD_PARAM(70): On entry, parameter tail has an illegal value.
successfully call of the nag_prob_normal function
*/
double nag_prob_normal(
Nag_TailProbability tail,
double x, // the value of the standard Normal variate
NagError* fail=NULL // NAG error structure
); // Probabilities for the standard Normal distribution
/** g01ebc
returns the lower tail,upper tail or two-tail probability for the
Student抯 t-distribution with real degrees of freedom.
Example:
Values from, and degrees of freedom for Student's t-distributions are read
along with the required tail. The probabilities are calculated and printed
until the end of data is reached.
void test_nag_prob_students_t()
{
double prob;
int i;
Nag_TailProbability tail[4] = {Nag_LowerTail, Nag_UpperTail, Nag_TwoTailSignif, Nag_TwoTailConfid};
double t[4] = {0.85, 0.85, 0.85, 0.85};
double df[4] = {20.0, 20.0, 20.0, 20.0};
printf(" t df prob tail\n");
for( i = 0; i < 4; i++)
{
prob = nag_prob_students_t(tail[i], t[i], df[i]);
if ( i == 0)
printf(" %4.3f %5.3f %5.4f Nag_LowerTail \n",t[i], df[i], prob);
if ( i == 1)
printf(" %4.3f %5.3f %5.4f Nag_UpperTail \n",t[i], df[i], prob);
if ( i == 2)
printf(" %4.3f %5.3f %5.4f Nag_TwoTailSignif \n",t[i], df[i], prob);
if ( i == 3)
printf(" %4.3f %5.3f %5.4f Nag_TwoTailConfid \n",t[i], df[i], prob);
}
}
The ouput results are following:
t df prob tail
0.850 20.000 0.7973 Nag_LowerTail
0.850 20.000 0.2027 Nag_UpperTail
0.850 20.000 0.4054 Nag_TwoTailSignif
0.850 20.000 0.5946 Nag_TwoTailConfid
Return:
The function returns missing value (NANUM) if error occurs, 0 if no error.
NE_BAD_PARAM(70): On entry, parameter tail has an illegal value.
NE_REAL_ARG_LT(5): On entry, df must not be less than 1.0: df = _value_.
successfully call of the nag_prob_students_t function
*/
double nag_prob_students_t(
Nag_TailProbability tail,
double t, // the value of the Student 抯 t variate
double df, // the degree of freedom
NagError* fail=NULL // NAG error structure
); // Probabilities for Student's t-distribution
/** g01ecc
returns the lower or upper tail probability for the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -