~ubuntu-branches/ubuntu/trusty/mricron/trusty-proposed

« back to all changes in this revision

Viewing changes to fpmath/demo/stat/av2a.pas

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2010-07-29 22:07:43 UTC
  • Revision ID: james.westby@ubuntu.com-20100729220743-q621ts2zj806gu0n
Tags: upstream-0.20100725.1~dfsg.1
ImportĀ upstreamĀ versionĀ 0.20100725.1~dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{ ******************************************************************
 
2
  Two-way analysis of variance (one observation per sample)
 
3
  ****************************************************************** }
 
4
 
 
5
program av2a;
 
6
 
 
7
uses
 
8
  tpmath;
 
9
 
 
10
const
 
11
  NA    = 3;            { Number of modalities of factor A }
 
12
  NB    = 4;            { Number of modalities of factor B }
 
13
  Alpha = 0.05;         { Significance level }
 
14
  Prob  = 1.0 - Alpha;  { Probability }
 
15
 
 
16
{ The samples are stored in a matrix Z, such that
 
17
  Z[I, J] contains the observation for the I-th
 
18
  modality of factor A and the J-th modality of factor B }
 
19
 
 
20
const
 
21
  Z : array[1..NA, 1..NB] of Float =
 
22
((2, 1, 3, 1),
 
23
 (3, 2, 3, 2),
 
24
 (3, 4, 5, 3));
 
25
 
 
26
var
 
27
  M : PMatrix;  { Means }
 
28
  S : PMatrix;  { Standard deviations }
 
29
 
 
30
  { Note: The S matrix does not need to be dimensioned if there is
 
31
    only one observation per sample. However, it must be declared. }
 
32
 
 
33
  V    : PVector;     { Variances (A, B, interaction) }
 
34
  DoF  : PIntVector;  { Degrees of freedom (A, B, interaction) }
 
35
  F    : PVector;     { Variance ratios (A, B) }
 
36
  Fc   : PVector;     { Critical values }
 
37
  I, J : Integer;     { Loop variables }
 
38
 
 
39
begin
 
40
  DimMatrix(M, NA, NB);  { Means }
 
41
  DimMatrix(S, NA, NB);  { Standard deviations }
 
42
  DimVector(V, 3);       { Variances (A, B, interaction) }
 
43
  DimIntVector(DoF, 3);  { Degrees of freedom (A, B, interaction) }
 
44
  DimVector(F, 2);       { Variance ratios (A, B) }
 
45
  DimVector(Fc, 2);      { Critical values }
 
46
 
 
47
  { Compare means. The matrix of means is equal to the data matrix.
 
48
    The matrix of standard deviations will be ignored. }
 
49
 
 
50
  for I := 1 to NA do
 
51
    for J := 1 to NB do
 
52
      M^[I]^[J] := Z[I,J];
 
53
 
 
54
  AnOVa2(NA, NB, 1, M, S, V, F, DoF);
 
55
 
 
56
  { Compute critical values }
 
57
  for I := 1 to 2 do
 
58
    Fc^[I] := InvSnedecor(DoF^[I], DoF^[3], Prob);
 
59
 
 
60
  { Print results }
 
61
  WriteLn('Two-way ANOVA');
 
62
  WriteLn;
 
63
  WriteLn('Source         Variance    D.o.F.     F      F(p = ', Alpha:4:2, ')');
 
64
  WriteLn('--------------------------------------------------------');
 
65
  WriteLn('Factor A     ', V^[1]:10:4, DoF^[1]:10, F^[1]:10:4, Fc^[1]:10:4);
 
66
  WriteLn('Factor B     ', V^[2]:10:4, DoF^[2]:10, F^[2]:10:4, Fc^[2]:10:4);
 
67
  WriteLn('Interaction  ', V^[3]:10:4, DoF^[3]:10);
 
68
end.
 
69