科研 Skill

田间试验混合模型分析

field-trial-mixed-models

Analyzes RCBD, split-plot, and multi-site field-trial data with mixed models in R (lme4) or Python (statsmodels), using correct error strata. Use for a crop or soil field-trial analysis.

发布者 Codar安全审核通过v0.1.0更新于 2026-11-18

SKILL.md

Field-Trial Mixed Models — Correct Error Strata for RCBD / Split-Plot / Multi-Site Trials

Fits the statistical model a field-trial design actually calls for, so the significance tests in a paper or proposal (food-paper/agri-paper) are run against the right error term instead of a flat one-way ANOVA. agri-research, agri-paper, and agri-review already tell the agent to watch for pseudoreplication and an unstated experimental unit — this skill is the missing piece that actually runs the correct model instead of only flagging the risk in prose.

When to use

Use when the user has (or describes) field, greenhouse, or soil-incubation data from one of these designs and wants the right test, not just a label for it:

  • RCBD (Randomized Complete Block Design) — one treatment factor, blocked.
  • Split-plot / split-split-plot — a whole-plot factor applied to larger plots (e.g. irrigation) and a sub-plot factor nested within it (e.g. cultivar), analyzed with separate error strata for each factor.
  • Multi-environment trial (MET) — the same trial repeated across sites and/or years, where genotype × environment (G×E) is itself a term of interest, not noise to average away.
  • Repeated measures on the same plot/animal/pen over time (growth curves, repeated soil sampling) where observations are not independent.

Do not use for a simple two-group comparison with true independent replicates (a plain t-test/one-way ANOVA is correct and simpler there — don't over-model), for remote-sensing pixel data (agri-remote-sensing), or for process-based crop simulation (crop-modeling, which simulates rather than fits observed data).

Core distinction: fixed vs. random, and the error term

  1. Identify the experimental unit for each factor — the thing that was independently, physically treated. In a split-plot, the whole-plot factor's experimental unit is the whole plot, not the sub-plot; treating sub-plot observations as the whole-plot factor's replicates is the classic pseudoreplication error (inflates whole-plot-factor significance).
  2. Random effects = block, whole-plot (as a random intercept nested in block), site, year, and genotype-by-environment interaction when G×E itself isn't the object of inference. Fixed effects = the treatment factors the user actually wants a p-value / estimate for.
  3. A plain aov()/statsmodels.OLS ANOVA on a split-plot or MET dataset, without the matching random-effects structure, uses one pooled error term for everything — it is a real, common error that the agri-* writing skills warn about but do not detect in actual data. This skill's whole job is to not make that mistake.

Prerequisites

  • R with lme4 (install.packages("lme4")) and, for split-plot F-tests with denominator degrees of freedom, lmerTest and/or emmeans; or
  • Python 3 with statsmodels>=0.14 (pip install statsmodels pandas) for MixedLM. Python's MixedLM supports one crossed/nested random-effects grouping well but not arbitrary split-plot variance-component structures as cleanly as lme4 — for a split-plot or split-split-plot design, prefer R/lme4 if either is available; use MixedLM for a simpler single-random-intercept case (RCBD, single-site repeated measures) or when only Python is available.
  • Tidy input: one row per observation, with explicit columns for block, whole-plot ID, treatment factor(s), site/year (if MET), and the response.

Workflow

1. Confirm the design with the user before modeling

Ask (or infer from the data/methods description) which design this is, and get the block/whole-plot/treatment columns named explicitly. Do not guess a split-plot vs. RCBD structure from column names alone — if genuinely ambiguous, ask one targeted question rather than silently picking the simpler (and often wrong) model.

2a. RCBD — R

library(lme4); library(lmerTest)
m <- lmer(yield ~ treatment + (1 | block), data = df)
anova(m)                      # Type III F-test via Satterthwaite df (lmerTest)
library(emmeans)
emmeans(m, pairwise ~ treatment, adjust = "tukey")

2b. RCBD — Python (statsmodels MixedLM)

import statsmodels.formula.api as smf

model = smf.mixedlm("yield ~ treatment", data=df, groups=df["block"])
result = model.fit(reml=True)
print(result.summary())

MixedLM does not give a split-plot-style F-test with denominator df out of the box; for a treatment-level significance test, use a likelihood-ratio test between the full model and one with treatment dropped (reml=False for both when comparing fixed effects).

2c. Split-plot — R (preferred)

# whole_plot nested in block; sub_treatment varies within whole_plot
m <- lmer(yield ~ whole_treatment * sub_treatment +
             (1 | block/whole_plot), data = df)
anova(m)   # whole_treatment is tested against the block:whole_plot stratum,
           # sub_treatment and the interaction against residual

The (1 | block/whole_plot) term is what supplies the two separate error strata; omitting it (i.e. lm(yield ~ whole_treatment * sub_treatment)) is the exact pseudoreplication mistake this skill exists to avoid.

2d. Multi-environment trial — R

m <- lmer(yield ~ genotype * env + (1 | env:block) + (1 | genotype:env),
          data = df)
# If env should be treated as random (inference beyond the sites tested):
m2 <- lmer(yield ~ genotype + (1 | env) + (1 | genotype:env) + (1 | env:block),
           data = df)

Report which choice was made (env fixed vs. random) and why — it changes what the genotype main effect generalizes to.

3. Diagnostics (run before trusting any p-value)

  • Residual plots: plot(m) (R) or result.resid vs. fitted (Python) — look for fan-shaped variance (consider a log/sqrt transform or a generalized model) and gross non-normality.
  • Random-effects variance — check block/whole-plot variance isn't being estimated as exactly zero (a sign the random term is unidentifiable with this data — e.g. too few blocks); R: VarCorr(m).
  • Singular fit warnings (isSingular(m) in R) mean the random-effects structure is too complex for the data — simplify (drop an interaction random term) rather than ignore the warning and report the estimates as if nothing happened.
  • Count or proportion data (disease incidence, pest counts, germination %) need a generalized linear mixed model (glmer(..., family = poisson) or binomial), not an untransformed linear model on counts/proportions.

4. Report for the paper

State explicitly, in Methods: the design, the model formula (fixed and random terms), the software and package version, the denominator-df method for F-tests (e.g. Satterthwaite via lmerTest), and the post-hoc comparison method and multiplicity correction (e.g. Tukey via emmeans). This satisfies food-paper/agri-paper's statistician stage requirement for a reproducible Methods statement, and gives agri-review's methodology reviewer the detail it needs to actually check the model rather than take it on faith.

Limitations

  • This skill fits the model; it does not replace experimental-design planning done before data collection (power/replication adequacy) or crop-modeling's process-based simulation.
  • Denominator-degrees-of-freedom methods (Satterthwaite/Kenward-Roger) and some split-plot variance-component structures are substantially easier to get right in R/lme4 than in Python/statsmodels; for anything beyond a single random intercept, prefer R if it is available in the current environment.
  • Small numbers of blocks/sites (fewer than ~4-5) often make a random-effects variance for that term inestimable (it collapses to zero); that is a sample-size limitation of the data, not a bug in the model — say so rather than reporting a spuriously precise estimate.
  • Does not itself check for missing-completely-at-random assumptions when plots are missing (e.g. storm-damaged plots dropped); state how missing plots were handled.

Quality checks before delivering results

  • The random-effects structure matches the design actually used (whole-plot nesting present for a split-plot; block present for an RCBD).
  • No singular-fit warning left unaddressed.
  • Residual diagnostics checked, not just the p-value table.
  • Methods paragraph states software, package, model formula, df method, and post-hoc correction — reproducible from that paragraph alone.
  • Count/proportion responses modeled with an appropriate GLMM family, not raw linear regression on counts or percentages.

示例提示词

帮我用正确的误差层级分析这个裂区试验设计的产量数据。

所属插件

农业与食品科学面向农学、食品与营养研究:作物模型、农业遥感、土壤数据、食物系统数据,以及食品/农业领域的文献调研、综述、选刊、论文与汇报。

安装该插件会一并获得同领域的 20 个 Skill / MCP。

同插件的其他科研 Skill

常见问题

田间试验混合模型分析能做什么?

Analyzes RCBD, split-plot, and multi-site field-trial data with mixed models in R (lme4) or Python (statsmodels), using correct error strata. Use for a crop or soil field-trial analysis。

如何安装田间试验混合模型分析?

在科搭 Codar 左侧点击「插件」,在「组件」页签搜索「田间试验混合模型分析」并安装;在 Claude Code 或 Codex 中可以发送本页的安装提示词,或下载 Skill 包后解压到 ~/.claude/skills 或 ~/.codex/skills。

田间试验混合模型分析需要哪些权限?

该科研 Skill没有声明额外权限;执行具体操作时仍由 Agent 按自身规则请求确认。

田间试验混合模型分析经过官方审核吗?

是。SpeedSkills 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。