A one-way ANOVA is used to determine whether or not there is a statistically significant difference between the means of three or more independent groups.
The hypotheses used in a one-way ANOVA are as follows:
- H0: The means are equal for each group.
- HA: At least one of the means is different from the others.
If the p-value from the ANOVA is less than some significance level (like α = .05), we can reject the null hypothesis and conclude that at least one of the group means is different from the others.
But in order to find out exactly which groups are different from each other, we must conduct a post-hoc test.
One commonly used post-hoc test is Fisher’s least significant difference (LSD) test.
You can use the LSD.test() function from the agricolae package to perform this test in R.
The following example shows how to use this function in practice.
Example: Fisher’s LSD Test in R
Suppose a professor wants to know whether or not three different studying techniques lead to different exam scores among students.
To test this, she randomly assigns 10 students to use each studying technique and records their exam scores.
The following table shows the exam scores for each student based on the studying technique they used:

We can use the following code to create this dataset and perform a one-way ANOVA on it in R:
#create data frame
df <- data.frame(technique = rep(c("tech1", "tech2", "tech3"), each = 10),
score = c(72, 73, 73, 77, 82, 82, 83, 84, 85, 89,
81, 82, 83, 83, 83, 84, 87, 90, 92, 93,
77, 78, 79, 88, 89, 90, 91, 95, 95, 98))
#view first six rows of data frame
head(df)
technique score
1 tech1 72
2 tech1 73
3 tech1 73
4 tech1 77
5 tech1 82
6 tech1 82
#fit one-way ANOVA
model <- aov(score ~ technique, data = df)
#view summary of one-way ANOVA
summary(model)
Df Sum Sq Mean Sq F value Pr(>F)
technique 2 341.6 170.80 4.623 0.0188 *
Residuals 27 997.6 36.95
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Since the p-value in the ANOVA table (.0188) is less than .05, we can conclude that not all of the mean exam scores between the three groups are equal.
Thus, we can proceed to perform Fisher’s LSD test to determine which group means are different.
The following code shows how to do so:
library(agricolae)
#perform Fisher's LSD
print(LSD.test(model,"technique"))
$statistics
MSerror Df Mean CV t.value LSD
36.94815 27 84.6 7.184987 2.051831 5.57767
$parameters
test p.ajusted name.t ntr alpha
Fisher-LSD none technique 3 0.05
$means
score std r LCL UCL Min Max Q25 Q50 Q75
tech1 80.0 5.868939 10 76.05599 83.94401 72 89 74.00 82.0 83.75
tech2 85.8 4.391912 10 81.85599 89.74401 81 93 83.00 83.5 89.25
tech3 88.0 7.557189 10 84.05599 91.94401 77 98 81.25 89.5 94.00
$comparison
NULL
$groups
score groups
tech3 88.0 a
tech2 85.8 a
tech1 80.0 b
attr(,"class")
[1] "group"
The portion of the output that we’re most interested in is the section titled $groups. The techniques that have different characters in the groups column are significantly different.
From the output we can see:
- Technique 1 and Technique 3 have significantly different mean exam scores (since tech1 has a value of “b” and tech3 has a value of “a”)
- Technique 1 and Technique 2 have significantly different mean exam scores (since tech1 has a value of “b” and tech2 has a value of “a”)
- Technique 2 and Technique 3 do not have significantly different mean exam scores (since they both have a value of “a”)
Additional Resources
The following tutorials explain how to perform other common tasks in R:
How to Perform a One-Way ANOVA in R
How to Perform a Bonferroni Post-Hoc Test in R
How to Perform Scheffe’s Post-Hoc Test in R
January 27, 2023 at 11:18 am
I have the following types of data (5 treatments each with 8 replications, total 5*8=40 observations. i.e CRD design and wanted to do One way ANOVA). Some times there is also a similar data but having missing values. Can you help me please to calculate the following five questions?. I tried so many times but R software is not friendly but I want to learn more.
Things that I need to calculate;
1. ANOVA analysis (one way anova)
2. Summary or descriptive statistics
3. Mean separation using Tukey, LSD and Duncan multiple range test methods for the above one way anova?
4. Incase if the data will have a missing value, how to calculate the above things by avoiding the missing value?
5. Assigning letters for the significant differences between or among treatment groups?
6. Is that also possible to do the above statsiscial analysis if there are more than 1 or 2 dependent variables (factors)? what is the syntax to do the analysis?
Treat AFI121
CON 50.64880952
CON 53.25595238
CON 58.12903226
CON 49.26785714
CON 49.37125749
CON 39.02380952
CON 52.13690476
CON 48.61309524
ANT 56.97959184
ANT 49.20238095
ANT 51.70238095
ANT 51.7797619
ANT 53.82142857
ANT 53.60714286
ANT 50.25
ANT 48.17032967
D400 52.99378882
D400 53.59868421
D400 53.61904762
D400 53.2797619
D400 48.6547619
D400 54.35119048
D400 54.92261905
D400 50.32738095
D800 54.76190476
D800 54.64880952
D800 53.89880952
D800 51.61585366
D800 55.15483871
D800 50.7202381
D800 56.05031447
D800 46.86904762
D1200 49.69642857
D1200 55.60509554
D1200 53.27380952
D1200 46.8452381
D1200 50.89285714
D1200 52.26190476
D1200 51.46428571
D1200 52.66666667
Many thanks email; sefibahir2009@gmail.com
Brooooooo!!!! I have been trying to figure this out for months, and here you are with an easy way out! How did i not discover this sooner?? Thank you soooooo much!!!!
You are very welcome Sinqobile! We appreciate your support and feedback!