科研 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.
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
- 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).
- 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.
- A plain
aov()/statsmodels.OLSANOVA 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,lmerTestand/oremmeans; or - Python 3 with
statsmodels>=0.14(pip install statsmodels pandas) forMixedLM. Python'sMixedLMsupports one crossed/nested random-effects grouping well but not arbitrary split-plot variance-component structures as cleanly aslme4— for a split-plot or split-split-plot design, prefer R/lme4 if either is available; useMixedLMfor 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) orresult.residvs. 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)orbinomial), 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
- 农业深度研究综述Deep research producing a source-validated literature review for an agricultural question, ranked by journal quartile. Reuses food-deep-research machinery. Use for an agronomy deep dive.
- 农业科学论文撰写系统Multi-subagent manuscript system for agricultural science with field-trial/soil/animal reporting standards. Reuses food-paper machinery. Use for an agronomy or soil-science manuscript.
- 农业研究全流程编排Orchestrates the full agricultural research-to-publication workflow: journal selection, research, writing, figures, peer review, revision. Use to manage an agronomy project end to end.
- 农业综述转可编辑PPTConverts an agricultural-science report or manuscript into a fully editable PowerPoint deck, reusing food-ppt machinery with agronomy framing. Use for slides from a field-trial report.
- 农业遥感作物制图Maps crop types from Sentinel-2 imagery with Random Forest, extracts NDVI phenology, estimates LAI, and predicts yield via Google Earth Engine. Use for field/county crop remote sensing.
- 农业文献证据综合Multi-source literature and evidence-synthesis workflow for agricultural science, ranked by journal quartile. Reuses food-research machinery. Use for an agronomy or soil-science evidence review.
- 农业论文多审稿人模拟Simulates an editorial peer-review panel for an agricultural manuscript, grounded in cited and field literature. Use for a pre-submission review or mock referee report in agriculture.
- 作物生长模拟Simulates crop growth with WOFOST/AquaCrop via PCSE, pulls weather from NASA POWER, and runs yield-gap analysis under climate scenarios. Use for agronomic intervention evidence.
- 通用深度文献综述研究General-purpose deep research producing a source-validated, fully written literature review via a 12-subagent team. Use for a thorough review or deep-dive needing verified sources.
- 学术文献全文合法获取Lawfully acquires full-text PDFs via open access, the user’s reference manager, or their logged-in library session; never bypasses paywalls. Use to fetch papers before research or review.
- 食品营养论文图表系统Builds publication-ready figures (bar/box, dose-response, PCA, heatmaps, forest plots) to a target journal’s spec, with a privacy scan before delivery. Use for a journal-ready figure.
- 食品科学论文撰写系统Multi-subagent manuscript system for food/nutrition science: frames questions, analyzes data, writes statistics, drafts, polishes, and reformats for a journal. Use to write or revise a paper.
- 食品研究全流程编排Orchestrates the whole food/nutrition research-to-publication workflow with quality gates: journal selection, research, writing, figures, review, revision. Use to manage a paper end to end.
- 食品研究报告转可编辑PPTConverts a food/agriculture report or manuscript into a fully editable PowerPoint deck with python-pptx: outline, grounded slide text, themed layout. Use to make slides from a paper.
- 科研基金申请书编排Orchestrates a food/agriculture funding proposal to a scheme’s format (headings, length limit, criteria), drafting or revising via the research/paper/review skills. Use for a grant application.
- 食品营养文献综合研究Runs a multi-source literature and evidence-synthesis workflow for food/nutrition science: search, two-phase screening, synthesis, evidence grading. Use for a deep review or systematic-review scope.
- 食品论文多审稿人模拟Simulates an editorial peer-review panel for a food/nutrition manuscript, grounded in cited and field literature first. Use for a pre-submission review or mock referee report.
- FAOSTAT食品系统数据分析Analyzes FAOSTAT food-balance, dietary-diversity, and trade/production data for cross-country food-systems indicators. Use for a country-comparison food-security dataset.
- 土壤数据空间分析Pulls and analyzes soil properties from SoilGrids (global) and SSURGO (US-only), computes SOC stock, and runs kriging interpolation. Use for a soil-property or soil-carbon map.
常见问题
田间试验混合模型分析能做什么?
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 收录的每个版本都会记录内容摘要与权限声明,当前版本已通过安全审核。