#include /* Header for input/output subroutines. */ #include /* Header for math subroutines. */ #include /* Header for floating point subroutines. */ #define pi 3.141592653589793238462643383279 /* Accurate value for pi. */ /* Simpson's rule for approximating integrals. a: left endpoint b: right endpoint fc: pointer to function to integrate n: number of subintervals */ double fc (double x); main() double a,b,h,sum,x,y,p,r,psum; /* In 'C' all variables must be assigned */ double p1, p2, p3; int i, n, o; printf("\007"); /* Sound bell in computer. */ a = (double) 0.0; /* The normalizing integral is */ b = (double) 1.0; /* from 0 to 1. */ n = 256; /* This has been tested and seen to give 5 decimal accuracy. */ printf("\n Enter number of points "); scanf("%d",&o); if (o < 5){ printf("Too few points"); return(o); p = (double) o; h = (double) (b-a)/n; for (i=1, sum=0.0; i<=n; i = i+ 2) p1 = fc((double) a+(i-1)*h, p); p2 = fc((double) a+i*h, p); p3 = fc((double) a+(i+1)*h, p); sum += p1 + 4.0 * p2 + p3; psum = (double) h*sum/3.0; /* This normalizes the integral */ /* For a given value of N, P\_N[|r|>=0] (must)) = 1.0 */ /* We assure this (and eliminate the need to compute some */ /* Gamma function) in computing the value in "psum." */ printf("\n Enter correlation coefficient r = "); scanf("%lf", &r); a = fabs((double) r); if (a > 1) a = (double) 1.0; /* r\_0 must be between -1 and 1. Force a to assume a value */ /* between 0 and 1. */ h = (double) (b-a)/n; for (i=1, sum=0.0; i<=n; i = i+ 2) p1 = fc((double) a+(i-1)*h, p); p2 = fc((double) a+i*h, p); p3 = fc((double) a+(i+1)*h, p); sum += p1 + 4.0 * p2 + p3; y = (double) h*sum/3.0; printf("\n Percentage probability that N measurements"); printf("\n of two uncorrelated variables would give an r"); printf("\n as large as r\_0, %.2lf, that is ", a); printf("\n P\_N[|r|>=r\_0] = %.2lf (per cent).", (double) 100.*y/psum); printf("\n If the number %.2lf is less than 5 (per cent),", 100.*y/psum); printf("\n then the correlation is called significant."); printf("\n If the number %.2lf is less than 1 (per cent),", 100.*y/psum); printf("\n then the correlation is call highly significant."); printf("\n Given this simple program and its speedy calculation"); printf("\n of the significance of a correlation in absolute terms,"); printf("\n we only have to plug in the number of data points and,"); printf("\n the value gotten from Pearson's correlation coefficient, r."); printf("\n"); return(0); double fc (double x, double p) double y; y = (double) pow((double)(1.0-x*x),(double) (p-4.0)/2.0); return (y); /* End of file */