/* nag_anova_icc (g04gac) Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
*
* Mark 30.2, 2024.
*/
/* Pre-processor includes */
#include <nag.h>
#include <stdio.h>
int main(void) {
/* Integer scalar and array declarations */
Integer i, j, k, nrater, nsubj, t, nrep;
Integer exit_status = 0;
/* Nag Types */
NagError fail;
Nag_ICCModelType mtype;
Nag_ICCReliabilityType rtype;
Nag_MissingType mscore;
/* Double scalar and array declarations */
double alpha, clevel, df1, df2, fstat, icc, lci, pvalue, uci, smiss;
double *score = 0;
/* Character scalar and array declarations */
char crtype[40], cmtype[40], cmscore[40];
/* Initialize the error structure */
INIT_FAIL(fail);
printf("nag_anova_icc (g04gac) Example Program Results\n\n");
/* Skip heading in data file */
scanf("%*[^\n] ");
/* Read in the problem size */
scanf("%39s%39s%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", cmtype,
crtype, &nrep, &nsubj, &nrater);
mtype = (Nag_ICCModelType)nag_enum_name_to_value(cmtype);
rtype = (Nag_ICCReliabilityType)nag_enum_name_to_value(crtype);
/* Read in the values used to identify missing scores */
scanf("%39s%lf%*[^\n] ", cmscore, &smiss);
mscore = (Nag_MissingType)nag_enum_name_to_value(cmscore);
/* Allocate memory */
if (!(score = NAG_ALLOC(nsubj * nrater * nrep, double))) {
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
/* Read in the rating data */
for (k = 0; k < nrep; k++) {
for (i = 0; i < nsubj; i++) {
for (j = 0; j < nrater; j++) {
t = j * nrep * nsubj + i * nrep + k;
scanf("%lf", &score[t]);
}
scanf("%*[^\n] ");
}
}
/* Read in alpha for the confidence interval */
scanf("%lf%*[^\n] ", &alpha);
/* Call nag_anova_icc (g04gac) to calculate the intraclass correlation */
nag_anova_icc(mtype, rtype, nrep, nsubj, nrater, score, mscore, smiss, alpha,
&icc, &lci, &uci, &fstat, &df1, &df2, &pvalue, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_anova_icc (g04gac).\n%s\n", fail.message);
exit_status = -1;
if (fail.code != NW_POTENTIAL_PROBLEM)
goto END;
}
/* Display the results */
printf("Intraclass Correlation : %5.2f\n", icc);
clevel = 100.0 * (1.0 - alpha);
printf("Lower Limit for %4.1f%% CI : %5.2f\n", clevel, lci);
printf("Upper Limit for %4.1f%% CI : %5.2f\n", clevel, uci);
printf("F statistic : %5.2f\n", fstat);
printf("Degrees of Freedom 1 : %5.1f\n", df1);
printf("Degrees of Freedom 2 : %5.1f\n", df2);
printf("p-value : %5.3f\n", pvalue);
END:
NAG_FREE(score);
return (exit_status);
}