SoftIntegration Demos for Ch NAG Statistics Package
Demos
Ch
Toolkit Demos
Ch Mechanism
Ch Control System
Ch CGI
Ch ODBC
ChExcel
C++ Library Demos
Graphical Library
Package Demos
Ch NAG Statistics

An application of using the original distribution of NAG library.

In a Ch shell or Ch IDE, run the following command:

ch g02brce.c < g02brce.d

You will get the output:


g02brc Example Program Results

Correlation coefficients:

 1.00000  0.85714  0.12849
 0.71429  1.00000  0.33040
 0.10287  0.41148  1.00000

The contents for files g02brce.c and g02brce.d are listed below.

/* nag_ken_spe_corr_coeff(g02brc) Example Program * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1993. */ #include <nag.h> #include <stdio.h> #include <nag_stdlib.h> #include <nagg02.h> #define NMAX 20 #define MMAX 20 int main(void) { Integer i, j, m, n, tdx, tdc; double x[NMAX][MMAX], corr[MMAX][MMAX]; Integer svar[MMAX], sobs[NMAX]; Integer *svarptr, *sobsptr; char s, w; tdx = MMAX; tdc = MMAX; Vprintf("g02brc Example Program Results\n"); /* Skip heading in data file */ Vscanf(" %*[^\n]"); /* Read data */ Vscanf("%ld%ld\n",&m,&n); if (m>=1 && m<=MMAX && n>=1 && n<=NMAX) { for (i=0; i<n; i++) for (j=0; j<m; j++) Vscanf("%lf",&x[i][j]); /* Read flag specifying if svar is to be supplied */ Vscanf(" %c",&s); if (s == 'S' || s == 's') { /* Assign pointer to svar and read in values for svar */ svarptr = svar; for (i=0; i<m; i++) Vscanf("%ld",&svar[i]); } else { /* Assign pointer to NULL and discard rest of line */ svarptr = (Integer *)0; Vscanf(" %*[^\n]"); /* skip rest of line */ } /* Read flag specifying if sobs is to be supllied */ Vscanf(" %c",&w); if (w == 'W' || w == 'w') { /* Assign pointer to sobs and read in values for sobs */ sobsptr = sobs; for (i=0; i<n; i++) Vscanf("%ld",&sobs[i]); } else { /* Assign pointer to NULL and discard rest of line */ sobsptr = (Integer *)0; Vscanf(" %*[^\n]"); /* skip rest of line */ } /* Calculate the Kendall and Spearman coefficients */ g02brc(n, m, &x[0][0], tdx, svarptr, sobsptr, &corr[0][0], tdc, NAGERR_DEFAULT); Vprintf("\nCorrelation coefficients:\n\n"); for (i=0; i<m; i++) { for (j=0; j<m; j++) Vprintf("%8.5f ", corr[i][j]); Vprintf("\n"); } } else { Vfprintf(stderr, "One or both of m and n are out of range:" " m = %-3ld while n = %-3ld\n", m, n); return EXIT_FAILURE; } return EXIT_SUCCESS; }

The content of file "g02brc.d" is as follows.

g02brc Example Program Data 3 7 1.0 2.0 4.0 7.0 7.0 3.0 2.0 3.0 4.0 4.0 4.0 5.0 5.0 6.0 7.0 3.0 1.0 3.0 6.0 5.0 5.0 s 1 1 1 w 1 1 1 1 1 1 1