Home / Guides / RCBD ANOVA in R

RCBD ANOVA in R with agricolae: step by step

How to analyse a randomized complete block design in R: read the data, fit the model, check the assumptions, and get Tukey, LSD or Duncan letters with the agricolae package. With the full output of a worked example.

FieldTrialHub guide · 1 December 2026 · Tested in R 4.3.3 with agricolae 1.3-8

1. Arrange the data

Use one row per plot, with a column for the treatment (here Genotype), one for the block (Rep) and one per trait. Save it as CSV. The example has six genotypes in three blocks (the sample data of the ANOVA tool):

Genotype,Rep,PlantHeight,Yield
G1,1,96.1,19.2
G1,2,99.4,21.8
G1,3,99.4,20.6
G2,1,102.1,22.0
...

2. Fit the model

Block and treatment must be factors, otherwise R treats block numbers 1, 2, 3 as a continuous variable and the analysis is wrong.

library(agricolae)          # install.packages("agricolae") the first time
d <- read.csv("trial.csv")
d$Genotype <- factor(d$Genotype)
d$Rep      <- factor(d$Rep)
m <- aov(Yield ~ Rep + Genotype, data = d)
summary(m)
cv.model(m)                 # coefficient of variation, %

Output:

            Df Sum Sq Mean Sq F value   Pr(>F)
Rep          2  23.51   11.75   26.09 0.000108 ***
Genotype     5 250.24   50.05  111.08 1.99e-08 ***
Residuals   10   4.51    0.45
CV = 2.67 %

Genotypes differ highly significantly (F = 111.08 with 5 and 10 df). The block effect is also large, which shows that blocking removed real field variation from the error.

3. Check the assumptions

ANOVA assumes that the residuals are roughly normal and that the variance is similar across treatments. Look at the plots first; formal tests have little power with a few replications.

par(mfrow = c(1, 2)); plot(m, which = 1:2)   # residuals vs fitted, normal Q-Q
shapiro.test(residuals(m))                   # W = 0.975, p = 0.88
bartlett.test(Yield ~ Genotype, data = d)    # K-squared = 0.62, df = 5, p = 0.99

Here neither test suggests a problem. With clearly unequal variances (common for counts or percentages), consider a transformation before the ANOVA.

4. Compare the means

out <- HSD.test(m, "Genotype", console = TRUE)   # Tukey HSD
# LSD.test(m, "Genotype", p.adj = "none", console = TRUE)   # Fisher's LSD
# duncan.test(m, "Genotype", console = TRUE)                # Duncan (DMRT)

Tukey's HSD at α = 0.05 is 1.904 (MSE = 0.4506, 10 df). The groups:

      Yield groups
G5 31.46667      a
G3 27.96667      b
G6 25.43333      c
G2 23.30000      d
G4 21.86667     de
G1 20.53333      e

Means that share a letter do not differ; see how to read letter groupings. For the choice between Tukey, LSD and Duncan, see Tukey vs LSD vs Duncan.

5. A bar chart with letters (optional)

bar.group(out$groups, ylim = c(0, 40), ylab = "Yield", col = "grey85")

The same without writing code

The free ANOVA tool does steps 2 to 5 in your browser: paste the data, pick the treatment, block and traits, and you get the ANOVA table, CV, Bartlett's test, letters and a chart. Its Download R script button writes the R code above for your own data, so you can reproduce the result in R or attach it to a thesis. The results match agricolae exactly; see the validation page.

Main plots and subplots? Use a split-plot analysis instead: split-plot ANOVA in R.