'****************************************************** '* Computing the means and moments * '* of a statistical variable * '* * '* -------------------------------------------------- * '* REFERENCE: "Mathematiques et statistiques By H. * '* Haut, PSI Editions, France, 1981" [13]* '* -------------------------------------------------- * '* SAMPLE RUN: * '* * '* TUTORIAL * '* * '* Means and moments of a statistical variable X(i) * '* with frequency F(i) * '* * '* 1. Input number n of data * '* * '* 2. Input successively the n values X(i) and F(i) * '* * '* Number of data: 3 * '* * '* 1 ? 1 6 * '* 2 ? 3 4 * '* 3 ? 5 8 * '* * '* Calculate generalized mean for t= 2 * '* * '* * '* Arithmetic mean: 3.22222222 * '* Geometric mean : 2.61023904 * '* Harmonic mean : 2.01492537 * '* * '* Moments: * '* * '* M1= 3.22222222 * '* M2= 3.06172840 * '* M3= -1.16323733 * '* M4= 12.56881570 * '* * '* Flatness coefficient....: 1.34079084 * '* Coefficient of asymmetry: -0.21712925 * '* * '* Gen. mean M(2): 3.66666667 * '* * '****************************************************** defint i-n defdbl a-h,o-z cls print print " TUTORIAL" print print " Means and moments of a statistical variable X(i)" print " with frequency F(i)" print print " 1. Input number n of data" print print " 2. Input sucessively the n values X(i) and F(i)" print input " Number of data: ", n print dim X(n), F(n) for i=1 to n print " ";i;" "; : input X(i), F(i) next i print input " Calculate generalized mean for t= ", t print gosub 1000 'print results cls f$="####.########" print print " Arithmetic mean: "; : print using f$; a print print " Geometric mean : "; : print using f$; g print if ite=1 then print " Harmonic mean undefined." else print " Harmonic mean : "; : print using f$; h end if print print " Moments:" print print " M1= "; : print using f$; xm1 print " M2= "; : print using f$; xm2 print " M3= "; : print using f$; xm3 print " M4= "; : print using f$; xm4 print print " Flatness coefficient....: "; : print using f$; ap print " Coefficient of asymmetry: "; : print using f$; asy print print " Gen. mean M(";t;"): "; : print using f$; xmt print END 1000 'Subroutine to calculate the means and moments of a ' statistical variable X(i) '***************************************************** '* INPUTS: * '* n: number of data X(i) and F(i) * '* X: n values X(i) * '* F: n values F(i), frequency of X(i) * '* t: coefficient of generalized mean M(t) * '* to calculate * '* OUTPUTS: * '* a: arithmetic mean of X(i) * '* g: geometric mean of X(i) * '* h: harmonic mean of X(i) * '* xm1: moment of first order * '* xm2: moment of second order * '* xm3: moment of third order * '* xm4: moment of fourth order * '* ap: flatness coefficient * '* asy: coefficient of assymetry * '* xmt: generalized mean M(t) * '* ite: test flag (if ite=1, harmonic mean h * '* is not defined * '***************************************************** ite=0 v1=0# : v2=0# : v3=0# : v4=0# v5=1# : v6=0# : v7=0# : xm=0# 'Calculate necessary sums for i=1 to n vt=F(i)*X(i) v1=v1+vt v2=v2+vt*X(i) v3=v3+vt*X(i)^2 v4=v4+vt*X(i)^3 xm=xm+F(i) v7=v7+F(i)*X(i)^t 'test for a X(i)=0 if X(i)=0 then ite=1 goto 100 end if 'if one X(i)=0, the harmonic mean is undefined 'and the geometric mean = 0 if ite=1 then goto 100 v5=v5*X(i)^F(i) v6=v6+F(i)/X(i) 100 next i 'prepare outputs a=v1/xm xmt=(v7/xm)^(1#/t) xm1=a xm2=(v2-2#*a*v1+a*a*xm)/xm xm3=(v3-3#*a*v2+3#*a*a*v1-xm*a^3)/xm xm4=(v4-4#*a*v3+6#*a*a*v2-4#*v1*a^3+xm*a^4)/xm ap=xm4/xm2/xm2 asy=xm3/(xm2^1.5#) if ite=1 then 'one X(i)=0 g=0# return end if g=v5^(1#/xm) h=xm/v6 return 'End of file moment.bas