📄 ocn_g04.h
字号:
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
it:
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
ANOVA TABLE
Rows 4 29.4231 7.3558 9.0266 0.0013
Cloumns 4 22.9950 5.7487 7.0545 0.0037
Treatments 4 0.5423 0.1356 0.1664 0.9514
Residual 12 9.7788 0.8149
Total 24 62.7392
Treatment means
7.3180 7.2440 7.2060 6.9000 7.2600
S.E. of difference (orthogonal design) = 0.5709
Return:
The function returns NAG error code, 0 if no error.
NE_INT_ARG_LT(11): On entry, nrep must not be less than 1: nrep = <value>. On entry, nrow must not be less than 2: nrow = <value>. On entry, ncol must not be less than 2: ncol = <value>. On entry, nt must not be less than 1: nt = <value>. On entry, irdf must not be less than 0: irdf = <value>.
NE_2_INT_ARG_LT(17): On entry, tdc = <value> while nt = <value>. These parameters must satisfy tdc >= nt.
NE_REAL_ARG_LT(5): On entry, tol must not be less than 0: tol = <value>.
NE_ARRAY_CONS(58): The contents of array it are not valid. Constraint: if nt >= 2, 1 <= it[i] <= nt, i = 0, 1, 2, ..., nrep*nrow*ncol. Constraint: some value of it = j for all j = 1, 2, ..., nt.
NE_ALLOC_FAIL(73): Memory allocation failed.
NE_ARRAY_CONSTANT(534): On entry, the elements of the array y are constant.
NE_G04BC_ST_ERR(543): A computed standard error is zero due to rounding errors, or the eigenvalue computation failed to converge. Both are unlikely errors.
NE_G04BC_REPS(544): The treatments are totally confounded with replicates, rows and columns, so the treatment sum of squares and degrees of freedom are zero. The analysis of variance table is not computed, except for replicate, row, column, total sum of squares and degrees of freedom.
NE_G04BC_RESD(545): 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.
NE_G04BC_DISCON(546): The design is disconnected, the standard errors may not be valid. The design may have a nested structure.
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 calll of the nag_anova_row_col function.
*/
int nag_anova_row_col(
int nrep, //the number of replicates.
int nrow, //the number of rows per replicate.
int ncol, //the number of columns per replicate.
const double y[], // the observation of the k column of the jth row of the ith replicate.
int nt, //the number of treatments
const int it[], // indicate which of the nt treatments unit i received, i = 1, 2, 3, ...., n.
double * gmean, //the grand mean.
double tmean[], //contains the (adjusted) mean for the lth treatment, l = 1, 2, 3, ..., nt.
double table[], //the analysis of variance table
double c[], // the variance/covariance matrix of the treatment effects.
int tdc, //the second dimension of c.
int irep[], //the treatment replications.
double rpmean[], //contains the mean for the ith replicate, i = 1, 2, ..., b.
double rmean[], //contains the mean for the jth row, j= 1, 2, ..., r.
double cmean[], //contains the mean for the kth column, k = 1, 2, ..., c.
double r[], //contains the residuals
double ef[], //the canonical efficiancy factor
double tol, //the tolerance value used to check for zero eigenvalue of the matrix Omega.
int irdf //an adjustment to the degrees of freedom for the residual and total.
); // Analysis of variance, general row and column design, treatment means and standard errors.
/** g04cac
computes an analysis of variance table and treatment means for a
complete factorial design.
Example:
These are the program data:
The data, given by John and Quenouille (1977), is for the yield of turnips (54 observation) for a
factorial experiment with two factors, the amount of phosphate with 6 levels and the amount of
liming with 3 levels. The design was replicated in 3 blocks.
void test_nag_anova_factorial()
{
double r[54];
double *bmean;
double *e;
double *semean;
double *table;
double *tmean;
int c__27 = 27;
int lfac[2] = {6, 3};
int *imean;
int mterm = 6;
int nfac, irdf;
int i, j, k, l, n;
int num;
int inter, nblock;
int itotal, ntreat;
n = 54;
nblock = 3;
nfac = 2;
inter = 2;
double y[54] = {274, 361, 253, 325, 317, 339, 326, 402, 336, 379, 345, 361,
352, 334, 318, 339, 393, 358, 350, 340, 203, 397, 356, 298, 382, 376, 355,
418, 387, 379, 432, 339, 293, 322, 417, 342, 82, 297, 133, 306, 352, 361,
220, 333, 270, 388, 379, 274, 336, 307, 266, 389, 333, 353};
irdf = 0;
nag_anova_factorial(n, y, nfac, lfac, nblock, inter, irdf, &mterm, &table, &tmean,
&c__27, &e, &imean, &semean, &bmean, r);
itotal = mterm;
printf("\n ANOVA table\n\n");
printf(" Source df SS MS F Prob\n\n");
k = 0;
if (nblock > 1)
{
++k;
printf("%s"," Blocks ");
for (j = 1; j <= 5; ++j)
printf("%10.2f ",table[((1)-1) * ( 5) + ((j)-1)]);
printf("\n");
}
ntreat = mterm - 2 - k;
for (i = 1; i <= ntreat; ++i)
{
printf("%s%2i "," Effect ",i);
for (j = 1; j <= 5; ++j)
printf("%10.2f ",table[((k+i)-1) * ( 5) + ((j)-1)]);
printf("\n");
}
printf("%s "," Residual ");
for (j = 1; j <= 3; ++j)
printf("%10.2f ",table[((mterm -1)-1) * ( 5) + ((j)-1)]);
printf("\n");
printf("%s "," Total ");
for (j = 1; j <= 2; ++j)
printf("%10.2f ",table[((mterm)-1) * ( 5) + ((j)-1)]);
printf("\n");
printf("\n");
printf(" Treatment Means and Standard Errors ");
printf("\n");
printf("\n");
k = 0;
for (i = 0; i < ntreat; ++i)
{
l = imean[i];
printf("%s%2i"," Effect ",i+1);
printf("\n");
printf("\n");
num=1;
for (j = k; j < l; ++j)
{
printf("%10.2f ",tmean[j]);
if(num % 8 == 0)
printf("\n");
num++;
}
printf("\n");
printf("\n%s%10.2f\n\n"," SE of difference in means = ",semean[i]);
k = l;
}
nag_anova_factorial_free(&table, &tmean, &e, &imean, &semean, &bmean);
}
The output is following:
ANOVA TABLE
Source df SS MS F Prob
Blocks 2.0000 30118.7778 15059.3889 7.6848 0.0018
Effect0 5.00 73008.17 14601.63 7.45 0.00
Effect1 2.00 21596.33 10798.17 5.51 0.01
Effect2 10.00 31191.67 3119.17 1.59 0.15
Residual 34.0000 66627.8889 1959.6438
total 53.0000 222542.8333
Treatment Means and Standard Errors
Effect 1
254.78, 339.00, 333.33, 367.78, 330.78, 360.67
SE of difference inm means = 20.87
Effect 2
334.28, 353.78, 305.11
SE of difference inm means = 14.76
Effect 3
235.33, 332.67, 196.33, 342.67, 341.67, 332.67, 309.33, 370.33,
320.33, 395.00, 370.33, 338.00, 373.33, 326.67, 292.33, 350.00,
381.00, 351.00
SE of difference in means = 36.14
Return:
The function returns NAG error code, 0 if no error.
NE_INT_ARG_LT(11): On entry, n must not be less than 4: n = _value_. On entry, nfac must not be less than 1: nfac = _value_. On entry, nblock must not be less than 0: nblock = _value_. On entry, inter must not be less than 0: inter = _value_. On entry, irdf must not be less than 0: irdf = _value_.
NE_2_INT_ARG_GT(19): On entry, inter = _value_ while nfac = _value_. These parameters must satisfy inter = nfac.
NE_INTARR(111): On entry, lfac[_value_] = _value_. Constraint: lfac[i - 1] = 2 for i = 1, 2, . . . ,nfac.
NE_INT_2(91): On entry, nblock = _value_, n = _value_. Constraint: n must be a multiple of nblock, when nblock > 1.
NE_PLOT_TREAT(541): The number of plots per block is not a multiple of the number of treatment combinations.
NE_ARRAY_CONSTANT(534): On entry, the elements of the array y are constant.
NE_G04CA_RES_DF(542): There are no degrees of freedom for the residual or the residual sum of squares is zero. In either case the standard errors and F-statistics cannot be computed.
NE_ALLOC_FAIL(73): Memory allocation failed.
successfully call of the nag_anova_factorial function.
*/
int nag_anova_factorial(
int n, // the number of observations
const double y[], // the observations in standard order
int nfac, // the number of factors
int lfac[], // the number of levels for the ith factor
int nblock, // the number of blocks
int inter, // the maximum number of factors in an interaction term, inter=0 or 1 if no interaction terms are computed.
int irdf, // the adjustment to the residual and total degrees of freedom
int *mterm, // the number of terms in the analysis of variance table
double **table, // the table of analysis of variance.
double **tmean, // contains the treatment means.
int *maxt, // the number of treatment means that have been computed.
double **e, // contains the estimated effects in the same order as for the means in tmean.
int **imean, // indicates the position of the e.ect means in tmean.
double **semean, // the standard error of the di.erence between means corresponding to the ith treatment effect in the ANOVA table.
double **bmean, // bmean[0] contains the grand mean, bmean[1] up to bmean[nblock] contain the block means.
double r[] // the residuals
); // Complete factorial design
/** g04czc
frees Nag allocated memory to some parameters in nag anova factorial
Example:
These are the program data:
The data, given by John and Quenouille (1977), is for the yield of turnips (54 observation) for a
factorial experiment with two factors, the amount of phosphate with 6 levels and the amount of
liming with 3 levels. The design was replicated in 3 blocks.
void test_nag_anova_factorial()
{
double r[54];
double *bmean;
double *e;
double *semean;
double *table;
double *tmean;
int c__27 = 27;
int lfac[2] = {6, 3};
int *imean;
int mterm = 6;
int nfac, irdf;
int i, j, k, l, n;
int num;
int inter, nblock;
int itotal, ntreat;
n = 54;
nblock = 3;
nfac = 2;
inter = 2;
double y[54] = {274, 361, 253, 325, 317, 339, 326, 402, 336, 379, 345, 361,
352, 334, 318, 339, 393, 358, 350, 340, 203, 397, 356, 298, 382, 376, 355,
418, 387, 379, 432, 339, 293, 322, 417, 342, 82, 297, 133, 306, 352, 361,
220, 333, 270, 388, 379, 274, 336, 307, 266, 389, 333, 353};
irdf = 0;
nag_anova_factorial(n, y, nfac, lfac, nblock, inter, irdf, &mterm, &table, &tmean,
&c__27, &e, &imean, &semean, &bmean, r);
itotal = mterm;
printf("\n ANOVA table\n\n");
printf(" Source df SS MS F Prob\n\n");
k = 0;
if (nblock > 1)
{
++k;
printf("%s"," Blocks ");
for (j = 1; j <= 5; ++j)
printf("%10.2f ",table[((1)-1) * ( 5) + ((j)-1)]);
printf("\n");
}
ntreat = mterm - 2 - k;
for (i = 1; i <= ntreat; ++i)
{
printf("%s%2i "," Effect ",i);
for (j = 1; j <= 5; ++j)
printf("%10.2f ",table[((k+i)-1) * ( 5) + ((j)-1)]);
printf("\n");
}
printf("%s "," Residual ");
for (j = 1; j <= 3; ++j)
printf("%10.2f ",table[((mterm -1)-1) * ( 5) + ((j)-1)]);
printf("\n");
printf("%s "," Total ");
for (j = 1; j <= 2; ++j)
printf("%10.2f ",table[((mterm)-1) * ( 5) + ((j)-1)]);
printf("\n");
printf("\n");
printf(" Treatment Means and Standard Errors ");
printf("\n");
printf("\n");
k = 0;
for (i = 0; i < ntreat; ++i)
{
l = imean[i];
printf("%s%2i"," Effect ",i+1);
printf("\n");
printf("\n");
num=1;
for (j = k; j < l; ++j)
{
printf("%10.2f ",tmean[j]);
if(num % 8 == 0)
printf("\n");
num++;
}
printf("\n");
printf("\n%s%10.2f\n\n"," SE of difference in means = ",semean[i]);
k = l;
}
nag_anova_factorial_free(&table, &tmean, &e, &imean, &semean, &bmean);
}
The output is following:
ANOVA TABLE
Source df SS MS F Prob
Blocks 2.0000 30118.7778 15059.3889 7.6848 0.0018
Effect0 5.00 73008.17 14601.63 7.45 0.00
Effect1 2.00 21596.33 10798.17 5.51 0.01
Effect2 10.00 31191.67 3119.17 1.59 0.15
Residual 34.0000 66627.8889 1959.6438
total 53.0000 222542.8333
Treatment Means and Standard Errors
Effect 1
254.78, 339.00, 333.33, 367.78, 330.78, 360.67
SE of difference inm means = 20.87
Effect 2
334.28, 353.78, 305.11
SE of difference inm means = 14.76
Effect 3
235.33, 332.67, 196.33, 342.67, 341.67, 332.67, 309.33, 370.33,
320.33, 395.00, 370.33, 338.00, 373.33, 326.67, 292.33, 350.00,
381.00, 351.00
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -