# How do you perform a repeated measures anova in Genstat (and R)?

Genstat is a statistical package developed by plant scientists and geneticists to perform mainly analysis of variance. It has a limited repeated measures facility invoked by the AREPMEASURES procedure. Greenhouse-Geisser sphericity corrections, available using the menu interface or syntax, will only handle *one* repeated measures factor which it calls 'time'! this is probably due to the use of split-plot designs in plant science where due to the hierarchical nature of experiments since a particular tree, for example, can only be in one particular position in one particular plot. In psychology, by contrast, designs are often crossed in that each person will undergo each condition.

This means that you need to produce pooled means and differences using, for example, VECTOR and LOOP commands in SPSS before entering the data into Genstat. It follows you can only do this if no more than one factor has 3 or more levels.

The below gives an example of producing 204 pooled means for the factor, mags, by averaging two sets of two consecutive columns 408 columns apart that can be used to produce main effects in Genstat.

Notice the use of 'V' to designate column name and how useful it is for referring to columns in shorthand. Columns are numbered consecutively preceded by a 'V', by default, when reading an EXCEL file into SPSS and ignoring columns names.

DO REPEAT R=MAG1 TO MAG204. COMPUTE R=0.0. END REPEAT. EXE. VECTOR TEST = V1 TO V816/ MAG = MAG1 TO MAG204. LOOP #I = 1 TO 407 BY 2. COMPUTE MAG(0.5*(#I+1)) = MEAN(TEST(#I),TEST(#I+1),TEST(#I+408),TEST(#I+409)). END LOOP. EXE.

A similar approach will produce pooled differences that can be used to compute interaction terms using the one-way repeated measures procedure in Genstat. The example below uses two sets of adjacent columns 408 columns apart.

* ID/CON BY MAG INTERACTION WORKS AND AGREES WITH LONG WINDED COMPUTATIONS DO REPEAT R=MATDIFF1 TO MATDIFF204. COMPUTE R=0.0. END REPEAT. EXE. VECTOR TEST = V1 TO V816/ MATD = MATDIFF1 TO MATDIFF204. LOOP #I = 1 TO 407 BY 2. COMPUTE MATD(0.5*(#I+1)) = TEST(#I+1)+TEST(#I+409)-TEST(#I)-TEST(#I+408). END LOOP. EXE.

Other points to bear in mind:

- You can read EXCEL spreadsheets into Genstat
- A missing value in Genstat is denoted by an asterisk
- A trial version (for 30 days) is available which allows you unlimited access to Genstat in this period although no session may last longer than 30 minutes.
- You can specify factors in Genstat, or preferably, can put a ! in front of a column name which tells genstat that variable is a factor.
- Genstat PC version has a menu bar which enables easy data entry and use of the statistics procedures although the old syntax is still available for use if desired.

In MATLAB

ranova fits repeated measures ANOVAs in MATLAB.

Tom Gladwin has written some code for fitting repeated measures ANOVA which may be downloaded from here which fits all possible interactions using Matlab code. If the link is broken the code is also available from here. There are other MATLAB programs on this site for doing statistical analyses which may also be worth a look.

Aaron Schurger has MATLAB code here for the special case of two within subject factors.