'****************************************************** '* Computing the statistical functions * '* for one or two variables * '* * '* -------------------------------------------------- * '* REFERENCE: "Mathematiques et statistiques By H. * '* Haut, PSI Editions, France, 1981" * '* [BIBLI 13]. * '* -------------------------------------------------- * '* SAMPLE RUN: * '* * '* TUTORIAL * '* * '* 1. Define type of calculus:" * '* 1: Statistical functions for a set X(i) * '* 2: Statistical functions for a set X(i), Y(i) * '* * '* 2. Input number n of data * '* * '* 3. Input successively the n values X(i) [and Y(i)] * '* * '* Type of calculus (1 or 2): 2 * '* * '* Number of data: 5 * '* * '* 1 ? 1 12 * '* 2 ? 2 9 * '* 3 ? 3 7 * '* 4 ? 4 15 * '* 5 ? 5 6 * '* * '* * '* Mean of X(i)....................: 3 * '* * '* (n-1) standard deviation of X(i): 1.58113883 * '* (n) standard deviation of X(i): 1.41421356 * '* * '* (n-1) standard dev. of X mean...: .707106782 * '* (n) standard dev. of X mean...: .632455532 * '* * '* Mean of Y(i)....................: 9.80000000 * '* * '* (n-1) standard deviation of Y(i): 3.70135111 * '* (n) standard deviation of Y(i): 3.31058908 * '* * '* (n-1) standard dev. of Y mean...: 1.65529454 * '* (n) standard dev. of Y mean...: 1.48054045 * '* * '* * '* (n-1) covariance of X,Y.........: -1.5 * '* (n) covariance of X,Y.........: -1.2 * '* * '* Correlation coefficient.........: -.256307296 * '* * '****************************************************** 'Description: This program computes the usual statistical functions ' for a set of n variables X(i) or for a set of n pairs ' X(i), Y(i). defint i-n defdbl a-h,o-z cls print print " TUTORIAL" print print " 1. Define type of calculus:" print " 1: Statistical functions for a set X(i)" print " 2: Statistical functions for a set X(i), Y(i)" print print " 2. Input number n of data" print print " 3. Input successively the n values X(i) [and Y(i)]" print input " Type of calculus (1 or 2): ", nt print input " Number of data: ", n print dim X(n) if nt=2 then dim Y(n) 'read n data for i=1 to n print " "; i;" "; if nt=1 then input X(i) if nt=2 then input X(i), Y(i) next i 'call subroutine 1000 gosub 1000 'print results print print " Mean of X(i)....................: "; v1 print print " (n-1) standard deviation of X(i): "; a3 print " (n) standard deviation of X(i): "; a5 print print " (n-1) standard dev. of X mean...: "; v3 print " (n) standard dev. of X mean...: "; v5 print if nt=1 then end print " Mean of Y(i)....................: "; v2 print print " (n-1) standard deviation of Y(i): "; a4 print " (n) standard deviation of Y(i): "; a6 print print " (n-1) standard dev. of Y mean...: "; v4 print " (n) standard dev. of Y mean...: "; v6 print print print " (n-1) covariance of X,Y.........: "; v7 print " (n) covariance of X,Y.........: "; a7 print print " Correlation coefficient.........: "; v8 print end 1000 'Subroutine of statistical functions for 1 or 2 variables '***************************************************** '* INPUTS: * '* nt: type of calculus =1 for one variable * '* =2 for two variables * '* n: number of data X(i) [and Y(i) ] * '* OUTPUTS: * '* v1: mean of X(i) * '* v2: mean of Y(i) * '* v3: (n-1) standard deviation of v1 * '* v4: (n-1) standard deviation of v2 * '* v5: (n) standard deviation of v1 * '* v6: (n) standard deviation of v2 * '* v7: (n-1) covariance of X,Y * '* v8: correlation coefficient * '* a3: (n-1) standard deviation of X * '* a4: (n-1) standard deviation of Y * '* a5: (n) standard deviation of X * '* a6: (n) standard deviation of Y * '* a7: (n) covariance of X,Y * '***************************************************** v1=0# : v2=0# : v3=0# : v4=0# : v5=0# n1=n-1 : xnr=SQR(n) 'choose type of calculus if nt=2 then goto 500 'case of one set X(i) for i=1 to n v1=v1+X(i) v3=v3+X(i)^2 next i v6=v3-v1*v1/n v1=v1/n a3=SQR(v6/n1) : a5=SQR(v6/n) v5=a5/xnr : v3=a3/xnr return 500 'case of a set X(i), Y(i) for i=1 to n v1=v1+X(i) v2=v2+Y(i) v3=v3+X(i)^2 v4=v4+Y(i)^2 v5=v5+X(i)*Y(i) next i v6=v3-v1*v1/n v7=v4-v2*v2/n v8=v5-v1*v2/n v1=v1/n : v2=v2/n a3=SQR(v6/n1) : a4=SQR(v7/n1) a5=SQR(v6/n) : a6=SQR(v7/n) v7=v8/n1 : a7=v8/n v3=a3/xnr : v4=a4/xnr v5=a5/xnr : v6=a6/xnr if (a3=0) or (a4=0) then return 'correlation coefficient not defined v8=v8/(n*a5*a6) return 'end of file fstat.bas