# Using R's aov() for two-way repeated-measurement ANOVA

We analyze blood vessel samples of patients in an organ bath which gives us force values. Each subject (patient) donates two types of blood vessels (pulmonary vein and pulmonary artery). The organ bath measurements include dose-response curves with a pharmaceutical, i.e. different concentrations are applied. From what I understand, this should be analyzed using a two-way RM ANOVA test. There are two variables (vessel type and concentration), and all levels of both are applied to each subject. The data table looks like this:

subject  vessel  conc  force
20110818 PA      -12   0
20110818 PV      -12   0
20110818 PA      -11   0.09
20110818 PV      -11   0.15
...


There are no missing values or anything like that to consider.

Perusing several R tutorials, I came up with the following query:

aov.ex2=aov(force~(vessel*conc)+Error(subject/(vessel*conc)),data=data.ex2)


However, the results are somewhat unclear to me:

> summary(aov.ex2)

Error: subject
Df Sum Sq Mean Sq F value Pr(>F)
Residuals  1 15.370  15.370

Error: subject:vessel
Df Sum Sq Mean Sq
vessel  1 166.72  166.72

Error: subject:concentration
Df Sum Sq Mean Sq
concentration  1 3134.3  3134.3

Error: subject:vessel:concentration
Df Sum Sq Mean Sq
vessel:concentration  1 148.32  148.32

Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 219   3031  13.840


This is quite a lot of information, but in contrast to the nice examples on the web I can't seem to find the useful part of the information: p values and whether or not there are significant differences. Is there something wrong with my input, or does the result simply mean there is nothing interesting to see in these data?

• An output of "str(data.ex2)" would be helpful. This is because if "subject", "concentration" and "vessel" are not factors, aov will give strange numbers (particularly subject and concentration in this instance). – Matt Albrecht Nov 18 '11 at 13:32
• > str(data.ex2) 'data.frame': 224 obs. of 4 variables: $subject : int 20110818 20110818 20110818 20110818 20110818 20110818 20110818 20110818 20110818 20110818 ...$ vessel : Factor w/ 2 levels "PA","PV": 1 1 1 1 1 1 1 1 1 1 ... $concentration: num -12 -11 -10.5 -10 -9.5 -9 -8.5 -8 -7.5 -7 ...$ force : num 0 -1.2425 -1.4525 -1.755 0.0925 ... – mhoenicka Nov 18 '11 at 14:38

You don't get any p-values or f-values because you don't have an error term. You don't have an error term because there are no discrete replicates of your measures. Either get get more than one subject or make your subject a factor.

data.ex2$subject <- factor(data.ex2$subject)


Also, as is typical with ANOVA's you might want your predictors to be categorical (but maybe not). Something like...

data.ex2$conc <- factor(data.ex2$conc)

• I'm afraid my data description was too terse as I didn't want to post the entire data table. Of course there are several subjects included (n=8), and a total of 14 different concentrations. I just wanted to sketch the layout. I can post the entire data somewhere if that makes things clearer – mhoenicka Nov 18 '11 at 14:34
• As for the categorical predictors, this is pretty much right. I use the numbers as mere labels but I was not aware that R would treat them as numerical data. In any case, after using factor there are still no p values. – mhoenicka Nov 18 '11 at 14:46
• Now if I combine the helpful comments above, I seem to arrive at a result. The main problem appears to be that I (ab)use integers as subject names and integers as labels for the concentration. After converting both subject and concentration into factors, I get more reasonable output. Thanks everyone for their help. – mhoenicka Nov 18 '11 at 14:52
• I don't think you read my answer carefully because it included the argument that you don't have "discrete" subjects and that you had to factor it. I mentioned the number of them because it can also cause this issue. Regardless... glad you got it working. – John Nov 18 '11 at 15:08
• @mhoenicka Your last comment suggest that John was right which makes this response eligible for the "green mark" (i.e., you can check this answer as accepted since it solved your problem). – chl Nov 19 '11 at 8:57