"To illustrate finding a balanced incomplete block design
with seven treatments, five periods and 21 patients"
"This version updated February 2015 from that included in the book
to include various checks of design adequacy"
CAPTION 'Design of an incomplets blocks trial in asthma';STYLE=MAJOR
CAPTION 'Example 9.3 in Senn, Cross-over Trials in Clinical Research, 2nd edition pp 272-275';STYLE=STRESS
CAPTION 'This has seven treatments in five periods and 21 sequences';STYLE=NOTE
CAPTION 'Three orthogonal Latin squares';STYLE=STRESS
"Find three 7x7 orthogonal Latin Squares"
AGLATIN [PRINT=Design;ANALYSE=no]NROWS=7 ; NSQUARES=3;\
TREATMENTFACTORS=Treat; ROWS=Pat; COLUMNS=Period;\
Seed=270901
CAPTION 'These are used to construct an incomplete blocks design by dropping periods 6 & 7';STYLE=NOTE
"Construct incomplete blocks design from the squares"
VARIATE [NVALUES=49] Pat1,Pat2,Pat3
CALCULATE Pat1=Pat+0
& Pat2=Pat1+7
& Pat3=Pat2+7
APPEND [NEWVECTOR=Pat4]OLDVECTOR=Pat1,Pat2,Pat3
& [NEWVECTOR=Period] OLDVECTOR=Period,Period,Period
& [NEWVECTOR=Treat2] OLDVECTOR=Treat[1],Treat[2],Treat[3]
FACTOR [nvalues=147;levels=21]Patient; Values=Pat4
FACTOR [nvalues=147; levels=7; LABELS=!T(A,B,C,D,E,F,G)]\
Treatment;VALUES=Treat2
SUBSET [CONDITION=Period.LT.6]Treatment, Patient, Period
PAGE
CAPTION 'Incomplete blocks design: columns are periods, rows are patients';STYLE=STRESS
PRINT [ORIENTATION=across; RLPRINT=*;WIDTH=50;IPRINT=*]Treatment; FIELDWIDTH=10
"Check design"
PAGE
CAPTION 'Check design';STYLE=STRESS
TABULATE [PRINT=*; CLASSIFICATION=Patient,Treatment; MARGIN=yes;COUNTS=Table_1]
TABULATE [PRINT=*; CLASSIFICATION=Patient,Period; MARGIN=yes;COUNTS=Table_2]
TABULATE [PRINT=*; CLASSIFICATION=Treatment,Period; MARGIN=yes;COUNTS=Table_3]
CAPTION 'Treatments by patient'
PRINT Table_1;DECIMALS=0;FIELDWIDTH=8
CAPTION 'Periods by patient'
PRINT Table_2;DECIMALS=0;FIELDWIDTH=8
PAGE
CAPTION 'Periods by treatment'
PRINT Table_3;DECIMALS=0;FIELDWIDTH=8
"Convert treatment by patient table Table_1 to 21 by 7 matrix"
CALCULATE PatTrMatrix=TMATRIX(Table_1;Patient;Treatment)
"Declare 7 x 7 matrix to hold frequencies of treatment pairs"
MATRIX[ROWS=Treatment;COLUMNS=Treatment]MPairFreq;EXTRA='Frequency of treatment pairs'
"Multiply transpose of matrix (7x21) into matrix (21x7)"
CALCULATE MPairFreq=PRODUCT(T(PatTrMatrix);PatTrMatrix)
"Print result"
PRINT [IPRINT=Extra;VSPECIAL=0;TSPECIAL='']MPairFreq;DECIMALS=0;FIELDWIDTH=4
CAPTION 'Diagonal gives number of times treatment appears, off-diagonal gives pair frequency';\
STYLE=NOTE