(Question originally posted on StackOverflow but users advised it was more appropriate to ask here:)

I’m just starting out with R so I apologise if this is a silly question, however I have Googled it extensively and can’t seem to find an answer. I am attempting to analyse data with structure:

'data.frame':   60 obs. of  4 variables:
 $ response: num  8.2 8.2 9.4 11 9.9 9.5 9.8 11.1 10.9 9.7 ...
 $ subject : Factor w/ 10 levels "1","2","3","4",..: 1 1 1 1 1 1 2 2 2 2 ...
 $ dose    : Factor w/ 3 levels "A","B","C": 1 1 2 2 3 3 1 1 2 2 ...
 $ time    : Factor w/ 2 levels "dawn","dusk": 1 2 1 2 1 2 1 2 1 2 ...

I.e. there are 10 subjects, for each subject there are two recordings at each of three doses: one at dusk and one at dawn.

So I performed a mixed model ANOVA as follows:

aov1<- aov(response~dose*time + Error(subject/(dose*time)))

Which worked fine and generated the result:

Error: subject
          Df Sum Sq Mean Sq F value Pr(>F)
Residuals  9   4417   490.8               

Error: subject:dose
          Df Sum Sq Mean Sq F value Pr(>F)  
dose       2  25.95  12.975   3.681 0.0457 *
Residuals 18  63.45   3.525                 
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: subject:time
          Df Sum Sq Mean Sq F value   Pr(>F)    
time       1  78.66   78.66   27.14 0.000557 ***
Residuals  9  26.09    2.90                     
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: subject:dose:time
          Df Sum Sq Mean Sq F value Pr(>F)
dose:time  2   4.09   2.046   0.578  0.571
Residuals 18  63.70   3.539      

This I took to mean that there was a significant (p<0.05) effect of time and dose but not a significant interaction. Time has only two levels so that’s self-explanatory, but dose has three levels, and I’d now like to do a post-test to check which ones are significantly different from each other. However I can’t work out how to do this. “TukeyHSD(aov1)” and “summary.lm(aov1)” (to use contrasts) don’t seem to work in the same way that they did with one-way ANOVAs that I have some prior experience with.

Since I am working in a high-security area and I'm not sure if I'd be able to download and install packages without specific authorisation (I won't know until I have a meeting in a fortnight or so), I was wondering if there is any way to do some form of post-test to assess the differences between different doses WITHOUT downloading and installing any further packages?

Thanks in advance for any advice!


There's probably no need to apologize. Despite the large amount of educational material free on the web for learning statistics in R, the vast majority don't address situations that users of other packages take for granted. For example, unbalanced anova or post-hoc testing after factorial anova. Even most popular textbooks with R don't do a good job with this. It's getting better, but it's still a slog. And if you are trying to do these things with just the base R packages, you are starting right behind the eight ball.

If you will doing statistical analyses of this level, you will really need to be able to use contributed packages. It might make sense to get together a list of packages you will need beforehand to get approval. Once you get everything installed and working, there may not be much cause to update R or the packages, except, say, every six months. A few suggestions for packages: car for anova; lme4, lmerTest, and nlme for mixed models; lsmeans, multcomp, and multcompView for post-hoc testing; I also use pysch and FSA all the time for summarizing data conveniently. There are a bunch of others I use for other specific analyses. If you want a more comprehensive list, you could go through the analyses you are interested in the menu at the following page; the packages are listed near the top of each page. http://rcompanion.org/handbook/ . You should also be aware that is is possible to install R and additional packages in a portable set up. This may be more acceptable for security (?).

As to your specific analysis, I think the links in the first comment to the question address this kind of analysis well. Personally, I prefer using lsmeans to glht for the post-hoc analyses, but both are powerful and flexible enough.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.