Home / Guides / Split-plot ANOVA in R

Split-plot ANOVA in R: sp.plot, Error() and mean comparisons

How to analyse a split-plot experiment in randomized complete blocks in R, why it needs two error terms, how to compare main-plot and subplot means correctly, and what goes wrong if you analyse it as an ordinary factorial.

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

The design

In a split-plot trial, one factor is applied to large main plots and a second factor to smaller subplots inside them. The example: four nitrogen rates (N0, N60, N120, N180) on main plots, three varieties (V1, V2, V3) on subplots, four blocks, grain yield in t/ha (the sample data of the split-plot tool). Because main plots are larger and fewer, nitrogen is estimated less precisely than variety, so the two factors need different error terms:

Option 1: agricolae::sp.plot

library(agricolae)
d <- read.csv("splitplot.csv")          # columns Rep, Nitrogen, Variety, Yield
sp <- with(d, sp.plot(Rep, Nitrogen, Variety, Yield))
                 Df  Sum Sq Mean Sq F value    Pr(>F)
Rep               3 30.4590 10.1530 90.0781 3.362e-13 ***
Nitrogen          3 19.9757  6.6586 26.5209 8.421e-05 ***
Ea                9  2.2596  0.2511
Variety           2  5.8411  2.9205 25.9111 1.012e-06 ***
Nitrogen:Variety  6  2.7113  0.4519  4.0091  0.006394 **
Eb               24  2.7051  0.1127
cv(a) = 9.7 %, cv(b) = 6.5 %, Mean = 5.175833
One correction. sp.plot tests blocks (Rep) against Error (b), which gives F = 90.08 here. Blocks and main plots share the main-plot stratum, so blocks should be tested against Error (a), as in Gomez and Gomez (1984): F = 10.153 / 0.2511 = 40.44 with 3 and 9 df, p = 1.5 × 10−5. All other rows are correct.

Option 2: base R with Error()

d[] <- lapply(d, function(x) if (is.character(x)) factor(x) else x)
m <- aov(Yield ~ Nitrogen * Variety + Error(Rep / Nitrogen), data = d)
summary(m)

This gives the same F values for nitrogen (26.52 with 3 and 9 df), variety (25.91 with 2 and 24 df) and the interaction (4.01 with 6 and 24 df), split into strata. It does not test blocks.

Comparing the means

Each comparison must use the error term of its factor. With agricolae, pass the right error mean square and degrees of freedom:

with(d, HSD.test(Yield, Nitrogen, DFerror = sp$gl.a, MSerror = sp$Ea, console = TRUE))  # main plots: Error (a)
with(d, HSD.test(Yield, Variety,  DFerror = sp$gl.b, MSerror = sp$Eb, console = TRUE))  # subplots: Error (b)
Nitrogen (Error a, 9 df)MeanGroup
N1205.78a
N1805.69ab
N605.07b
N04.17c
Variety (Error b, 24 df)MeanGroup
V25.57a
V35.24b
V14.72c

Tukey's HSD is 0.639 for nitrogen means and 0.296 for variety means. The interaction is significant (p = 0.006), so the varieties are best compared within each nitrogen rate, again with Error (b):

for (n in unique(d$Nitrogen)) {
  s <- d[d$Nitrogen == n, ]
  print(HSD.test(s$Yield, s$Variety, DFerror = sp$gl.b, MSerror = sp$Eb)$groups)
}
VarietyN0N60N120N180
V13.98 b4.82 a5.33 b4.76 b
V24.67 a5.31 a6.09 a6.21 a
V33.85 b5.07 a5.93 a6.11 a

V2 is the best or equal-best variety at every rate. V1 yields significantly less than V2 at N0, N120 and N180, and at N60 the three varieties do not differ. Comparing nitrogen rates within one variety needs a combined error term with approximate degrees of freedom and is not shown here.

What goes wrong with an ordinary factorial ANOVA

Analysing the same data as a two-factor RCBD, aov(Yield ~ Rep + Nitrogen * Variety), pools both error terms into one residual (MS = 0.150 with 33 df). Nitrogen is then tested against an error that is too small: F rises from 26.52 to 44.26. Here nitrogen is significant either way, but with fewer blocks or smaller effects the factorial analysis can declare a main-plot effect significant when the correct split-plot analysis does not.

The same without code

The split-plot tool runs this whole analysis in your browser: both error terms, blocks tested against Error (a), CV(a) and CV(b), Tukey, LSD or Duncan letters for main plots, subplots and subplots within each main plot, an interaction plot, and an R script that reproduces everything. It runs free on its sample data; your own data need FieldTrialHub Pro. All values match R; see the validation page.

Reference: Gomez, K. A., & Gomez, A. A. (1984). Statistical procedures for agricultural research (2nd ed.). John Wiley & Sons.