📄 ocn_g04.h
字号:
/*------------------------------------------------------------------------------*
* File Name: OCN_g04.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_G04_H
#define _O_NAG_G04_H
//#importdll "ONAG" // NAG DLL prepared by OriginLab
#pragma dll(ONAG)
#include <NAG\nag_types.h>
/* begin proto */
/** g04bbc
computes the analysis of variance and treatment means and standard
errors for a randomized block or completely randomized design
Example1:
Assume "Data1" Worksheet contains 7 columns and 36 rows and it is double type, "Data2" Worksheet
contains 2 columns and 36 rows and it is integer type. The first column contains 30 data in every
worksheet. The result will write in rest columns.
int n = 30, nt = 6, iblock = 10, tdc = 6, irdf = 0;
double tol = 5e-6;
double gmean;
//Attach 7 Datasets to 7 columns of "Data1".
Dataset dy("data1",0);
Dataset dbmean("data1",1);
Dataset dtmean("data1",2);
Dataset dtable("data1",3);
Dataset dc("data1",4);
Dataset dr("data1",5);
Dataset def("data1",6);
//Attach 2 Datasets to 2 columns of "Data2".
Dataset dit("data2",0);
Dataset direp("data2",1);
dy.SetSize(30);
dbmean.SetSize(10);
dtmean.SetSize(6);
dtable.SetSize(20);
dc.SetSize(36);
dit.SetSize(30);
dr.SetSize(30);
def.SetSize(6);
direp.SetSize(6);
vector y = dy, bmean = dbmean, tmean = dtmean, table = dtable, c = dc, r = dr, ef = def;
vector<int> it=dit, irep=direp;
BOOL sucess = nag_anova_random( n, y, Nag_SerialBlocks, iblock, nt, it, &gmean, bmean, tmean,
table, c, tdc, irep, r, ef, tol, irdf );
//put the result to the Worksheet "data1" and Worksheet "data2".
dbmean = bmean;
dtmean = tmean;
dtable = table;
dc = c;
dr = r;
def = ef;
dit = it;
direp = irep;
Example2:
The data, given by John and Quenouille (1977), is for a balanced incomplete block design with
10 blocks and 6 treatments and with 3 plots per block. The observations are the degree of pain
experienced and the treatments are penicillin of different potency.
void test_nag_anova_random()
{
double tmean[6];
double table[20];
double ef[6], r[30];
double gmean;
double tol = 5e-6;
double bmean[10];
double c[36];
int irep[6];
int irdf = 0;
int i, j;
int tdc = 6;
int sucess;
int n = 30, nt = 6, iblock = 10;
double y[30] = {1.00, 5.00, 4.00, 5.00, 10.00, 6.00, 2.00, 9.00, 3.00, 4.00,
8.00, 6.00, 2.00, 4.00, 7.00, 6.00, 7.00, 5.00, 5.00, 7.00, 2.00, 7.00,
2.00, 4.00, 8.00, 4.00, 2.00, 10.00, 8.00, 7.00};
int it[30] = {1, 2, 3, 1, 2, 4, 1, 3, 5, 1, 4, 6, 1, 5, 6, 2, 3, 6, 2, 4, 5,
2, 5, 6, 3, 4, 5, 3, 4, 6};
printf("the input data is following\n");
printf("n = 30, nt = 6, iblock = 10\n");
printf("y: \n");
for( i = 0; i < 30; i++)
{
printf("%f ",y[i]);
if((i + 1) % 10 == 0)
printf("\n");
}
printf("\nit:\n");
for(i = 0; i < 30; i++)
{
printf("%d ",it[i]);
if((i + 1) % 10 == 0)
printf("\n");
}
sucess = nag_anova_random(n, y, Nag_SerialBlocks, iblock, nt, it, &gmean, bmean, tmean,
table, c, tdc, irep, r, ef, tol, irdf);
if(sucess == 0)
{
printf("the function is called sucessfully\n\n\n");
printf("the results are the following:\n\n");
printf("ANOVA table\n");
printf(" Source df SS MS F Prob\n");
printf("Blocks ");
for(i = 0; i < 5; i++)
{
printf("%10.4f",table[i]);
}
printf("\nTreatments ");
for(i = 5; i < 10; i++)
{
printf("%10.4f",table[i]);
}
printf("\nResidual ");
for(i = 11; i < 14; i++)
{
printf("%10.4f",table[i]);
}
printf("\nTotal ");
for(i = 15; i < 17; i++)
{
printf("%10.4f",table[i]);
}
printf("\n\nEfficency Fators \n");
for(i = 0; i < 6; i++)
printf("%10.5f",ef[i]);
printf("\n\nGrand Mean%10.5f\n",gmean);
printf("\nTreatment Means\n");
for(i = 0; i < 6; i++)
printf("%10.5f", tmean[i]);
printf("\nthe standard erros of difference between means\n");
for( i = 1; i < 6; i++)
{
for( j = 0; j < i; j++)
printf("%10.5f",c[i*6+j]);
printf("\n");
}
}
else
printf("the function has not been called successfully");
}
The output is following:
the input data is following
n = 30, nt = 6, iblock = 10
y:
1.000000 5.000000 4.000000 5.000000 10.000000 6.000000 2.000000 9.000000 3.000000 4.000000
8.000000 6.000000 2.000000 4.000000 7.000000 6.000000 7.000000 5.000000 5.000000 7.000000
2.000000 7.000000 2.000000 4.000000 8.000000 4.000000 2.000000 10.000000 8.000000 7.000000
it:
1 2 3 1 2 4 1 3 5 1
4 6 1 5 6 2 3 6 2 4
5 2 5 6 3 4 5 3 4 6
the function is called sucessfully
the results are the following:
ANOVA table
Source df SS MS F Prob
Blocks 9.0000 60.0000 6.6667 4.7872 0.0039
Treatments 5.0000 101.7778 20.3556 14.6170 0.0000
Residual 20.8889 1.3926 0.0000
Total 29.0000 182.6667
Efficency Fators
0.00000 0.80000 0.80000 0.80000 0.80000 0.80000
Grand Mean 5.33333
Treatment Means
2.50000 7.25000 8.08333 5.91667 2.91667 5.33333
the standard erros of difference between means
0.83444
0.83444 0.83444
0.83444 0.83444 0.83444
0.83444 0.83444 0.83444 0.83444
0.83444 0.83444 0.83444 0.83444 0.83444
Return:
The function returns NAG error code, 0 if no error.
NE_BAD_PARAM(70): On entry, parameter blocks has illegal value.
NE_INT_ARG_LT(11): On entry, n must not be less than 2: n = _value_. On entry, nt must not be less than 1: nt = _value_. On entry, irdf must not be less than 0: irdf = _value_.
NE_REAL_ARG_LT(5): On entry, tol must not be less than 0.0: tol = _value_.
NE_INT(90): On entry, iblock = _value_. Constraint: iblock = 2when blocks = Nag NoBlocks. On entry, nt = _value_. Constraint: nt = 2when blocks = Nag NoBlocks.
NE_2_INT_ARG_LT(17): On entry, tdc = _value_ while nt = _value_. These parameters must satisfy tdc = nt.
NE_INT_2(91): On entry, n = _value_, iblock = _value_. Constraint: when iblock = 2, n must be a multiple of iblock.
NE_INTARR(111): On entry, it[_value_] = _value_. Constraint: 1 = it[i - 1] = nt, for i = 1, 2, . . . ,n.
NE_IT_ARRAY(533): No value of it[j - 1] = j for some j = 1, 2, . . . ,nt.
NE_ARRAY_CONSTANT(534): On entry, the elements of the array y are constant.
NE_G04BB_STDERR(535): A computed standard error is zero due to rounding errors. This is an unlikely error exit.
NE_G04BB_DESIGN(537): The design is disconnected; the standard errors may not be valid. The design may be nested.
NE_G04BB_TREAT(538): The treatments are totally confounded with blocks, so the treatment sum of squares and degrees of freedom are zero. The analysis of variance table is not computed, except for block and total sums of squares and degrees of freedom.
NE_G04BB_CONV(536): The eigenvalue computation has failed to converge. This is an unlikely error exit.
NE_G04BB_RES_DF(539): The residual degrees of freedom or the residual sum of squares are zero, columns 3, 4 and 5 of the analysis of variance table will not be computed and the matrix of standard errors and covariances, C, will not be scaled by s or the square of s.
NE_ALLOC_FAIL(73): Memory allocation failed.
successfully call of the nag_anova_random function.
*/
int nag_anova_random(
int n, //the number of observations n
const double y[], //the observations in the order as described by blocks and nt
Nag_Blocks blocks,
int iblock, //indicates the number of blocks
int nt, //indicates the number of treatments
int it[], //indicates the treatments used
double *gmean, //the grand mean
double bmean[], //if blocks = Nag SerialBlocks or Nag ParallelBlocks, bmean contains the mean for the jth block
double tmean[], //contains the mean of the treatments
double table[], // the analysis of variance table
double c[], // the variance/covariance matrix of the treatment effects
int tdc, //the second dimension of the array c
int irep[], //the treatment replications
double r[], //the residuals
double ef[], //the canonical efficiency factors
double tol, //the tolerance value used to check for zero eigenvalues of the matrix.
int irdf //an adjustment to the degrees of freedom for the residual and total
); // General block design or completely randomized design.
/** g04bcc
computes the analysis of variance for a general row and column design
together with the treatment means and standard error
Example:
The data for a 5 x 5 Latin square is inputted and the ANOVA and treatment means are computed and printed.
void test_nag_anova_row_col()
{
double c[25], c_b20 = 1e-5, cmean[5], ef[5], r[25], gmean;
double rmean[5], rpmean[1], tmean[5], table[30];
int irep[5], c_0 = 0, i, j;
int nrep = 1, nt = 5, nrow = 5, ncol = 5;
int sucess;
double y[25] = {6.67, 7.15, 8.29, 8.95, 9.62, 5.40, 4.77, 5.40, 7.54, 6.93,
7.32, 8.53, 8.50, 9.99, 9.68, 4.92, 5.00, 7.29, 7.85, 7.08, 4.88, 6.16,
7.83, 5.38, 8.51};
int it[25] = {5, 4, 1, 3, 2, 2, 5, 4, 1, 3, 3, 2, 5, 4, 1, 1, 3, 2, 5, 4, 4,
1, 3, 2, 5};
sucess = nag_anova_row_col(nrep, nrow, ncol, y, nt, it, &gmean, tmean, table, c,
nt, irep, rpmean, rmean, cmean, r, ef, c_b20, c_0);
if(sucess == 0)
{
printf("\nthe input data are following\n");
printf("nrep = 1, nt = 5, nrow = 5 , ncol = 5\n");
printf("y:\n");
for(i = 0; i < 25; i++)
{
printf("%3.2f ",y[i]);
if((i + 1) % 5 == 0)
printf("\n");
}
printf("it:\n");
for(i = 0; i < 25; i++)
{
printf("%d ",it[i]);
if((i + 1) % 5 == 0)
printf("\n");
}
printf("\n\n\n");
printf("ANOVA TABLE\n");
printf("Rows ");
for(i = 5; i < 10; i++)
{
if(i == 5)
printf("%3.0f ", table[i]);
else
printf("%6.4f ", table[i]);
}
printf("\nCloumns ");
for(i = 10; i < 15; i++)
{
if(i == 10)
printf("%3.0f ", table[i]);
else
printf("%6.4f ", table[i]);
}
printf("\nTreatments ");
for(i = 15; i <20; i++)
{
if(i == 15)
printf("%3.0f ", table[i]);
else
printf("%6.4f ", table[i]);
}
printf("\nResidual ");
for(i = 20; i <23; i++)
{
if(i == 20)
printf("%3.0f ", table[i]);
else
printf("%6.4f ", table[i]);
}
printf("\nTotal ");
for(i = 25; i < 27; i++)
{
if(i == 25)
printf("%3.0f ", table[i]);
else
printf("%6.4f ", table[i]);
}
printf("\nTreatment means\n");
for(i = 0; i < 5; i++)
printf("%10.4f", tmean[i]);
printf("\n\nS.E. of difference (orthogonal design) = %10.4f\n", c[5]);
}
else
printf("the function is not sucessfully called");
}
The output is following:
the input data are following
nrep = 1, nt = 5, nrow = 5 , ncol = 5
y:
6.67 7.15 8.29 8.95 9.62
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -