' ******************************************************************
' Statistics: Concentration of hemoglobin in blood (mg/L) in men
' and women.
' ******************************************************************

#INCLUDE "fbmath.bi"

CONST N     = 30    ' Number of values
CONST Alpha = 0.05  ' Significance level

' Concentrations in men
DIM AS DOUBLE HbM(1 TO N) = _
{141, 144, 146, 148, 149, 150, 150, 151, 153, 153, _
 153, 154, 155, 156, 156, 160, 160, 160, 163, 164, _
 164, 165, 166, 168, 168, 170, 172, 172, 176, 179}

' Concentrations in women
DIM AS DOUBLE HbW(1 TO N) = _
{105, 110, 112, 112, 118, 119, 120, 120, 125, 126, _
 127, 128, 130, 132, 133, 134, 135, 138, 138, 138, _
 138, 142, 145, 148, 148, 150, 151, 154, 154, 158}

DIM AS DOUBLE  MM, MW, SM, SW    ' Means and standard deviations
DIM AS DOUBLE  SkM, SkW, KM, KW  ' Skewness and kurtosis
DIM AS DOUBLE  T, F              ' Student's t and Snedecor's F
DIM AS DOUBLE  U, E              ' Mann-Whitney's U and assoc. standard normal
DIM AS INTEGER DoF, DoF1, DoF2   ' Degrees of freedom
DIM AS DOUBLE  Tc, Fc, Ec        ' Critical values
DIM AS DOUBLE  P                 ' Probability

MM  = Mean(HbM())
MW  = Mean(HbW())
SM  = StDev(HbM(), MM)
SW  = StDev(HbW(), MW)
SkM = Skewness(HbM(), MM, SM)
SkW = Skewness(HbW(), MW, SW)
KM  = Kurtosis(HbM(), MM, SM)
KW  = Kurtosis(HbW(), MW, SW)

' Compare means and variances (parametric tests)
StudIndep N, N, MM, MW, SM, SW, T, DoF
Snedecor N, N, SM, SW, F, DoF1, DoF2

' Compare means (non-parametric test)
Mann_Whitney HbM(), HbW(), U, E

' Compute critical values
P = 1 - 0.5 * Alpha
Tc = InvStudent(DoF, P)
Fc = InvSnedecor(DoF1, DoF2, P)
Ec = InvNorm(P)

PRINT "Hemoglobin in blood"
PRINT
PRINT "                 Men     Women"
PRINT
PRINT "Mean     : "; : PRINT USING "######.####"; MM; MW
PRINT "St. dev. : "; : PRINT USING "######.####"; SM; SW
PRINT "Skewness : "; : PRINT USING "######.####"; SkM; SkW
PRINT "Kurtosis : "; : PRINT USING "######.####"; KM; KW

PRINT

PRINT "Comparison of means (parametric test):"
PRINT
PRINT USING "Student's t                = ######.####  (### DoF)"; T; Dof
PRINT USING "Critical value (p = #.###) = ######.####"; Alpha; Tc

PRINT

PRINT "Comparison of variances:"
PRINT
PRINT USING "Snedecor's F               = ######.####  (### and ### DoF)"; F; DoF1; DoF2
PRINT USING "Critical value (p = #.###) = ######.####"; Alpha; Fc
PRINT

PRINT "Comparison of means (non-parametric test):"
PRINT
PRINT USING "Mann-Whitney U             = ######.####"; U
PRINT USING "Associated standard normal = ######.####"; E
PRINT USING "Critical value (p = #.###) = ######.####"; Alpha; Ec

PRINT

SLEEP
