' ******************************************************************
' Comparison of means for paired samples
' ******************************************************************

#INCLUDE "fbmath.bi"

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

' First sample
DIM AS DOUBLE X(1 TO N) = _
{9.2, 10, 9, 9.4, 10.1, 9.5, 10, 10.3, 10.2, 10.2, 9.8, 10.1}

' Second sample
DIM AS DOUBLE Y(1 TO N) = _
{9.5, 9, 8.8, 9.5, 9.1, 10, 10.1, 9.3, 9, 9.7, 9.1, 9.3}

DIM AS DOUBLE  MX, MY, SX, SY  ' Means and standard deviations
DIM AS DOUBLE  T               ' Student's t
DIM AS DOUBLE  WT, E           ' Wilcoxon's t and assoc. standard normal
DIM AS INTEGER Nd              ' Number of nonzero differences
DIM AS INTEGER DoF             ' Degrees of freedom
DIM AS DOUBLE  P               ' Probability
DIM AS DOUBLE  Tc, Ec          ' Critical values

MX = Mean(X())
MY = Mean(Y())
SX = StDev(X(), MX)
SY = StDev(Y(), MY)

' Compare means (parametric test)
StudPaired X(), Y(), T, DoF

' Compare means (non-parametric test)
Wilcoxon X(), Y(), Nd, WT, E

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

PRINT "                X          Y"
PRINT
PRINT "Mean     :"; : PRINT USING "######.####"; MX; MY
PRINT "St. dev. :"; : PRINT USING "######.####"; SX; SY

PRINT

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

PRINT

PRINT "Comparison of means (paired samples, non-parametric test)"
PRINT
PRINT USING "Wilcoxon's T               = ######.####"; WT
PRINT USING "Associated standard normal = ######.####"; E
PRINT USING "Critical value (p = #.###) = ######.####"; Alpha; Ec

SLEEP
