
What a two-zone wheat experiment teaches about marginal returns
A wheat crop can reach its highest predicted yield at a nitrogen rate that is not its most economical rate. Each additional kilogram of fertilizer costs money, while the extra grain gained from later applications usually becomes smaller. Economically efficient nitrogen management therefore compares the marginal value of grain with the marginal cost of nitrogen, rather than choosing the largest predicted yield.
This tutorial analyzes 88 historical wheat plots in Germany, grouped into low- and high-fertility zones. We fit a quadratic response curve for each zone, calculate two different nitrogen optima, and test how the economic decision changes under illustrative price assumptions. The resulting rates are a historical statistical demonstration, not fertilizer advice for a present-day field.
Result at a glance. Under the illustrative wheat and nitrogen prices, the modeled economic optima are 199.08 kg N/ha (low fertility) and 239.75 kg N/ha (high fertility). The corresponding yield-maximizing rates within the tested range are 232.35 and 260 kg N/ha. This comparison illustrates why maximizing crop production and maximizing return above fertilizer cost are not equivalent.
Why the experiment matters
The agridat::bachmaier.nitrogen teaching dataset contains 11 nitrogen rates, from 0 to 260 kg N/ha, repeated four times in each fertility zone. Wheat yield is measured in megagrams per hectare (Mg/ha, equivalent to metric tonnes per hectare). Although the original research describes a randomized complete-block experiment, plot-to-block identifiers are not present in the released data. We can study yield response by fertility zone but cannot legitimately reconstruct a block-adjusted analysis. Source: agridat dataset documentation.
1. Read the plot-level observations
The first check confirms that each treatment combination contains four measurements, and that yields and nitrogen rates are physically plausible. The unit of observation is an experimental plot, not a zone average.
data_file <- "01_data/bachmaier_nitrogen_wheat.csv"
trial <- read.csv(data_file, stringsAsFactors = FALSE)
stopifnot(identical(names(trial), c("nitro", "yield", "zone")),
nrow(trial) == 88L, !anyNA(trial),
all(is.finite(trial$nitro)), all(is.finite(trial$yield)),
all(trial$yield > 0), all(trial$nitro >= 0),
setequal(trial$zone, c("low", "high")))
trial$zone <- factor(trial$zone, levels = c("low", "high"))
dose_levels <- c(0, seq(80, 260, by = 20))
stopifnot(setequal(trial$nitro, dose_levels),
all(xtabs(~ zone + nitro, data = trial) == 4L))
zone_levels <- levels(trial$zone)
n_range <- range(trial$nitro)
dir.create("04_outputs", showWarnings = FALSE)2. Model diminishing yield returns
We fit a separate quadratic curve for each fertility zone:
The linear term expresses the initial response and the quadratic term describes how the response changes with increasing nitrogen. A negative quadratic term gives a concave curve, but the assumed shape still requires checking against observed dose means and residuals. Shaded bands in the first figure are pointwise model-based mean confidence intervals under ordinary least-squares assumptions—not field recommendations.
dose_means <- aggregate(yield ~ zone + nitro, data = trial, FUN = mean)
names(dose_means)[3] <- "mean_yield_Mg_ha"
fits <- lapply(zone_levels, function(z) {
lm(yield ~ nitro + I(nitro^2), data = subset(trial, zone == z))
})
names(fits) <- zone_levels
coefficient_table <- do.call(rbind, lapply(zone_levels, function(z) {
s <- summary(fits[[z]])
data.frame(zone = z, term = rownames(s$coefficients),
estimate = s$coefficients[, 1],
standard_error = s$coefficients[, 2],
row.names = NULL)
}))
prediction_grid <- do.call(rbind, lapply(zone_levels, function(z) {
g <- data.frame(nitro = seq(n_range[1], n_range[2], by = 1))
p <- predict(fits[[z]], newdata = g, interval = "confidence")
data.frame(zone = z, nitro = g$nitro,
estimate = p[, "fit"], lower = p[, "lwr"], upper = p[, "upr"])
}))The fitted curves are concave in both zones. Their values are approximately 0.739 in the low-fertility zone and 0.863 in the high-fertility zone. These measure within-sample fit, not how well the model would predict a new field. The low-zone response levels off within the tested nitrogen range; the high-zone quadratic peak lies beyond the largest tested rate.
3. Maximum yield is not maximum economic return
The yield-maximizing rate solves the model’s peak problem. The economic rate instead maximizes wheat revenue minus the variable cost of applied N:
At an interior optimum, the slope of the yield response equals the price ratio:
The numerical example uses €110 per Mg of wheat and €0.60 per kg of nitrogen, historical illustrative prices from the agridat example, not present-day market quotations. The calculation omits all other production costs; the result is return above nitrogen fertilizer cost, not complete farm profit. We restrict both optima to 0–260 kg N/ha because the data provide no direct evidence outside that domain.
# Historical illustrative inputs from the package's teaching example, not current quotes.
wheat_price <- 110 # EUR per Mg (metric tonne) of wheat
nitrogen_price <- 0.60 # EUR per kg of applied N
best_rate <- function(beta, cost_ratio = 0, lower = 0, upper = 260) {
b1 <- unname(beta["nitro"])
b2 <- unname(beta["I(nitro^2)"])
candidates <- c(lower, upper)
if (b2 < 0) {
vertex <- (cost_ratio - b1) / (2 * b2)
candidates <- c(candidates, max(lower, min(upper, vertex)))
}
# The constant intercept does not affect the maximizing dose.
score <- (b1 - cost_ratio) * candidates + b2 * candidates^2
candidates[which.max(score)]
}
optima <- do.call(rbind, lapply(zone_levels, function(z) {
b <- coef(fits[[z]])
y_rate <- best_rate(b, lower = n_range[1], upper = n_range[2])
e_rate <- best_rate(b, nitrogen_price / wheat_price,
lower = n_range[1], upper = n_range[2])
data.frame(zone = z, yield_max_rate_kg_N_ha = y_rate,
economic_rate_kg_N_ha = e_rate,
yield_at_economic_rate_Mg_ha = unname(predict(
fits[[z]], newdata = data.frame(nitro = e_rate))),
return_above_N_cost_EUR_ha = wheat_price * unname(predict(
fits[[z]], newdata = data.frame(nitro = e_rate))) - nitrogen_price * e_rate)
}))Under these teaching prices, the fitted economic optimum is approximately 199.1 kg N/ha in the low-fertility zone and 239.8 kg N/ha in the high-fertility zone. The fitted yield-maximizing rates within the observed range are 232.3 and 260.0 kg N/ha, respectively. For the high-fertility zone, the quadratic’s unconstrained vertex can fall outside the experimental range; the reported constrained yield optimum is then the tested upper limit, not an empirically observed peak.
At the modeled economic rates, fitted returns above nitrogen cost are approximately €755.84/ha for the low-fertility zone and €1,006.74/ha for the high-fertility zone. The calculation includes estimated grain revenue and the applied N fertilizer expense alone; it excludes every other farming cost and any environmental damages. The rates should not be transferred directly to other soils or seasons.
| Zone | Yield optimum (kg N/ha) | Economic optimum (kg N/ha) |
|---|---|---|
| low | 232.3 | 199.1 |
| high | 260.0 | 239.8 |
4. Change the prices, change the decision
A price ratio is more informative than either price alone. For instance, if N becomes more expensive relative to wheat, the extra grain required to recover the cost of one more kilogram of nitrogen increases. We express that threshold as kilograms of additional grain per kilogram of N and examine a hypothetical grid of prices. These prices are sensitivity scenarios, not quotations from a current marketplace.
prices <- expand.grid(wheat_EUR_per_Mg = c(90, 110, 160, 220),
nitrogen_EUR_per_kg_N = c(0.40, 0.60, 0.90, 1.20))
price_sensitivity <- do.call(rbind, lapply(zone_levels, function(z) {
s <- prices
s$zone <- z
s$required_kg_grain_per_kg_N <- 1000 * s$nitrogen_EUR_per_kg_N /
s$wheat_EUR_per_Mg
s$economic_rate_kg_N_ha <- vapply(seq_len(nrow(s)), function(i) {
best_rate(coef(fits[[z]]),
s$nitrogen_EUR_per_kg_N[i] / s$wheat_EUR_per_Mg[i],
lower = n_range[1], upper = n_range[2])
}, numeric(1))
s
}))The baseline price ratio of 0.60/110 corresponds to 5.45 kilograms of extra grain per additional kilogram of nitrogen. Across the 16 illustrative combinations of grain and nitrogen prices, modeled economic rates range from 151.0 to 221.3 kg N/ha in the low zone and 179.8 to 260 kg N/ha in the high zone. The boundary value of 260 indicates the experiment’s limit, not an estimate beyond it.
5. Examine model assumptions and uncertainty
Having four plots per dose allows a pure-error versus lack-of-fit comparison. The lack-of-fit F statistic asks whether the fitted quadratic leaves systematic differences from the observed dose means beyond the variation among plots at the same dose. It is a diagnostic rather than proof that the model is physically correct. Unrecorded block effects could affect the independence and error-variance assumptions behind this test.
We also draw 3,000 coefficient vectors from each model’s estimated covariance matrix to explore how parameter uncertainty changes the constrained economic optimum. These ranges are exploratory model-based parameter-draw intervals. They are not block-adjusted confidence sets, and they do not account for price uncertainty, functional-form uncertainty or future-year variability.
model_checks <- do.call(rbind, lapply(zone_levels, function(z) {
d <- subset(trial, zone == z)
f <- fits[[z]]
pure_error <- sum((d$yield - ave(d$yield, d$nitro))^2)
lack_of_fit <- sum(resid(f)^2) - pure_error
df_pure <- nrow(d) - length(unique(d$nitro))
df_lof <- length(unique(d$nitro)) - length(coef(f))
f_stat <- (lack_of_fit / df_lof) / (pure_error / df_pure)
data.frame(zone = z, n_plots = nrow(d), r_squared = summary(f)$r.squared,
residual_sd_Mg_ha = summary(f)$sigma,
quadratic_coefficient = unname(coef(f)[3]),
lack_of_fit_F = f_stat, lack_of_fit_df1 = df_lof,
pure_error_df2 = df_pure,
lack_of_fit_p = pf(f_stat, df_lof, df_pure, lower.tail = FALSE))
}))
# Exploratory uncertainty assumes the unblocked OLS covariance is adequate.
set.seed(20261115)
uncertainty <- do.call(rbind, lapply(zone_levels, function(z) {
f <- fits[[z]]
b <- coef(f)
draws <- matrix(rnorm(3000 * length(b)), ncol = length(b)) %*% chol(vcov(f))
draws <- sweep(draws, 2, b, "+")
colnames(draws) <- names(b)
rates <- apply(draws, 1, best_rate, cost_ratio = nitrogen_price / wheat_price,
lower = n_range[1], upper = n_range[2])
data.frame(zone = z, median_rate = median(rates),
lower_2_5pct = unname(quantile(rates, 0.025)),
upper_97_5pct = unname(quantile(rates, 0.975)),
fraction_at_boundary = mean(rates == n_range[1] | rates == n_range[2]),
fraction_concave = mean(draws[, "I(nitro^2)"] < 0))
}))| Zone | R-squared | Residual SD (Mg/ha) | Lack-of-fit p |
|---|---|---|---|
| low | 0.739 | 0.775 | 0.580 |
| high | 0.863 | 0.599 | 0.728 |
| Zone | Median (kg N/ha) | 2.5% draw quantile | 97.5% draw quantile |
|---|---|---|---|
| low | 198.5 | 173.4 | 258.6 |
| high | 239.6 | 205.1 | 260.0 |
The lack-of-fit comparisons against within-dose variability return p = 0.580 for the low-fertility zone and p = 0.728 for the high-fertility zone. Neither provides strong evidence that the quadratic means miss systematic dose patterns, but the tests do not establish perfect fit or independence. Residual standard deviations are 0.775 and 0.599 Mg/ha, respectively.
Under exploratory draws from the fitted OLS coefficient covariance, central 95% ranges for the economic optimum are 173.4–258.6 kg N/ha in the low zone and 205.1–260 kg N/ha in the high zone. About 24.2% of high-zone draws choose a boundary, illustrating how the experimental upper limit constrains the uncertainty summary. These ranges are not block-adjusted design-based confidence intervals, because the original block labels are unavailable.
6. Read the four figures together
Together, the four figures connect the observed plot yields to the fitted response mechanism, the economic objective, the sensitivity of the recommendation to prices, and the diagnostic limits of the regression. The estimated optima are most informative when viewed alongside these distributions and residual patterns.
zone_cols <- c(low = "#147D90", high = "#C16B25")
png("04_outputs/01_yield_response.png", width = 1800, height = 860, res = 170)
par(mfrow = c(1, 2), mar = c(4.3, 4.4, 3.3, 0.9))
for (z in zone_levels) {
d <- subset(trial, zone == z)
g <- subset(prediction_grid, zone == z)
plot(yield ~ nitro, data = d, pch = 16, cex = 0.85,
col = adjustcolor(zone_cols[z], alpha.f = 0.7),
xlim = n_range, ylim = range(trial$yield),
xlab = "Nitrogen applied (kg N/ha)", ylab = "Wheat yield (Mg/ha)",
main = paste(tools::toTitleCase(z), "fertility zone"))
polygon(c(g$nitro, rev(g$nitro)), c(g$lower, rev(g$upper)),
border = NA, col = adjustcolor(zone_cols[z], alpha.f = 0.18))
lines(g$nitro, g$estimate, col = zone_cols[z], lwd = 2.5)
points(d$nitro, d$yield, pch = 16, cex = 0.7, col = zone_cols[z])
abline(v = optima$economic_rate_kg_N_ha[optima$zone == z], lty = 2, lwd = 2)
}
dev.off()png
2
png("04_outputs/02_return_above_n_cost.png", width = 1800, height = 860, res = 170)
par(mfrow = c(1, 2), mar = c(4.3, 4.8, 3.3, 0.9))
for (z in zone_levels) {
g <- subset(prediction_grid, zone == z)
value <- wheat_price * g$estimate - nitrogen_price * g$nitro
plot(g$nitro, value, type = "l", lwd = 2.5, col = zone_cols[z],
xlab = "Nitrogen applied (kg N/ha)",
ylab = "Return above N fertilizer cost (EUR/ha)",
main = paste(tools::toTitleCase(z), "fertility zone"))
o <- subset(optima, zone == z)
abline(v = o$economic_rate_kg_N_ha, col = "#B23636", lwd = 2, lty = 2)
abline(v = o$yield_max_rate_kg_N_ha, col = "#3F5366", lwd = 2, lty = 3)
legend("bottomright", c("Economic optimum", "Yield optimum"),
lty = c(2, 3), col = c("#B23636", "#3F5366"), bty = "n", cex = 0.82)
}
dev.off()png
2
png("04_outputs/03_price_sensitivity.png", width = 1500, height = 900, res = 170)
par(mar = c(4.6, 4.6, 2.6, 1))
plot(NA, xlim = range(price_sensitivity$required_kg_grain_per_kg_N),
ylim = n_range, xlab = "Required extra grain (kg) per kg applied N",
ylab = "Economically optimal N (kg/ha)",
main = "Price-ratio sensitivity (illustrative scenarios)")
for (z in zone_levels) {
s <- subset(price_sensitivity, zone == z)
s <- s[order(s$required_kg_grain_per_kg_N), ]
lines(s$required_kg_grain_per_kg_N, s$economic_rate_kg_N_ha,
col = zone_cols[z], lwd = 2.3)
points(s$required_kg_grain_per_kg_N, s$economic_rate_kg_N_ha,
pch = 16, col = zone_cols[z])
}
abline(v = 1000 * nitrogen_price / wheat_price, lty = 3, col = "#555555")
legend("topright", legend = c("Low fertility", "High fertility", "Baseline price ratio"),
col = c(zone_cols, "#555555"), lty = c(1, 1, 3), bty = "n")
dev.off()png
2
png("04_outputs/04_model_diagnostics.png", width = 1800, height = 1550, res = 170)
par(mfrow = c(2, 2), mar = c(4.2, 4.3, 3.1, 1))
for (z in zone_levels) {
f <- fits[[z]]
plot(fitted(f), resid(f), pch = 16, col = zone_cols[z],
xlab = "Fitted yield (Mg/ha)", ylab = "Residual (Mg/ha)",
main = paste(tools::toTitleCase(z), "— residuals"))
abline(h = 0, lty = 2)
qqnorm(resid(f), pch = 16, col = zone_cols[z],
main = paste(tools::toTitleCase(z), "— normal Q–Q"))
qqline(resid(f), col = "#B23636", lwd = 1.5)
}
dev.off()png
2

The low-fertility yield response rises steeply at small and moderate nitrogen doses, then flattens near the high end of the experiment. In the high-fertility zone, the visible fitted response is still rising at 260 kg N/ha; an extrapolated vertex would not be an observed optimum.

The return curves peak before—or at a different point than—the yield curves. The economic criterion values additional grain only when its sale value exceeds the additional nitrogen expense. This distinction matters even when the model predicts a slightly larger harvest at a higher dose.

The lines follow the marginal decision rule rather than a universal “best dose.” A grower facing lower grain prices or more expensive nitrogen needs a larger extra yield to justify another kilogram of fertilizer, so the modeled optimum falls.

The residual panels remind us that a neat fitted curve is not a guarantee about variability or uncertainty. Apparent departures at distribution tails and the unobserved block structure caution against overinterpreting precise dose recommendations.
7. Why reproducible calculations matter
A fitted recommendation is most useful when its assumptions can be examined. The model coefficients, dose means, economic comparisons and diagnostics form a reproducible trail from the original plots to the final scientific interpretation.
8. What this example can—and cannot—tell us
For this historical experiment and the illustrative price assumptions, the estimated economic N rate is lower than the yield-maximizing rate in both fertility zones. The critical idea is marginal return: extra fertilizer is worthwhile only while its expected grain value exceeds its marginal cost. The values differ by fertility zone because the response curves have different slopes and curvature.
These are model-dependent historical estimates, not universal fertilizer prescriptions. Soil nitrogen supply, cultivar, weather, current local prices, timing, other expenses and environmental consequences can alter the decision. The released data lack the original block identifiers, so formal block-adjusted uncertainty cannot be reconstructed. Neither unmeasured environmental costs nor out-of-range doses are resolved by the calculations here.
Sources and further reading
agridatpackage: Bachmaier nitrogen wheat experiment.- Bachmaier, M. (2009). A Confidence Set for That X-Coordinate Where a Quadratic Regression Model Has a Given Gradient. Statistical Papers, 50, 649–660. DOI.
- Bachmaier, M. (2012). Sources of Inaccuracy When Estimating Economically Optimum N Fertilizer Rates. Agricultural Sciences. Article.
Comments
Post a Comment