Neighbouring plots in a field are usually more alike than plots far apart. A model that ignores this gives wrong standard errors and less precise variety comparisons. This article works through one trial:
- check the block analysis for spatial correlation with a residual
variogram (
residvariogram()); - fit an AR1 x AR1 correlation over the field
(
corAR1xAR1()); - compare, by AIC, models that fit the blocking of the design first
and then a spatial term (AR1 x AR1 or a smooth surface: SpATS, LVIS, a
thin-plate spline in
semireg()), and look at the best one; - on a simulated trial with a known truth, compare these models with
one that has both a smooth trend and an AR1 x AR1 correlation
(
semireg_tmb()with apropto()term).
The data are the Slate Hall Farm trial (Genstat’s REML Guide, chapter 3): 25 wheat varieties in 6 replicates, 150 plots on a grid of 10 field rows by 15 field columns.
d <- read.csv(system.file("extdata", "slatehall.csv", package = "predictmeans"))
d$variety <- factor(d$variety)
d$rep <- factor(d$replicates)
d$rowf <- factor(d$fieldrow)
d$colf <- factor(d$fieldcolumn)1. The block analysis and its residual variogram
The design is a randomized complete block design, so the first model
has the replicates and the varieties. residvariogram()
draws the variogram of its residuals against the lag, with an envelope
from data simulated under the fitted model:
m0 <- lm(yield ~ rep + variety, data = d)
v0 <- residvariogram(m0, row = "fieldrow", col = "fieldcolumn", data = d)
advice(v0)$text## [1] "Plots next to each other in rows and columns are more alike than the model allows (the variogram is below the envelope at the shortest lag): the standard errors of the means ignore it. Fit a spatial covariance (gls() or lme() with corAR1xAR1(form = ~ row + col)) or a smooth surface t2(row, col) in semireg(), and check its variogram."
At the shortest lags the variogram is below its envelope:
neighbouring plots are more alike than the block model allows, and the
advice says what to fit. (v0 keeps the variogram:
print(v0) gives the test and the short lags,
autoplot(v0) draws it again,
autoplot(v0, type = "surface") as a surface over the row
and column lags.)
2. AR1 x AR1 over the field
fA <- gls(yield ~ variety, data = d, correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn))
coef(fA$modelStruct$corStruct, unconstrained = FALSE)## phi_row phi_col
## 0.4586104 0.6837671
fB <- gls(yield ~ variety, data = d,
correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn, nugget = TRUE))
coef(fB$modelStruct$corStruct, unconstrained = FALSE)## phi_row phi_col nugget
## 0.68269678 0.84379858 0.09596553
anova(fA, fB)## Model df AIC BIC logLik Test L.Ratio p-value
## fA 1 28 535.0870 614.2798 -239.5435
## fB 2 29 530.0874 612.1085 -236.0437 1 vs 2 6.999567 0.0082
Both correlations are high (0.68 between rows, 0.84 between columns, with the nugget). The nugget, an independent plot error beside the AR1 x AR1 part, improves the fit: the REML deviance is 7.0 lower for one more parameter. The residual variogram of this model stays inside its envelope:
vB <- residvariogram(fB, row = "fieldrow", col = "fieldcolumn", data = d, nsim = 39)
advice(vB)$text # empty: nothing is flagged## character(0)
The variety means and their comparisons, with Kenward-Roger df:
pB <- predictmeans(fB, "variety")
head(pB$means[, c("variety", "estimate", "std.error", "df")])## variety estimate std.error df
## 1 1 12.45582 0.9959761 4.601645
## 2 2 15.16234 0.9955372 4.629201
## 3 3 14.03984 1.0004145 4.607442
## 4 4 14.04918 0.9974440 4.633306
## 5 5 14.71612 1.0010578 4.661920
## 6 6 15.21937 0.9976044 4.570890
summary(pB$pairs$std.error)## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.5791 0.6071 0.6180 0.6169 0.6250 0.6517
A single mean has a large SE on few df (about 1.0 on 4.6 df here): with correlation this strong, the overall level of the field is poorly known. Comparisons between varieties do not depend on that level, and their SEDs (mean 0.62) are much smaller than those of the block analysis (1.08, section 3).
Replicates can be added as random effects. In lme() a
correlation acts only within the groups of the innermost random effect,
so for an AR1 x AR1 over the whole field the replicate effects go in one
group:
d$all <- factor(1)
fD <- lme(yield ~ variety, random = list(all = pdIdent(~ rep - 1)), data = d,
correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn | all, nugget = TRUE))
VarCorr(fD)[1:2, ]## Variance StdDev
## rep1 "2.398791e-08" "0.0001548803"
## rep2 "2.398791e-08" "0.0001548803"
The replicate variance is estimated as 0 (Genstat, which allows
negative components, gives -0.078), so this model is the same as
fB.
Several trials are analysed together with
form = ~ row + col | trial (the same phi in every trial),
or with by_group = TRUE a phi pair for each trial and,
through varIdent(), a residual variance for each:
gls(yield ~ trial / variety, data = trials, weights = varIdent(form = ~ 1 | trial),
correlation = corAR1xAR1(form = ~ row + col | trial, by_group = TRUE))This gives each trial the estimates and SEDs of its own fit (checked in the tests), with the means of all trials in one table.
3. Blocking first, then a spatial surface: choosing the model by AIC
Williams (2026) recommends fitting the blocking of the design first
and adding a spatial term only as an enhancement (Piepho et al. 2015):
without the blocks, the field trend appears as a spatial correlation
close to 1. He compares by AIC a model with the blocks only, AR1 x AR1,
the P-spline ANOVA of SpATS (bs = "pspline2d"; second
differences, Rodríguez-Álvarez et al. 2018), the linear variance plus
interaction splines of LVIS (bs = "lvis"; first
differences, Piepho et al. 2022) and a thin-plate spline, each with and
without the blocks.
Each Slate Hall replicate is a 5 x 5 square, so the blocks are the
replicates (fixed) and the rows and columns within them (random). REML
likelihoods are comparable only between models with the same fixed
effects, so every model has the same fixed part: the varieties, the
replicates (with blocking), and the plane
fieldrow * fieldcolumn (the null space of the splines,
written in the formula for the others).
d$reprow <- interaction(d$rep, d$rowf, drop = TRUE) # rows within replicates
d$repcol <- interaction(d$rep, d$colf, drop = TRUE) # columns within replicates
plane <- "fieldrow * fieldcolumn"
fx <- function(blocks) paste("yield ~ variety +", if (blocks) "rep +", plane)
re <- "+ (1 | reprow) + (1 | repcol)"
fits <- list()
for (b in c(TRUE, FALSE)) {
k <- if (b) "with blocking" else "no blocking"
fits[[k]]$`no spatial term` <- gls(as.formula(fx(b)), data = d)
if (b) fits[[k]]$`+ rows, columns in replicates` <- lme4::lmer(as.formula(paste(fx(b), re)), data = d)
# (with the blocks: lme, the within-replicate rows and columns as random effects of one field-wide group)
fits[[k]]$`AR1 x AR1 + nugget` <- if (b) {
lme(as.formula(fx(b)), data = d,
random = list(all = pdBlocked(list(pdIdent(~ reprow - 1), pdIdent(~ repcol - 1)))),
correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn | all, nugget = TRUE))
} else gls(as.formula(fx(b)), data = d, correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn, nugget = TRUE))
sm <- function(s) semireg(as.formula(paste(fx(b), "+", s, if (b) re)), data = d)
fits[[k]]$SpATS <- sm('s(fieldcolumn, fieldrow, bs = "pspline2d")')
fits[[k]]$LVIS <- sm('s(fieldcolumn, fieldrow, bs = "lvis")')
fits[[k]]$`thin plate` <- sm("s(fieldcolumn, fieldrow, k = 30)")
}
aic <- function(f) { ll <- logLik(if (inherits(f, "semireg")) f$semer else f); -2 * as.numeric(ll) + 2 * attr(ll, "df") }
sed <- function(f) mean(predictmeans(f, "variety")$pairs$std.error)
tab <- do.call(rbind, lapply(names(fits), function(k) data.frame(
blocking = k, model = names(fits[[k]]), AIC = round(vapply(fits[[k]], aic, 0), 1),
mean_SED = round(vapply(fits[[k]], sed, 0), 3), row.names = NULL)))
tab## blocking model AIC mean_SED
## 1 with blocking no spatial term 623.9 1.084
## 2 with blocking + rows, columns in replicates 557.4 0.628
## 3 with blocking AR1 x AR1 + nugget 539.0 0.607
## 4 with blocking SpATS 544.4 0.627
## 5 with blocking LVIS 537.1 0.602
## 6 with blocking thin plate 536.0 0.619
## 7 no blocking no spatial term 629.3 1.093
## 8 no blocking AR1 x AR1 + nugget 543.5 0.617
## 9 no blocking SpATS 562.0 0.640
## 10 no blocking LVIS 541.9 0.611
## 11 no blocking thin plate 566.9 0.738
As in Williams’ trials, the rows and columns within replicates take out most of the trend: the AIC falls by about 66 and the mean SED from 1.08 to 0.63. A spatial term on top of them improves the fit by a further 13-21 units, with SEDs a little smaller (0.60-0.62; SpATS 0.63). With the blocks, the thin-plate spline, LVIS and AR1 x AR1 are within three AIC units: they fit about equally well here, and SpATS is behind. Without the blocks every spatial model fits worse: AR1 x AR1 and LVIS by about 5 units, SpATS and the thin-plate spline by 18 and 31. There is no single best spatial model for every trial; the comparison is made on each one.
The model with the lowest AIC is the thin-plate spline with the blocks. Its residual variogram stays inside the envelope:
best <- fits$`with blocking`$`thin plate`
vBest <- residvariogram(best, row = "fieldrow", col = "fieldcolumn", data = d, nsim = 39)
semipred() gives its fitted trend over the field (the
varieties averaged). plot() (or autoplot())
draws it as filled contours with the plots marked, and
autoplot(type = "3d") as a 3-D surface (a plotly widget
that can be turned with the mouse):

autoplot(sBest, type = "3d")Genstat gives the same deviances and SEDs for these models (see Checks below).
4. A smooth trend plus AR1 x AR1: a simulated trial
A field can have both a smooth trend and local correlation between neighbouring plots. The model is then
with the varieties in , the spline in , an AR1 x AR1 plot effect and a nugget . On real data the true variety effects are unknown, so to see how well each model does, the yields below are simulated on the Slate Hall layout from this model: a trend , strong correlations and , and a nugget SD of 0.25.
ar1ar1 <- function(phi_row, phi_col)
phi_row^abs(outer(d$fieldrow, d$fieldrow, "-")) * phi_col^abs(outer(d$fieldcolumn, d$fieldcolumn, "-"))
set.seed(2026)
eff <- setNames(rnorm(25, sd = 0.6), levels(d$variety)) # the true variety effects
d$ysim <- 12 + eff[as.character(d$variety)] + 0.8 * sin(d$fieldcolumn / 3) + 0.6 * cos(d$fieldrow / 2) +
0.7 * drop(t(chol(ar1ar1(0.84, 0.9))) %*% rnorm(150)) + rnorm(150, sd = 0.25)semireg_tmb() fits the spline together with an AR1 x AR1
plot effect through glmmTMB’s propto() term: one effect per
plot, with covariance
for a given matrix
.
Only the scale
is estimated; the two correlations are supplied, here those of the
gls() fit of section 2 on the simulated yields.
is built from the plots’ own row and column numbers, so a missing plot
still leaves the right distances between the others. Two separate
ar1() terms would not do: their covariances add, so two
plots one row and one column apart would get none, where AR1 x AR1 gives
.
fB_sim <- gls(ysim ~ variety, data = d, correlation = corAR1xAR1(form = ~ fieldrow + fieldcolumn, nugget = TRUE))
phi <- coef(fB_sim$modelStruct$corStruct, unconstrained = FALSE)
round(phi, 3)## phi_row phi_col nugget
## 0.913 0.942 0.028
d$plot <- factor(seq_len(nrow(d)))
d$field <- factor(1)
C <- ar1ar1(phi[["phi_row"]], phi[["phi_col"]])
dimnames(C) <- list(levels(d$plot), levels(d$plot)) # in the order of the plot effects
fS_sim <- semireg_tmb(ysim ~ variety + s(fieldcolumn, fieldrow, bs = "pspline2d", xt = list(nseg = c(6, 4))) +
propto(0 + plot | field, C), data = d)(The spline basis is smaller than the default,
nseg = c(6, 4), because semireg_tmb() needs
fewer spline columns than plots. The residual variance of this fit is
the nugget; dispformula = ~ 0 would leave it out.)
Four models are scored against the truth on the 300 differences between varieties: the error of the estimated differences (root mean square), the SED the model claims, and the share of 95% limits that contain the true difference:
fP_sim <- semireg(ysim ~ variety + s(fieldcolumn, fieldrow, bs = "pspline2d", xt = list(nseg = c(6, 4))) +
(1 | rowf) + (1 | colf), data = d)
score <- function(fit) {
pr <- predictmeans(fit, "variety")$pairs
truth <- eff[as.character(pr$level1)] - eff[as.character(pr$level2)]
c(error = sqrt(mean((pr$estimate - truth)^2)), mean_SED = mean(pr$std.error),
coverage = mean(pr$conf.low <= truth & truth <= pr$conf.high), df = median(pr$df))
}
round(rbind(blocks = score(lm(ysim ~ rep + variety, data = d)), `AR1 x AR1 + nugget` = score(fB_sim),
`pspline2d trend` = score(fP_sim), `pspline2d + AR1 x AR1` = score(fS_sim)), 3)## error mean_SED coverage df
## blocks 0.364 0.453 0.987 120.000
## AR1 x AR1 + nugget 0.188 0.157 0.907 86.801
## pspline2d trend 0.182 0.169 0.930 88.561
## pspline2d + AR1 x AR1 0.185 0.156 0.897 92.569
In this trial every spatial model halves the error of the block
analysis (about 0.19 against 0.36). The AR1 x AR1 fit estimates the
correlations a little too high (0.91 and 0.94 against the true 0.84 and
0.9), as it takes part of the trend into them, and here the spatial
models claim SEDs somewhat smaller than their actual error. One trial is
one draw, though. Over 100 simulated trials
(dev/sim-spatial-models.R) the claimed SEDs match the
errors:
| model | error of the differences | SED claimed (root mean square) | coverage of 95% limits |
|---|---|---|---|
| blocks | 0.364 | 0.378 | 0.959 |
| AR1 x AR1 + nugget | 0.186 | 0.184 | 0.946 |
| pspline2d trend | 0.198 | 0.196 | 0.946 |
pspline2d + AR1 x AR1 (phi from gls()) |
0.188 | 0.182 | 0.941 |
Each spatial model is about twice as precise as the block analysis
(errors 0.19-0.20 against 0.36), and each model’s SEDs match its error;
the coverages are within about one Monte Carlo SE (0.004) of 0.95, the
block analysis being slightly conservative. With correlation this
strong, AR1 x AR1 alone does as well as the model with both parts, which
gains nothing. The combined model’s coverage is the lowest (0.941), as
expected of SEDs that take the supplied correlations as known, though
the difference is within about two Monte Carlo SEs. In 4 of its 100 fits
glmmTMB’s Hessian was not positive definite; predictmeans then gives z
tests and says so in settings$df_method.
Two points to keep in mind:
- The SEs and Satterthwaite df of the
propto()fit are conditional on the supplied correlations; they do not allow for the correlations being estimated. Estimating them in the same fit needs an outer search over , a refit at each step. - The spline and the AR1 x AR1 effect compete for the same variation.
On the real Slate Hall yields, with the correlations of
fB, three of the spline’s five variances are estimated at about zero, glmmTMB warns that the Hessian is not positive definite (so the SEs cannot be trusted), and the mean SED barely moves (0.605 against 0.617). There, fit one or the other (sections 2 and 3) and compare their SEDs and residual variograms.
Checked against Genstat
corAR1xAR1() was checked against a Genstat run of these
models (dev/genstat/ar1ar1-slatehall.gen):
| predictmeans / nlme | Genstat | |
|---|---|---|
| AR1 x AR1: phi row, column | 0.4586, 0.6838 | 0.4586, 0.6838 |
| with nugget: phi; units variance | 0.6827, 0.8438; 0.486 | 0.6827, 0.8438; 0.486 |
| REML deviance difference | 7.00 | 7.00 |
| 25 means and 300 SEDs of each model | within 1e-6 | |
variety F test d.d.f. (df_method = "KR-average") |
79.99, 75.67 | 80.0, 75.7 |
The SEDs agree with vcov_adjust = FALSE (Genstat’s are
not adjusted); the default Kenward-Roger adjusted SEs are slightly
larger. The tests are in
tests/testthat/test-cor-ar1xar1.R.
The models of section 3 were run in Genstat 24
(dev/genstat/spatial-slatehall.gen:
VCOMPONENTS, TENSORSPLINE for SpATS,
V2DSPLINE for LVIS and the thin-plate spline,
VAROWCOLUMNDESIGN for Genstat’s own choice), with the same
fixed parts. REML deviance (-2 log L) and mean SED of the 300 variety
differences (unadjusted, as Genstat’s):
| model | blocking | predictmeans: deviance, SED | Genstat: deviance, SED |
|---|---|---|---|
| no spatial term | with / no | 555.86, 1.0843 / 571.31, 1.0933 | 555.86, 1.0843 / 571.31, 1.0933 |
| rows, columns in replicates | with | 485.39, 0.6249 | 485.39, 0.6249 |
| AR1 x AR1 + nugget | with / no | 460.98, 0.5914 / 479.52, 0.6043 | 460.76, 0.5918 / 479.52, 0.6043 |
SpATS (xt = list(center = FALSE)) |
with / no | 460.97, 0.5951 / 491.09, 0.6271 | 460.96, 0.5951 / 491.09, 0.6272 |
| LVIS | with / no | 459.13, 0.5898 / 477.89, 0.6022 | 459.13, 0.5898 / 477.89, 0.6022 |
| thin-plate spline | with / no | 461.96, 0.6036 / 506.90, 0.7351 | 461.08, 0.5981 / 501.64, 0.6885 |
They agree except where the models differ: Genstat lets the variance
of columns within replicates go negative (-0.06) in the AR1 x AR1 fit
with the blocks, where lme() keeps it at 0; and its
thin-plate spline is the full THINPLATE basis, where
s(col, row, k = 30) is mgcv’s rank-30 one. Genstat’s SpATS
uses the raw coordinates for its linear-by-smooth terms, as
xt = list(center = FALSE); the article’s default centres
them. Genstat’s automatic selection (VAROWCOLUMNDESIGN,
which tries rows, columns and AR1 structures, not spline surfaces) also
chose AR1 x AR1 with a nugget, and dropped the replicates. The test is
tests/testthat/test-genstat-spatial.R.
References
- Gilmour, A. R., Cullis, B. R. and Verbyla, A. P. (1997). Accounting for natural and extraneous variation in the analysis of field experiments. Journal of Agricultural, Biological, and Environmental Statistics, 2, 269-293.
- Piepho, H. P., Boer, M. P. and Williams, E. R. (2022). Two-dimensional P-spline smoothing for spatial analysis of plant breeding trials. Biometrical Journal, 64, 835-857.
- Piepho, H. P., Möhring, J., Pflugfelder, M., Hermann, W. and Williams, E. R. (2015). Problems in parameter estimation for power and AR(1) models of spatial correlation in designed field experiments. Communications in Biometry and Crop Science, 10, 3-16.
- Rodríguez-Álvarez, M. X., Boer, M. P., van Eeuwijk, F. A. and Eilers, P. H. C. (2018). Correcting for spatial heterogeneity in plant breeding experiments with P-splines. Spatial Statistics, 23, 52-71.
- Williams, E. R. (2026). Modern methods for the spatial analysis of field trials. VSNi blog, 4 November 2026. https://vsni.co.uk/modern-methods-for-the-spatial-analysis-of-field-trials/
