📄 ocn_g08.h
字号:
/*------------------------------------------------------------------------------*
* File Name: OCN_g08.h *
* Creation: SDB 5/22/2001 *
* Purpose: Origin C Header for NAG functions *
* Copyright (c) OriginLab Corp. 2001 *
* All Rights Reserved *
* *
* Modification Log: *
*------------------------------------------------------------------------------*/
#ifndef _O_NAG_G08_H
#define _O_NAG_G08_H
//#importdll "ONAG" // NAG DLL prepared by OriginLab
#pragma dll(ONAG)
#include <NAG\nag_types.h>
/* begin proto */
/** g08aac
Performs the Sign test on two related samples of size n.
Example:
void test_nag_sign_test()
{
double p;
double x[] = {4, 4, 5, 5, 3, 2, 5, 3, 1, 5, 5, 5, 4, 5, 5, 5, 5};
int i, s, n, non_tied;
n= 17;
double y[] ={2,3,3, 3,3,3,3,3,2,3,2,2,5,2,5,3,1};
printf("\nSign Test\n\n");
printf("Data values\n\n");
for(i =0; i < n; i++)
printf("%3.0f",x[i]);
printf("\n");
for(i =0; i < n; i++)
printf("%3.0f",y[i]);
printf("\n");
nag_sign_test(n, x, y, &s, &p, &non_tied);
printf("Test statistic %5ld\n",s);
printf("Observations %5ld\n",non_tied);
printf("Lower tail prob %5.3f\n",p);
}
The output is following:
Sign Test
Data values
4 4 5 5 3 2 5 3 1 5 5 5 4 5 5 5 5
2 3 3 3 3 3 3 3 2 3 2 2 5 2 5 3 1
Test statistic 3
Observations 14
Lower tail prob 0.029
Parameters:
Return:
This function returns NAG error code, 0 if no error.
successfully call of the nag_sign_test function.
*/
int nag_sign_test(
int n, // Size of each sample, n>=1.
const double x[], // Sample1 dataset, x[i-1] and y[i-1] must be set to ith pair of data values.
const double y[], // Sample2 dataset, x[i-1] and y[i-1] must be set to ith pair of data values.
int *s, // The returned Sign test statistic, S.
double *p, // The returned lower tail probability, p, corresponding to S.
int *non_tied // The returned number of non-tied pairs.
); // Sign test on two paired samples.
/** g08acc
Performs the Median test on two independent samples of possibly unequal size.
Example:
void test_nag_median_test()
{
double p;
int i, above, below, n1, n2;
n1 = 16;
n2 = 23;
double x[] = {13, 6, 12, 7, 12, 7, 10, 7, 10, 7, 10, 7, 10, 8, 9, 8}
double y[] = {17, 6, 16, 8, 15, 8, 15, 10, 15, 10, 14, 10, 14, 11, 14, 11,
13, 12, 13, 12, 13, 12, 12}
printf("\nMedian test\n\n");
printf("Data values\n\n");
printf(" Group1 ");
for(i = 0; i < n1; i++)
{
printf("%4.0f",x[i]);
if((i+1) % 8 == 0)
printf("\n ");
}
printf("\n Group2 ");
for(i = 0; i < n2; i++)
{
printf("%4.0f",y[i]);
if((i+1) % 8 == 0)
printf("\n ");
}
nag_median_test(n1, x, n2, y, &above, &below, &p);
printf("\n");
printf("%6ld scores below madian in group 1\n",above);
printf("%6ld scores below madian in group 2\n",below);
printf("\n Significance %8.5f\n", p);
}
The output is following:
Median test
Data values
Group1 13 6 12 7 12 7 10 7
10 7 10 7 10 8 9 8
Group2 17 6 16 8 15 8 15 10
15 10 14 10 14 11 14 11
13 12 13 12 13 12 12
13 scores below madian in group 1
6 scores below madian in group 2
Significance 0.00088
Parameter:
Return:
The function returns NAG error code, 0 if no error.
*/
int nag_median_test(
int n1, // The size of the first sample, n1>=1.
const double x[], // The data values of the first sample.
int n2, // The size of the second sample, n2>=1.
const double y[], // The data values of the second sample.
int *above, // The returned number of scores in the first sample which lie above the pooled median.
int *below, // The returned number of scores in the first sample which lie below the pooled median.
double *p // The returned tail probability, p, corresponding to the observed dichotomy of the two samples.
); // Median test on two samples of unequal size.
/** g08aec
Performs the Friedman two-way analysis of variance by ranks on k related samples of size n.
Example:
void test_nag_friedman_test()
{
double fr, sig;
int i, ix, j, k, n;
n = 18;
k =3;
ix =k;
double x[] = {1, 2, 1, 1, 3, 2, 3, 1, 3, 3, 2, 2, 3, 2, 2.5, 3, 3, 2,
3, 3, 3, 2, 1, 3, 2, 3, 1, 1, 3, 3, 2, 3, 2.5, 2, 2, 3,
2, 1, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1};
printf("\nData values\n");
printf("\n Group Group Group\n");
printf("\n 1 2 3\n");
for(j = 0; j < 18; j++)
{
for( i =0; i < 3; i++)
printf("%7.1f", x[i * 18 + j]);
printf("\n");
}
nag_friedman_test(k, n, x, n, &fr, &sig);
printf("\n");
printf("Test statistics %6.3f\n", fr);
printf("Degrees of freedom %6ld\n", k-1);
printf("Significance %6.3f\n ", sig);
}
The output is following:
Data values
Group Group Group
1 2 3
1.0 3.0 2.0
2.0 3.0 1.0
1.0 3.0 2.0
1.0 2.0 3.0
3.0 1.0 2.0
2.0 3.0 1.0
3.0 2.0 1.0
1.0 3.0 2.0
3.0 1.0 2.0
3.0 1.0 2.0
2.0 3.0 1.0
2.0 3.0 1.0
3.0 2.0 1.0
2.0 3.0 1.0
2.5 2.5 1.0
3.0 2.0 1.0
3.0 2.0 1.0
2.0 3.0 1.0
Test statistics 8.583
Degrees of freedom 2
Significance 0.014
Parameter:
Return:
NAG error code, 0 if no error.
*/
int nag_friedman_test(
int k, // The number of samples, k>1.
int n, // The size of each sample, n>=1.
const double x[], // Two dimension array (x[k,tdx]) of all data points where x[i-1][j-1] is the jth observation in sample i.
int tdx, // The first dimension of x as declared in the function from which nag_friedman_test is called.
double *fr, // The returned value of the Friedman test statistic, FR.
double *p // The returned approximate significance, p, of the Friedman test statistic.
); // Friedman two-way analysis of variance on k matched samples.
/** g08afc
Performs the Kruskal-Wallis one-way analysis of variance by ranks on k independent samples
of possibly unequal sizes.
Example:
void test_nag_kruskal_wallis_test()
{
double h, p;
int count, i, ii, k, lx, nhi, ni, nlo;
k =5;
int l[] = { 5, 8, 6, 8, 8};
printf("\n");
printf("Kruskal_wallis test");
printf("\n");
printf("Data values \n\n");
printf(" Group Observations\n");
lx = 0;
for(i =0; i < 5; i++)
lx +=l[i];
double x[] = {23, 27, 26, 19, 30, 29, 25, 33, 36, 32,
28, 30, 31, 38, 31, 28, 35, 33, 36, 30,
27, 28, 22, 33, 34, 34, 32, 31, 33, 31,
28, 30, 24, 29, 30};
nlo = 1;
for(i = 0; i < k; i++)
{
ni = l[i];
nhi = nlo + ni - 1;
printf("%5ld ", i);
count = 1;
for( ii = nlo; ii <= nhi; ii++)
{
printf("%4.0f",x[ii -1]);
if(count % 10 == 0)
printf("\n");
}
nlo +=ni;
printf("\n");
}
nag_kruskal_wallis_test(k, l, x, lx, &h, &p);
printf("\n");
printf("\n");
printf("Test statistics %6.3f\n",h);
printf("Degrees of freedom %6ld\n", k-1);
printf("Significance %6.3f\n ",p);
}
The output is following:
Data values
Group Observations
0 23 27 26 19 30
1 29 25 33 36 32 28 30 31
2 38 31 28 35 33 36
3 30 27 28 22 33 34 34 32
4 31 33 31 28 30 24 29 30
Test statistics 10.537
Degrees of freedom 4
Significance 0.032
Parameters:
Return:
This function returns NAG error code, 0 if no error.
successfully call of the nag_kruskal_wallis_test function.
*/
int nag_kruskal_wallis_test(
int k, // The number of samples, k>=2.
const int l[], // l[i-1] contains the number of observations in sample i.
const double x[], // Contains the observations in k groups each having l[i-1] scores (e.g. The first l[0] elements contain the scores in the first group, etc.)
int lx, // The total number of observations, N.
double *h, // The returned value of the Kruskal-Wallis statistic, H.
double *p // The returned approximate significance, p, of the Kruskal-Wallis test statistic.
); // Kruskal-Wallis one-way analysis of variance on k samples of unequal size.
/** g08agc
Performs the Wilcoxon one-sample (matched pairs) signed rank test.
Example:
void test_nag_wilcoxon_test()
{
double median, p, w, z;
int i, n, non_zero;
double data[8];
n = 8;
double x[] = {82, 69, 73, 43, 58, 56, 76, 65};
double y[] = {63, 42, 74, 37, 51, 43, 80, 62};
printf("\n\n");
printf("Wilcoxon one sample signed ranks test");
printf("\n");
printf("Data Values \n");
for(i = 0; i < n; i++)
printf("%5.1f", x[i]);
printf("\n");
for(i = 0; i < n; i++)
printf("%5.1f", y[i]);
printf("\n");
for(i = 0; i < n; i++)
data[i] = x[i] -y[i];
median = 0.0;
nag_wilcoxon_test(n, data, median, Nag_TwoTail, Nag_IncSignZerosN, &w, &z, &p, &non_zero);
printf("\n");
printf("Test statistics =%8.4f\n",w);
printf("Normalized test statistics =%8.4f\n", z);
printf("Degree of freedom =%8ld\n",non_zero);
printf("Two tail probability =%8.4f\n", p);
}
The output is following:
Wilcoxon one sample signed ranks test
Data Values
82.0 69.0 73.0 43.0 58.0 56.0 76.0 65.0
63.0 42.0 74.0 37.0 51.0 43.0 80.0 62.0
Test statistics = 32.0000
Normalized test statistics = 1.8904
Degree of freedom = 8
Two tail probability = 0.0547
Parameters:
Return:
This function returns NAG error code, 0 if no error.
*/
int nag_wilcoxon_test(
int n, // The size of the sample, n>=1.
const double x[], // The sample observations.
double median, // The median test value.
Nag_TailProbability tail, // Indicates choice of tail probability and hence the alternative hypothesis.
Nag_IncSignZeros zeros, // Indicates whether or not to include cases where di=0.0 when ranking di's.
double *rs, // The returned Wilcoxon rank sum statistic, W, being the sum of the positive ranks.
double *rsnor, // The returned approximate Normal test statistic, z.
double *p, // The returned tail probability, p, as specified by the parameter tail.
int *nz1 // The returned number of non-zero di's.
); // Performs the Wilcoxon one-sample (matched pairs) signed rank test.
/** g08amc
Performs the Mann-Whitney U test on two independent samples of possibly unequal size
and calculates the exact probability for the Mann-Whitney rank sum test statistic for
the case where there are either ties or no ties in the samples pooled together.
Example:
void test_nag_mann_whitney()
{
double p, u, z;
int i , n1, n2;
n1 = 16;
n2 = 23;
printf("Sample size of group 1 = %5ld\n", n1);
printf("Sample size of group 2 = %5ld\n", n2);
double x[] ={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};
printf("Mann-Whitney U test\n");
printf("Data values\n");
printf(" Group 1 ");
for(i = 0; i < n1; i++)
{
printf("%5.1f",x[i]);
if((i + 1) % 8 == 0)
printf("\n");
}
double y[] ={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};
printf("\n Group 2 ");
for(i = 0; i < n2; i++)
{
printf("%5.1f",y[i]);
if((i + 1) % 8 == 0)
printf("\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -