Package {AgriDesign}


Title: Design and Analysis of Agricultural Experiments
Version: 1.0.0
Description: Plans and analyses agricultural experiments with classical designs: completely randomised, randomised complete blocks (also generalised), Latin, Graeco-Latin and Youden squares, balanced, cyclic, alpha (Patterson and Williams (1976) <doi:10.1093/biomet/63.1.83>) and lattice incomplete blocks, augmented designs, factorials, split-plots, strip-plots, split-split-plots and nested designs, with or without covariates. Each analysis of variance tests every term against its own error stratum, with Satterthwaite (1946) <doi:10.2307/3002019> degrees of freedom for pooled errors; least-squares means are separated with eleven multiple-comparison procedures, among them Dunnett (1955) <doi:10.1080/01621459.1955.10501294>, and compact letters, with simple effects, trends and contrasts. It checks the assumptions, offers transformations and rank-based alternatives, recovers inter-block information by restricted maximum likelihood (Patterson and Thompson (1971) <doi:10.1093/biomet/58.3.545>), randomises field layouts with field books and power calculations, draws publication figures and writes HTML reports. It also includes plant breeding analyses (additive main effects and multiplicative interaction, Gollob (1968) <doi:10.1007/BF02289676>; stability, Eberhart and Russell (1966) <doi:10.2135/cropsci1966.0011183X000600010011x>; line by tester; diallel, Griffing (1956) <doi:10.1071/BI9560463>; North Carolina designs) and plant pathology tools (area under the disease progress curve and stairs, Simko and Piepho (2012) <doi:10.1094/PHYTO-07-11-0216>; soil heterogeneity). Only base R is used.
License: GPL (≥ 3)
URL: https://github.com/luisangelbg/AgriDesign-R, https://luisangelbg.github.io/AgriDesign-R/
BugReports: https://github.com/luisangelbg/AgriDesign-R/issues
Depends: R (≥ 4.1.0)
Imports: graphics, grDevices, stats, utils
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-GB
LazyData: true
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-08 04:08:58 UTC; luisa
Author: Luis Ángel Barrera-Guzmán ORCID iD [aut, cre, cph]
Maintainer: Luis Ángel Barrera-Guzmán <lbarrerag@chapingo.mx>
Repository: CRAN
Date/Publication: 2026-12-03 15:50:14 UTC

AgriDesign: design and analysis of agricultural experiments

Description

AgriDesign logo

Details

Analysis of variance of the classical agricultural designs with the right error strata, least-squares means, assumption checks, mean separation, figures, reports and randomised field layouts. Base R only.

Start with designs() to see the designs available and design_anova() to analyse one.

Author(s)

Maintainer: Luis Ángel Barrera-Guzmán lbarrerag@chapingo.mx (ORCID) [copyright holder]

Authors:

See Also

Useful links:


Standard methods for fitted designs

Description

residuals(), fitted(), nobs() and anova() work on the result of design_anova() as on a linear model. anova() returns the analysis of variance as a data frame of class "anova", with the error stratum against which each term is tested. as.data.frame() on the result of compare_means() returns its table of means with their letters.

Usage

## S3 method for class 'ad_anova'
residuals(object, type = c("response", "studentized"), ...)

## S3 method for class 'ad_anova'
fitted(object, ...)

## S3 method for class 'ad_anova'
nobs(object, ...)

## S3 method for class 'ad_anova'
anova(object, ...)

## S3 method for class 'ad_comparison'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

object, x

A fitted design from design_anova() (or, for as.data.frame(), a comparison from compare_means()).

type

For residuals(): "response" (observed minus fitted) or "studentized" (internally studentized, as stats::rstandard()).

row.names, optional, ...

Passed on or not used.

Value

A numeric vector (residuals, fitted values), a count (nobs), or a data frame.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
anova(fit)
head(residuals(fit, type = "studentized"))
nobs(fit)
as.data.frame(compare_means(fit, "Nitrogen_kg_ha"))

Colours of the AgriDesign figures

Description

The categorical palette used by the figures of the package (forest green, ochre, blue, brick red, plum...), recycled to n colours.

Usage

agri_colors(n)

Arguments

n

Number of colours.

Value

A character vector of colours.

Examples

agri_colors(4)

AMMI analysis of a multi-environment trial

Description

Additive main effects and multiplicative interaction model (Gollob 1968; Gauch 1988): the analysis of variance of genotypes and environments, and the singular value decomposition of the genotype x environment interaction into principal axes (IPCA), each tested with the degrees of freedom of Gollob (1968).

Usage

ammi(
  data,
  response,
  genotype,
  environment,
  block = NULL,
  mse = NULL,
  df_error = NULL,
  reps = 1,
  n_axes = NULL
)

Arguments

data

A data frame in long format.

response

Name of the numeric response column.

genotype, environment

Names of the genotype and environment columns.

block

Optional name of the block (replicate) column; blocks are taken as nested within environments.

mse, df_error

Error mean square (plot scale) and its degrees of freedom, only when the data hold one mean per cell.

reps

Number of replicates behind each mean, when the data hold one mean per cell.

n_axes

Number of interaction axes shown in the analysis of variance (the rest is pooled as the residual interaction); by default all of them.

Details

The data must be balanced: every genotype in every environment with the same number of replicates. With plot data the error comes from the trial itself (with block, blocks within environments are taken out and environments are tested against them). With one mean per cell, give the pooled error of the trial (mse, on the plot scale, with df_error) and the number of replicates behind each mean (reps).

Interaction scores are scaled by the square root of the singular values (symmetric scaling), so that the product of a genotype score and an environment score is their interaction. The sign of every axis is fixed so that the environment with the largest absolute score is positive. The AMMI stability value (ASV) of Purchase et al. (2000) is sqrt((SS1 / SS2 * IPCA1)^2 + IPCA2^2); the yield stability index (YSI) adds its rank to the rank of the mean (highest mean = 1).

Value

An object of class "ad_ammi": the analysis of variance (anova), the interaction axes (axes: singular value, sum of squares, percentage of the interaction, Gollob degrees of freedom and F test), genotype and environment means with their scores (genotypes, environments, the first with ASV and YSI), the table of means and the interaction residuals.

References

Gollob, H. F. (1968) Psychometrika 33, 73-115. Gauch, H. G. (1988) Biometrics 44, 705-715. Purchase, J. L., Hatting, H. and van Deventer, C. S. (2000) South African Journal of Plant and Soil 17, 101-107.

Examples

fit <- ammi(maize_met, "Yield_t_ha", "Hybrid", "Environment", block = "Block")
fit
plot(fit)
plot(fit, type = "ammi2")

Area under the disease progress curve and stairs

Description

audpc() integrates the disease progress curve with trapezoids (Shaner and Finney 1977); audps() gives the area under the disease progress stairs of Simko and Piepho (2012), which weighs the first and the last assessment as much as the others: AUDPS = AUDPC + (y1 + yn) / 2 * D / (n - 1), with D the time from the first to the last assessment.

Usage

audpc(
  evaluation,
  dates,
  type = c("absolute", "relative", "standardized"),
  ymax = 100
)

audps(
  evaluation,
  dates,
  type = c("absolute", "relative", "standardized"),
  ymax = 100
)

Arguments

evaluation

Disease intensities: a vector (one unit) or a matrix or data frame with one row per unit and one column per assessment.

dates

Times of the assessments (days or Date values), strictly increasing.

type

"absolute", "relative" or "standardized".

ymax

Largest possible intensity (100 for percentages, 1 for proportions, the top of a rating scale).

Details

type = "relative" divides the area by the largest possible one, so it lies between 0 and 1: ymax * D for the AUDPC and ymax * D * n / (n - 1) for the AUDPS, whose stairs are n / (n - 1) times as wide as the curve. type = "standardized" divides by the width only and gives the mean intensity over the epidemic, in the units of the assessments. Missing assessments of a unit are skipped (its area then spans its own assessments only).

Value

A numeric vector with one area per unit.

References

Shaner, G. and Finney, R. E. (1977). The effect of nitrogen fertilization on the expression of slow-mildewing resistance in Knox wheat. Phytopathology 67, 1051-1056.

Simko, I. and Piepho, H.-P. (2012). The area under the disease progress stairs: calculation, advantage, and application. Phytopathology 102, 381-389.

See Also

audpc_by_unit() to compute them for every plot of a trial.

Examples

days <- c(7, 14, 21, 28, 35)
sev <- c(1, 4, 12, 30, 52)
audpc(sev, days)
audps(sev, days)
audpc(sev, days, type = "relative")
audps(rbind(plot1 = sev, plot2 = sev / 2), days, type = "standardized")

AUDPC and AUDPS of every plot of a trial

Description

Takes the assessments in long format (one row per plot and date), sorts them by time within each plot and returns one row per plot with its areas, ready for design_anova().

Usage

audpc_by_unit(data, response, time, units, ymax = 100)

Arguments

data

A data frame in long format.

response

Column with the disease intensity.

time

Column with the time of assessment (numbers or Date).

units

Column(s) that identify a plot, for instance c("Block", "Treatment"); they are kept in the result.

ymax

Largest possible intensity (100 for percentages, 1 for proportions, the top of a rating scale).

Value

A data frame with the unit columns, the number of assessments (n), the time spanned (duration) and the areas audpc, audps, their relative (audpc_rel, audps_rel) and standardised (audpc_std, audps_std) forms.

Examples

a <- audpc_by_unit(blight_progress, "Severity_pct", "Day", c("Block", "Treatment"))
head(a)
fit <- design_anova(a, "audps", "Treatment", block = "Block")
compare_means(fit, "Treatment")

Yield of five bean varieties (CRD)

Description

Completely randomised design with five common bean varieties.

Usage

bean_varieties

Format

A data frame with 20 rows and 3 columns:

Plot

Plot number.

Variety

Bean variety.

Yield_kg_plot

Yield, kg per plot.

Examples

design_anova(bean_varieties, "Yield_kg_plot", "Variety")

Sorghum hybrids in a balanced incomplete block design (simulated)

Description

Simulated grain yields of seven sorghum hybrids in seven blocks of three plots: every hybrid appears three times and every pair of hybrids meets once in a block (t = 7, k = 3, r = 3, lambda = 1).

Usage

bib_sorghum

Format

A data frame with 21 rows and 3 columns:

Block

Block (1-7).

Hybrid

Hybrid (H1-H7).

Yield_t_ha

Grain yield, t/ha.

Examples

durbin_test(bib_sorghum, "Yield_t_ha", "Hybrid", "Block")

Late blight progress under four fungicide programmes (simulated)

Description

Simulated severity of late blight (percentage of leaf area affected) in a potato trial with four fungicide programmes in four blocks, assessed weekly from day 21 to day 63 after planting. The values were generated with logistic epidemics (data-raw/make-data-pathology.R).

Usage

blight_progress

Format

A data frame with 112 rows and 4 columns:

Block

Block (1-4).

Treatment

Fungicide programme: Untreated, Contact, Systemic, Alternated.

Day

Days after planting.

Severity_pct

Disease severity, percent.

Examples

a <- audpc_by_unit(blight_progress, "Severity_pct", "Day", c("Block", "Treatment"))
design_anova(a, "audpc", "Treatment", block = "Block")

Box-Cox profile likelihood of a design

Description

Profile log-likelihood of the Box-Cox power lambda for the model of the design, its maximum, the 95 % interval and the nearest conventional power (-1, -0.5, 0, 0.5, 1 or 2).

Usage

box_cox(fit, lambda = seq(-2, 2, by = 0.1))

Arguments

fit

An "ad_anova" object from design_anova().

lambda

Grid of powers.

Value

A list with the profile (profile), the estimate (lambda), the 95 % interval (lower, upper), the nearest conventional power (rounded) and whether the interval contains 1 (contains_one); NULL when the response has zeros or negative values.

Examples

fit <- design_anova(tomato_factorial, "Yield_kg_plant", c("Variety", "Fertilizer"),
                    block = "Block")
box_cox(fit)[c("lambda", "lower", "upper", "rounded")]

Check the assumptions of the analysis of variance

Description

Runs the usual checks on the residuals of a fitted design: normality (Shapiro-Wilk, Anderson-Darling, Jarque-Bera), homogeneity of variances among treatments (Levene with median and with mean, Bartlett, Fligner-Killeen, Hartley's Fmax), additivity of blocks and treatments (Tukey's one-degree-of-freedom test, only for blocked designs), independence in data order (Durbin-Watson) and extreme studentized residuals. The checks are summarised in a grade from A (assumptions satisfied) to D (several assumptions fail).

Usage

check_assumptions(fit, alpha = 0.05)

Arguments

fit

An "ad_anova" object from design_anova().

alpha

Significance level of the checks.

Details

Each check is rated "ok" when its p-value is at least alpha, "warn" when it lies between alpha / 5 and alpha and "bad" below alpha / 5. The grade is D with two or more "bad" checks, C with one "bad" or two "warn", B with a single "warn" and A otherwise.

Value

An object of class "ad_assumptions" with the table of tests (tests), the residuals and studentized residuals (residuals), the observations with |studentized residual| > 2.5 (suspicious) and the grade.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
check_assumptions(fit)

Compare treatment means

Description

Separates the least-squares means of a treatment factor (or of the combinations of two factors) with one of eleven procedures and labels them with letters: levels that share a letter do not differ. Each factor is compared with its own error stratum (for instance, main plots of a split-plot with Error a).

Usage

compare_means(
  fit,
  factor,
  method = "tukey",
  alpha = 0.05,
  control = NULL,
  by = NULL
)

Arguments

fit

An "ad_anova" object from design_anova().

factor

Treatment factor whose means are compared; two names compare all their combinations together (not available for split- or strip-plots, where by should be used).

method

Procedure, see Details.

alpha

Significance level.

control

Level used as control by Dunnett's test (default: first level).

by

Optional second treatment factor: compare factor within each of its levels.

Details

Methods: "tukey" (Tukey-Kramer HSD), "lsd" (Fisher), "bonferroni", "sidak", "holm", "duncan", "snk" (Student-Newman-Keuls), "regwq", "scheffe", "dunnett" (each level against control; the groups are then "*" for a difference with the control and "ns") and "games_howell" (unequal variances; own SE and Welch df per pair).

With by, the comparison is made within each level of another factor (simple effects). In split-plots the sub-plot factor within a main plot uses Error b, and the main-plot factor within a sub-plot level uses the pooled error ⁠[(b - 1) Eb + Ea] / b⁠ with Satterthwaite degrees of freedom; strip-plots pool their errors the same way.

Value

An object of class "ad_comparison" with the means and their letters (means), the pairwise comparisons (pairs), the minimum significant difference (msd, for equal replication) and the error used.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
compare_means(fit, "Nitrogen_kg_ha")

fit <- design_anova(bean_varieties, "Yield_kg_plot", "Variety")
compare_means(fit, "Variety", method = "dunnett", control = "Negro Jamapa")

fit <- design_anova(split_irrigation, "Yield_t_ha", c("Irrigation", "Variety"),
                    block = "Block", design = "split_rcbd")
compare_means(fit, "Variety", by = "Irrigation")

Analysis of variance of an experimental design

Description

Fits the linear model of a classical agricultural design and tests every term against the right error stratum (for instance, main plots of a split-plot against Error a).

Usage

design_anova(
  data,
  response,
  treatment,
  block = NULL,
  row = NULL,
  col = NULL,
  covariate = NULL,
  design = NULL,
  ss_type = 3,
  random_blocks = TRUE,
  random_nested = TRUE,
  transform = NULL
)

Arguments

data

A data frame in long format: one row per plot.

response

Name of the numeric response column.

treatment

Name(s) of the treatment factor(s). In split-plots, strip-plots and nested designs the order matters: the first factor goes on main plots (or is the outer factor).

block

Name of the block column; two names (replicate, block within replicate) for incomplete block designs.

row, col

Names of the row and column factors of a Latin square.

covariate

Name(s) of numeric covariates (analysis of covariance).

design

Identifier of the design (see designs()). When NULL the design is suggested from the roles given.

ss_type

Type of sums of squares: 3 (default, adjusted for all other terms) or 1 (sequential).

random_blocks

In a generalised RCBD, treat blocks as random and test treatments against the block x treatment interaction.

random_nested

In a nested design, treat the inner factor as random and test the outer factor against it.

transform

Optional transformation of the response before the analysis, by its identifier in transformations() ("log", "sqrt", "asin"...). Means are then also reported back-transformed.

Value

An object of class "ad_anova": a list with the ANOVA table (table), the error strata (strata), the grand mean, the coefficient of variation, R squared, the fitted model and the data used.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha",
                    block = "Block", design = "rcbd")
fit

design_anova(split_irrigation, "Yield_t_ha", c("Irrigation", "Variety"),
             block = "Block", design = "split_rcbd")

Efficiency factor of a block design

Description

The efficiency factor of a block design is the harmonic mean of its canonical efficiency factors: the average variance of a treatment difference in a complete block design with the same replication, divided by the average variance in this design (intra-block analysis, same error variance). It is 1 for complete blocks and the target of incomplete block designs. For resolvable designs the upper bound of Patterson and Williams (1976) is also reported.

Usage

design_efficiency(x, treatment = "Treatment", block = NULL)

Arguments

x

An "ad_layout" object from make_design(), or a data frame.

treatment, block

Column names of the treatment and of the (incomplete) block when x is a data frame. For a layout the blocks are the incomplete blocks when there are any.

Value

A list with the efficiency factor E, the canonical efficiency factors, whether the design is connected, and upper_bound for equireplicated resolvable designs.

Examples

lay <- make_design("alpha", trt = 12, r = 2, k = 3, seed = 1)
design_efficiency(lay)$E

Write an HTML report of an analysis

Description

Builds a self-contained HTML report of a fitted design: a materials and methods paragraph ready to adapt, descriptive statistics, the assumption checks with their grade, the analysis of variance with a draft of the results, the means with their letters, trend analysis of quantitative factors, simple effects of two-factor interactions, figures embedded as vector graphics, appendices with the pairwise comparisons and the data, and how to cite the software. Open it in any web browser and print it to PDF from there (A4 page style included).

Usage

design_report(
  fit,
  file = NULL,
  title = NULL,
  authors = "",
  affiliation = "",
  trial = "",
  objective = "",
  units = "",
  method = "tukey",
  alpha = 0.05,
  control = NULL,
  assumptions = TRUE,
  figures = TRUE,
  pairwise = TRUE,
  data = FALSE,
  cite = TRUE,
  open = FALSE
)

Arguments

fit

An "ad_anova" object from design_anova().

file

Output file (.html); NULL only returns the HTML.

title, authors, affiliation, trial, objective

Texts for the head of the report.

units

Units of the response, for the methods paragraph.

method, alpha

Mean-separation procedure and significance level (see compare_means()).

control

Control level for method = "dunnett".

assumptions, figures, pairwise, data, cite

Include those sections.

open

Open the report in the browser when it is written.

Value

The HTML text, invisibly.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
f <- tempfile(fileext = ".html")
design_report(fit, f, title = "Nitrogen rates in maize", units = "t/ha", figures = FALSE)
file.exists(f)

List the designs that can be analysed or randomised

Description

designs() lists the 16 designs that design_anova() analyses; designs("layout") lists the 16 designs that make_design() randomises, with the arguments each one needs and the design to give to design_anova() once the responses are in the field book.

Usage

designs(type = c("analysis", "layout"))

Arguments

type

"analysis" (designs of design_anova()) or "layout" (designs of make_design()).

Details

Designs analysed by design_anova() (⁠design =⁠):

id Design Roles
crd Completely randomised treatment
rcbd Randomised complete blocks treatment, block
grcbd Generalised RCBD (replicates within blocks) treatment, block
latin Latin square treatment, row, col
graeco Graeco-Latin square treatment, row, col, block (Greek letters)
youden Youden square treatment, row, col
bib Incomplete blocks (BIBD, cyclic) treatment, block
ibd Resolvable incomplete blocks (lattice, alpha) treatment, block = c(rep, block)
augmented Augmented (checks and new entries) treatment, block
fact_crd Factorial in CRD (2 to 4 factors) treatment = c(A, B, ...)
fact_rcbd Factorial in RCBD (2 to 4 factors) treatment = c(A, B, ...), block
split_rcbd Split-plot in RCBD treatment = c(main, sub), block
split_crd Split-plot in CRD treatment = c(main, sub), block (replicate)
strip_rcbd Strip-plot (split-block) treatment = c(A, B), block
splitsplit_rcbd Split-split-plot in RCBD treatment = c(main, sub, sub-sub), block
nested Nested (hierarchical) treatment = c(outer, inner)

Designs randomised by make_design() (first argument; C is optional in factorials, and the conditions on the number of treatments and the block size are in the conditions column of designs("layout")):

id Design Arguments Analyse as
crd Completely randomised trt, r crd
rcbd Randomised complete blocks trt, r rcbd
latin Latin square trt latin
graeco Graeco-Latin square trt, greek graeco
youden Youden square trt, k youden
bib Balanced incomplete blocks trt, k bib
cyclic Cyclic incomplete blocks trt, k, r bib
ibd Resolvable incomplete blocks trt, k, r ibd
alpha Alpha design trt, k, r ibd
lattice Square lattice trt, k, r ibd
augmented Augmented checks, entries, r augmented
fact_crd Factorial in CRD A, B, C, r fact_crd
fact_rcbd Factorial in RCBD A, B, C, r fact_rcbd
split_rcbd Split-plot in RCBD A, B, r split_rcbd
strip Strip-plot A, B, r strip_rcbd
splitsplit Split-split-plot A, B, C, r splitsplit_rcbd

Value

A data frame. For "analysis": the identifier of each design (the value to pass to ⁠design =⁠ in design_anova()), its name, the number of treatment factors and block columns, and whether it needs rows and columns. For "layout": the identifier (the first argument of make_design()), its name, the arguments it needs (in parentheses when optional), its conditions and the design of design_anova() that analyses its field book.

Examples

designs()
designs("layout")

# the layout reports the call that analyses it
make_design("strip", A = c("Drip", "Furrow"), B = c("V1", "V2", "V3"), r = 3, seed = 1)$analysis

Diallel analysis by Griffing's methods

Description

Griffing's (1956) analysis of a diallel cross by any of the four methods: 1, parents, F1 and reciprocals; 2, parents and one F1 per pair; 3, F1 and reciprocals; 4, one F1 per pair. The analysis of variance of general (GCA) and specific (SCA) combining ability, and of reciprocal effects (split into maternal and non-maternal, Cockerham 1963) in methods 1 and 3; the effects with their exact standard errors (Model I), the standard errors of differences, and the variance components of Model II with the additive and dominance variances.

Usage

diallel(
  data,
  response,
  parent1,
  parent2,
  block = NULL,
  method = 1,
  inbreeding = 1
)

Arguments

data

A data frame in long format.

response

Name of the numeric response column.

parent1, parent2

Names of the female and male parent columns (equal for the parents themselves).

block

Name of the block column (randomised complete blocks); when NULL the entries are taken as completely randomised.

method

Griffing's method, 1 to 4.

inbreeding

Inbreeding coefficient of the parents, used to turn the Model II components into additive and dominance variances (1 for inbred lines).

Details

The combining-ability analysis is on the scale of entry means: the error is the error mean square of the trial divided by the number of replicates. Rows that do not belong to the method are left out (parents in methods 3 and 4; reciprocals in methods 2 and 4, where the cross with the first parent as female is kept), so one data set serves all methods. The effects are the least-squares estimates under Griffing's restrictions (sum of GCA effects zero; SCA effects summing to zero for every parent, the selfs counted twice in method 2), which reproduce his closed formulas.

Value

An object of class "ad_diallel".

References

Griffing, B. (1956) Australian Journal of Biological Sciences 9, 463-493. Cockerham, C. C. (1963) In Statistical Genetics and Plant Breeding, NAS-NRC 982, 53-94.

Examples

dl <- diallel(maize_diallel, "Yield_t_ha", "Female", "Male", block = "Block", method = 1)
dl
diallel(maize_diallel, "Yield_t_ha", "Female", "Male", block = "Block", method = 4)$gca

Disease severity scores under four fungicides (RCBD)

Description

Ordinal severity scores (0-9) of a foliar disease under four fungicide treatments in five blocks; suited to the rank-based (Friedman) analysis.

Usage

disease_scores

Format

A data frame with 20 rows and 3 columns:

Block

Block (1-5).

Fungicide

Fungicide treatment, including an untreated control.

Severity_score

Disease severity score.


Durbin test for balanced incomplete blocks

Description

Rank-based comparison of treatments in a balanced incomplete block design (every block has k of the t treatments, every treatment appears r times): the observations are ranked within each block and the rank sums are compared (Durbin 1951). With complete blocks it is Friedman's test. Pairwise comparisons use Conover's t test on the rank sums with ⁠b k - b - t + 1⁠ degrees of freedom; ties get average ranks.

Usage

durbin_test(
  x,
  response = NULL,
  treatment = NULL,
  block = NULL,
  alpha = 0.05,
  p_adjust = "holm"
)

Arguments

x

An "ad_anova" object from design_anova() with one treatment factor and blocks, or a data frame.

response, treatment, block

Column names when x is a data frame; several block columns (replicate, block within replicate) are combined.

alpha

Significance level of the pairwise comparisons.

p_adjust

Adjustment of the pairwise p-values, as in stats::p.adjust(); "none" gives Conover's protected comparisons (to be read only when the overall test is significant).

Value

An object of class c("ad_durbin", "ad_nonparametric") with the test (chi-square and its F form), the pairwise comparisons, the groups with their rank sums and letters, the design parameters (design) and the least significant difference of rank sums (lsd_ranks).

References

Durbin, J. (1951). Incomplete blocks in ranking experiments. British Journal of Statistical Psychology 4, 85-90.

Conover, W. J. (1999). Practical Nonparametric Statistics, 3rd ed. Wiley, New York, section 5.9.

Examples

durbin_test(bib_sorghum, "Yield_t_ha", "Hybrid", "Block")

Field book of a randomised layout

Description

The field book of make_design() with empty columns for the responses to be measured, ready to be filled in and analysed with design_anova().

Usage

field_book(layout, responses = "Response", file = NULL)

Arguments

layout

An "ad_layout" object.

responses

Names of the response columns to add.

file

Optional CSV file to write.

Value

The field book as a data frame (invisibly when file is given).

Examples

lay <- make_design("rcbd", trt = 4, r = 3, seed = 7)
head(field_book(lay, c("Yield", "Height")))

Plot size needed to detect a difference (Hatheway)

Description

Hatheway's (1961) relation between plot size, replication and the difference that can be detected, from Smith's index: ⁠x^b = 2 (t1 + t2)^2 CV1^2 / (r d^2)⁠, where CV1 is the coefficient of variation of the basic units (%), d the true difference to detect as a percentage of the mean, r the number of replicates, t1 the two-sided t for alpha and t2 the one-sided t for the power wanted.

Usage

hatheway_size(
  index,
  reps,
  difference,
  alpha = 0.05,
  power = 0.8,
  treatments = NULL,
  cv = NULL
)

Arguments

index

An "ad_smith" object from smith_index(), or the value of b (then give cv).

reps

Number(s) of replicates.

difference

Difference(s) to detect, as a percentage of the mean.

alpha

Significance level (two-sided).

power

Probability of detecting the difference.

treatments

Optional number of treatments: the t values then use the error degrees of freedom of a randomised complete block design, (reps - 1) (treatments - 1); otherwise normal quantiles are used.

cv

Coefficient of variation (%) of the basic units; by default the one of the uniformity trial.

Value

A data frame with reps, difference, the error df and the plot size in basic units (plot_size).

References

Hatheway, W. H. (1961). Convenient plot size. Agronomy Journal 53, 279-280.

Examples

sm <- smith_index(uniformity_trial)
hatheway_size(sm, reps = 3:6, difference = c(10, 15), treatments = 8)

Line x tester analysis

Description

Analysis of a line x tester mating design (Kempthorne 1957; Singh and Chaudhary 1985): the analysis of variance of the entries in randomised complete blocks, with the crosses partitioned into lines, testers and their interaction; general combining ability of lines and testers, specific combining ability of the crosses, their standard errors, the proportional contribution of every source to the variation among crosses and the genetic components.

Usage

line_tester(data, response, line, tester, block = NULL)

Arguments

data

A data frame in long format.

response

Name of the numeric response column.

line, tester

Names of the line (female) and tester (male) columns.

block

Name of the block column (randomised complete blocks); when NULL the entries are taken as completely randomised.

Details

A row is a cross when it has both a line and a tester, a line parent when the tester is missing (NA or empty) and a tester parent when the line is missing; parents are optional. Rows with neither (for instance checks) are not used.

Lines and testers are tested against the error and, in the random model of Kempthorne, against the line x tester interaction (anova_lxt). The average covariance of half sibs is ⁠[((l-1) MSl + (t-1) MSt) / (l+t-2) - MSlxt] (l+t-2) / (r (2lt - l - t))⁠, the moment estimator under equal variances of lines and testers; ⁠sigma2_A = 4 CovHS / (1 + F)⁠ and ⁠sigma2_D = 4 sigma2_SCA / (1 + F)^2⁠ are given for F = 0 and F = 1. The standard errors of the effects are the usual ones, ⁠sqrt(MSE / (r t))⁠ for lines, ⁠sqrt(MSE / (r l))⁠ for testers and sqrt(MSE / r) for crosses.

Value

An object of class "ad_line_tester".

References

Kempthorne, O. (1957) An Introduction to Genetic Statistics. Wiley. Singh, R. K. and Chaudhary, B. D. (1985) Biometrical Methods in Quantitative Genetic Analysis. Kalyani.

Examples

lt <- line_tester(maize_lxt, "Yield_t_ha", "Line", "Tester", block = "Block")
lt

Least-squares means of a design

Description

Means of the levels of one or more factors, adjusted for the other terms of the model: the other factors get equal weights and covariates are held at their mean.

Usage

ls_means(fit, factors)

Arguments

fit

An "ad_anova" object from design_anova().

factors

Name(s) of the factor(s) whose means are wanted.

Value

A data frame with one row per level (or combination of levels): the least-squares mean, its standard error, the number of observations and the raw mean and standard deviation.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha",
                    block = "Block", design = "rcbd")
ls_means(fit, "Nitrogen_kg_ha")

Full diallel among six maize lines

Description

Simulated yields of a complete diallel (Griffing's method 1: parents, F1 and reciprocals) among six inbred lines, in three randomised complete blocks. The other methods use subsets of the same data.

Usage

maize_diallel

Format

A data frame with 108 rows and 4 columns:

Block

Block (1-3).

Female

Female parent (P1-P6).

Male

Male parent (P1-P6); equal to Female for the parents.

Yield_t_ha

Grain yield, t/ha.

Examples

diallel(maize_diallel, "Yield_t_ha", "Female", "Male", block = "Block", method = 2)

Line x tester trial in maize

Description

Simulated yields of six lines crossed with three testers, evaluated with the nine parents in three randomised complete blocks. Parents have an empty tester (lines) or an empty line (testers).

Usage

maize_lxt

Format

A data frame with 81 rows and 4 columns:

Block

Block (1-3).

Line

Line (L1-L6), NA for the tester parents.

Tester

Tester (T1-T3), NA for the line parents.

Yield_t_ha

Grain yield, t/ha.

Examples

line_tester(maize_lxt, "Yield_t_ha", "Line", "Tester", block = "Block")

Maize hybrids in six environments (multi-environment trial)

Description

Simulated yields of 12 maize hybrids in six environments, each a randomised complete block design with three blocks; the interaction has a multiplicative structure of rank two plus noise.

Usage

maize_met

Format

A data frame with 216 rows and 4 columns:

Environment

Environment (E1-E6).

Block

Block within environment (1-3).

Hybrid

Hybrid (H01-H12).

Yield_t_ha

Grain yield, t/ha.

Examples

ammi(maize_met, "Yield_t_ha", "Hybrid", "Environment", block = "Block")

Maize yield under four nitrogen rates (RCBD)

Description

Randomised complete block design with four nitrogen rates in four blocks.

Usage

maize_nitrogen

Format

A data frame with 16 rows and 3 columns:

Block

Block (1-4).

Nitrogen_kg_ha

Nitrogen rate, kg/ha (0, 60, 120, 180).

Yield_t_ha

Grain yield, t/ha.

Examples

design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")

Maize nitrogen trial in wide format

Description

The same trial as maize_nitrogen, with one column per nitrogen rate. It shows the wide layout that has to be reshaped to long format (one row per plot) before the analysis.

Usage

maize_wide

Format

A data frame with 4 rows and 5 columns: Block and the yields (t/ha) at N0, N60, N120 and N180.


Randomise a field experiment

Description

Generates the randomised layout of a classical design, numbers the plots and returns the field book (one row per plot) with the skeleton analysis of variance. The randomisation is reproducible with seed and does not change the random state of the session.

Usage

make_design(
  design = names(.generated),
  trt = NULL,
  r = 3,
  A = NULL,
  B = NULL,
  C = NULL,
  k = NULL,
  checks = NULL,
  entries = NULL,
  greek = NULL,
  seed = NULL,
  serpentine = TRUE,
  numbering = c("sequential", "block"),
  arrangement = c("stacked", "side"),
  blocks_per_row = 2,
  plots_per_row = NULL,
  gap = FALSE
)

Arguments

design

Design identifier: one of "crd", "rcbd", "latin", "fact_crd", "fact_rcbd", "split_rcbd", "strip", "splitsplit", "ibd", "augmented", "graeco", "youden", "bib", "cyclic", "alpha" or "lattice" (see Details and designs("layout")).

trt

Treatment names, or a single number of treatments (named T1, T2...).

r

Number of replicates (blocks).

A, B, C

Levels of the factors of factorial and split designs.

k

Block size of incomplete block designs.

checks, entries

Checks and new entries of an augmented design.

greek

Levels of the second blocking factor of a Graeco-Latin square.

seed

Seed of the randomisation; NULL draws one and reports it.

serpentine

Number the plots in serpentine order (back and forth along the field rows).

numbering

"sequential" (1, 2, 3...) or "block" (101, 102... in block 1, 201... in block 2).

arrangement

Blocks "stacked" one below the other or "side" by side.

blocks_per_row

Blocks per row of the field with arrangement = "side".

plots_per_row

Plots per row within a block (CRD, RCBD, factorials, augmented); by default a whole block in one row.

gap

Leave an empty row or column between blocks.

Details

The table of the designs, with the arguments each one needs and the design of design_anova() that analyses its field book, is in designs(); designs("layout") returns it as a data frame. Printing the layout shows the call that analyses it (also in ⁠$analysis⁠).

Designs: "crd", "rcbd", "latin" (as many rows and columns as treatments), "fact_crd" and "fact_rcbd" (all combinations of A, B and optionally C), "split_rcbd" (A on main plots, B on sub-plots), "strip" (A in horizontal and B in vertical strips), "splitsplit" (A, B, C), "ibd" (each replicate split at random into blocks of k plots; the number of treatments must be a multiple of k) and "augmented" (checks in every block and each of the entries once).

Further designs: "graeco" (Graeco-Latin square: rows, columns, a second blocking factor greek and the treatments, for an odd number of treatments or 4 or 8), "youden" (incomplete Latin square: k rows and as many columns as treatments, from a cyclic difference set), "bib" (balanced incomplete blocks of size k: cyclic when a difference set is known, otherwise all combinations), "cyclic" (incomplete blocks developed from initial blocks chosen for the highest efficiency; r a multiple of k), "alpha" (alpha design: resolvable, t / k blocks of size k per replicate, k <= t / k, with the alpha array of highest efficiency found) and "lattice" (square lattice: k^2 treatments in blocks of k). design_efficiency() reports the efficiency factor of the layout.

Value

An object of class "ad_layout" with the field book (book), the outlines of blocks and main plots (boxes), the skeleton ANOVA (skeleton) and the seed used.

See Also

designs() for the table of designs, field_book(), design_efficiency(), power_design().

Examples

designs("layout")   # the designs that can be randomised

lay <- make_design("rcbd", trt = c("N0", "N60", "N120", "N180"), r = 4, seed = 2026)
lay
head(lay$book)
plot(lay)

make_design("split_rcbd", A = c("Drip", "Furrow"), B = paste0("V", 1:4), r = 3, seed = 1)

Mood's median test

Description

Compares the treatments of a one-way layout by the number of observations above the grand median: a chi-square test on the 2 x t table of counts above and at-or-below the median (Mood 1950; Conover 1999). Pairs of treatments are compared with the same test on their 2 x 2 table, either around the median of the two treatments together (pair_median = "pair", the default) or around the grand median ("grand"), or with Fisher's exact test (exact = TRUE). It assumes little more than independence, and resists outliers and unequal spreads, at the cost of power.

Usage

median_test(
  x,
  response = NULL,
  treatment = NULL,
  alpha = 0.05,
  p_adjust = "holm",
  correct = FALSE,
  pair_median = c("pair", "grand"),
  exact = FALSE
)

Arguments

x

An "ad_anova" object of a one-factor design without blocks, or a data frame.

response, treatment

Column names when x is a data frame.

alpha

Significance level of the pairwise comparisons.

p_adjust

Adjustment of the pairwise p-values, as in stats::p.adjust(); "none" gives Conover's protected comparisons (to be read only when the overall test is significant).

correct

Yates' continuity correction in the 2 x 2 tables (the overall test is corrected only when there are two treatments).

pair_median

Median used for the pairwise tables.

exact

Use Fisher's exact test for the pairwise tables.

Value

An object of class c("ad_median_test", "ad_nonparametric"); table holds the counts above and at-or-below the grand median and grand_median the median of all observations.

References

Mood, A. M. (1950). Introduction to the Theory of Statistics. McGraw-Hill, New York, 394-399.

Conover, W. J. (1999). Practical Nonparametric Statistics, 3rd ed. Wiley, New York, section 4.3.

Examples

median_test(bean_varieties, "Yield_kg_plot", "Variety")

North Carolina designs I, II and III

Description

Analysis of the mating designs of Comstock and Robinson (1948, 1952):

Design I

each male crossed with its own group of females (females nested within males).

Design II

every male crossed with every female of its set.

Design III

F2 (or other) plants used as males, each crossed with the two inbred parents of the population (the testers, given in the female column).

Males (and females) are nested within sets, and blocks within sets. When a plot holds several plants, the plot error (blocks x crosses within sets) is separated from the variation within plots. The table gives the expected mean squares; every term is tested against the mean square that differs from it only by its own component, and the components are their moment estimators with standard errors from Var(MS) = 2 MS^2 / df.

Usage

nc_design(
  data,
  response,
  male,
  female,
  block,
  set = NULL,
  design = 1,
  inbreeding = 0
)

Arguments

data

A data frame in long format.

response

Name of the numeric response column.

male, female

Names of the male and female columns (design III: the female column holds the two testers).

block

Name of the block (replicate) column, nested within sets.

set

Optional name of the set column.

design

1, 2 or 3.

inbreeding

Inbreeding coefficient of the parents (designs I and II).

Details

Genetic interpretation without epistasis: design I, ⁠sigma2_A = 4 Vm / (1 + F)⁠ and sigma2_D = 4 (Vf - Vm) / (1 + F)^2; design II, sigma2_A = 2 (Vm + Vf) / (1 + F) and ⁠sigma2_D = 4 Vmf / (1 + F)^2⁠; design III (F2 reference population, gene frequency 1/2), ⁠sigma2_A = 4 Vm = 2 (MSm - MSe) / r⁠ and sigma2_D = Vmt = (MSmt - MSe) / r, because the sum and the difference of the two backcross families of a plant have variances sigma2_A and 2 sigma2_D. The average degree of dominance is ⁠sqrt(2 sigma2_D / sigma2_A)⁠.

Value

An object of class "ad_nc_design": the analysis of variance with expected mean squares, the variance components and the genetic parameters.

References

Comstock, R. E. and Robinson, H. F. (1948) Biometrics 4, 254-266. Comstock, R. E. and Robinson, H. F. (1952) In Heterosis, Iowa State College Press, 494-516.

Examples

nc_design(nc_designs$nc2, "Yield_t_ha", "Male", "Female", block = "Rep", set = "Set", design = 2)
nc_design(nc_designs$nc3, "Yield_t_ha", "Male", "Tester", block = "Rep", set = "Set", design = 3)

North Carolina mating designs

Description

Simulated data of the three North Carolina designs, each in two sets with two replicates per set.

Usage

nc_designs

Format

A list of three data frames:

nc1

Design I: Set, Rep, Male (three per set), Female (four per male, labelled within the male) and Yield_t_ha; 48 rows.

nc2

Design II: Set, Rep, Male and Female (four of each per set) and Yield_t_ha; 64 rows.

nc3

Design III: Set, Rep, Male (six F2 plants per set), Tester (P1, P2) and Yield_t_ha; 48 rows.

Examples

nc_design(nc_designs$nc1, "Yield_t_ha", "Male", "Female", block = "Rep", set = "Set", design = 1)

Rank-based and unequal-variance alternatives to the ANOVA

Description

When the assumptions fail, compares the treatments without assuming normality (rank-based tests) or without assuming equal variances (Welch). The method follows the design of fit:

Usage

nonparametric(
  fit,
  method = NULL,
  posthoc = c("conover", "nemenyi"),
  p_adjust = "holm",
  alpha = 0.05
)

Arguments

fit

An "ad_anova" object from design_anova().

method

One of the methods above; NULL picks the first one that fits the design (Kruskal-Wallis, Friedman, Scheirer-Ray-Hare or ART).

posthoc

For Friedman, "conover" (default) or "nemenyi".

p_adjust

Adjustment of the pairwise p-values, as in stats::p.adjust().

alpha

Significance level of the checks.

Details

Pairwise p-values of Dunn, Mann-Whitney and Conover are adjusted with p_adjust; Games-Howell, Nemenyi and Tukey already control the family-wise error. Levels that share a letter do not differ.

Value

An object of class "ad_nonparametric" with the test (test), the table of terms for SRH and ART (table), the pairwise comparisons (pairs) and the groups with their letters (groups).

Examples

fit <- design_anova(bean_varieties, "Yield_kg_plot", "Variety")
nonparametric(fit)

fit <- design_anova(disease_scores, "Severity_score", "Fungicide", block = "Block")
nonparametric(fit, posthoc = "nemenyi")

Biplots of an AMMI analysis

Description

The AMMI1 biplot puts the means of genotypes and environments on the horizontal axis and their first interaction score on the vertical axis; the AMMI2 biplot shows the first two interaction axes, with the environments as vectors from the origin.

Usage

## S3 method for class 'ad_ammi'
plot(
  x,
  type = c("ammi1", "ammi2"),
  col = NULL,
  labels = TRUE,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  cex = 0.8,
  ...
)

Arguments

x

An "ad_ammi" object from ammi().

type

"ammi1" (mean vs IPCA1) or "ammi2" (IPCA1 vs IPCA2).

col

Two colours: genotypes and environments.

labels

Write the names of genotypes and environments.

main, xlab, ylab

Titles; NULL builds them from the analysis.

cex

Size of the labels.

...

Further graphical parameters passed to graphics::plot.window().

Value

Invisibly, a data frame with the coordinates of every point.

Examples

fit <- ammi(maize_met, "Yield_t_ha", "Hybrid", "Environment", block = "Block")
plot(fit, type = "ammi2")

Residual plots of a design

Description

Six diagnostic plots of the residuals: residuals against fitted values, normal Q-Q plot of the studentized residuals with a 95 % pointwise band, scale-location, residuals by treatment, residuals in data order and a histogram with the normal curve. Observations with |studentized residual| above 2.5 are labelled with their row number.

Usage

## S3 method for class 'ad_anova'
plot(x, which = 1:6, ...)

Arguments

x

An "ad_anova" object from design_anova().

which

Plots to draw (1 to 6). Several plots share one page.

...

Not used.

Value

Invisibly, a data frame with the fitted values, residuals and studentized residuals.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
plot(fit)
plot(fit, which = 2)

Plot treatment means with their letters

Description

Draws the means of a comparison from compare_means() as bars or points with error bars, or the observations as box plots or points, and writes the letters of the groups above them. With simple effects (by), the means are grouped by the levels of the other factor and the letters are valid within each group.

Usage

## S3 method for class 'ad_comparison'
plot(
  x,
  style = c("bars", "points", "box", "strip"),
  error = c("se", "ci", "none"),
  letters = TRUE,
  values = FALSE,
  sort = FALSE,
  col = NULL,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  ylim = NULL,
  letter_cex = 1.1,
  digits = 2,
  ...
)

Arguments

x

An "ad_comparison" object.

style

"bars", "points", "box" (box plots of the observations) or "strip" (every observation, with the mean and its error bar).

error

Error bars: "se" (standard error of the mean), "ci" (95 % confidence interval with the error degrees of freedom) or "none".

letters

Write the letters of the groups.

values

Write the value of each mean.

sort

Sort the levels by their mean, highest first.

col

Fill colours, one per level (default: agri_colors()).

main, xlab, ylab

Titles; NULL builds them from the analysis.

ylim

Range of the vertical axis.

letter_cex

Size of the letters.

digits

Decimals of the values written with values = TRUE.

...

Further graphical parameters passed to graphics::plot.window().

Value

Invisibly, a data frame with the position, mean, error-bar limits and letters of every level.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
cmp <- compare_means(fit, "Nitrogen_kg_ha")
plot(cmp)
plot(cmp, style = "box")

fit <- design_anova(split_irrigation, "Yield_t_ha", c("Irrigation", "Variety"),
                    block = "Block", design = "split_rcbd")
plot(compare_means(fit, "Variety", by = "Irrigation"))

Plot a randomised field layout

Description

Draws the plots on their field rows and columns coloured by treatment (or by main-plot factor), with the plot numbers and the outlines of blocks and main plots.

Usage

## S3 method for class 'ad_layout'
plot(x, color_by = NULL, labels = TRUE, numbers = TRUE, main = NULL, ...)

Arguments

x

An "ad_layout" object from make_design().

color_by

Column of the field book that colours the plots (default: A in split and factorial designs, otherwise Treatment).

labels

Write the treatment in each plot.

numbers

Write the plot number in each plot.

main

Title.

...

Not used.

Value

Invisibly, the field book.

Examples

plot(make_design("strip", A = c("Drip", "Furrow", "Sprinkler"), B = c("V1", "V2"), r = 2, seed = 3))

Heat map of cell means

Description

Least-squares means of every combination of two treatment factors as a coloured table with the values written in the cells.

Usage

plot_cell_means(fit, rows, cols, digits = 2, main = NULL)

Arguments

fit

An "ad_anova" object from design_anova().

rows, cols

Factors in the rows and columns of the map.

digits

Decimals of the values.

main

Title; NULL builds it from the analysis.

Value

Invisibly, the cell means plotted.

Examples

fit <- design_anova(tomato_factorial, "Yield_kg_plant", c("Variety", "Fertilizer"),
                    block = "Block")
plot_cell_means(fit, "Variety", "Fertilizer")

Plot the pairwise differences with their intervals

Description

Every pairwise difference of a comparison with its interval: the critical difference of the procedure (simultaneous for Tukey, Scheffe, Dunnett...) or, for Holm and Games-Howell, the 95 % t interval. Differences declared significant are drawn in red.

Usage

plot_differences(
  x,
  sort = TRUE,
  main = NULL,
  xlab = "Difference between means",
  col = c("#2f7d4f", "#b5432f")
)

Arguments

x

An "ad_comparison" object from compare_means().

sort

Sort by the size of the difference.

main, xlab

Titles.

col

Colours of non-significant and significant differences.

Value

Invisibly, the differences and interval limits plotted.

Examples

fit <- design_anova(bean_varieties, "Yield_kg_plot", "Variety")
plot_differences(compare_means(fit, "Variety"))

Field map of the response or of the residuals

Description

Draws the plots of the trial on their field rows and columns, coloured by the response or by the residuals of the model (a diverging scale centred at zero), and labelled with the treatment. Spatial patterns of the residuals point to fertility gradients that blocking did not remove.

Usage

plot_field(
  fit,
  row = NULL,
  col = NULL,
  data = NULL,
  value = c("response", "residuals"),
  labels = TRUE,
  values = TRUE,
  digits = 2,
  main = NULL
)

Arguments

fit

An "ad_anova" object from design_anova().

row, col

Names of the field row and column columns. By default the row and column of a Latin square.

data

The data frame given to design_anova(), needed when the field row and column were not roles of the design.

value

"response" or "residuals".

labels

Write the treatment of each plot.

values

Write the value of each plot.

digits

Decimals of the values.

main

Title.

Value

Invisibly, a data frame with the row, column, treatment and value of every plot.

Examples

fit <- design_anova(wheat_latin, "Yield_t_ha", "Treatment", row = "Row", col = "Column")
plot_field(fit, value = "residuals")

Interaction plot of two treatment factors

Description

Least-squares means of every combination of x (horizontal axis) and trace (one line per level), with error bars.

Usage

plot_interaction(
  fit,
  x,
  trace,
  error = c("se", "ci", "none"),
  col = NULL,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  ylim = NULL
)

Arguments

fit

An "ad_anova" object from design_anova().

x, trace

Treatment factors on the horizontal axis and as lines.

error

Error bars: "se" (standard error of the mean), "ci" (95 % confidence interval with the error degrees of freedom) or "none".

col

Fill colours, one per level (default: agri_colors()).

main, xlab, ylab

Titles; NULL builds them from the analysis.

ylim

Range of the vertical axis.

Value

Invisibly, the cell means plotted.

Examples

fit <- design_anova(tomato_factorial, "Yield_kg_plant", c("Variety", "Fertilizer"),
                    block = "Block")
plot_interaction(fit, "Fertilizer", "Variety")

Partition of the total sum of squares

Description

A bar split into the share of the total sum of squares taken by every source of the analysis of variance, including the error strata and the residual.

Usage

plot_ss_partition(fit, col = NULL, main = NULL)

Arguments

fit

An "ad_anova" object from design_anova().

col

Colours of the sources.

main

Title.

Value

Invisibly, a data frame with the sum of squares and percentage of every source.

Examples

fit <- design_anova(split_irrigation, "Yield_t_ha", c("Irrigation", "Variety"),
                    block = "Block", design = "split_rcbd")
plot_ss_partition(fit)

Replicates and power for a difference between two treatments

Description

Power of the two-sided t-test to detect a difference of diff per cent of the mean between two treatment means, when the coefficient of variation of the trial is cv per cent, as a function of the number of replicates. The error degrees of freedom are those of a CRD or an RCBD with t treatments, and the power uses the noncentral t distribution.

Usage

power_design(
  cv,
  diff,
  t,
  design = c("rcbd", "crd"),
  alpha = 0.05,
  power = 0.8,
  r = 2:30
)

Arguments

cv

Coefficient of variation expected (per cent), from earlier trials on the same site and crop.

diff

Difference to detect, per cent of the mean.

t

Number of treatments.

design

"rcbd" or "crd".

alpha

Significance level.

power

Power wanted.

r

Replicates for which the table is computed.

Value

An object of class "ad_power" with the replicates needed (replicates, NA above 200) and a table with the error df, the power and the detectable difference for each number of replicates.

Examples

power_design(cv = 15, diff = 15, t = 4)
plot(power_design(cv = 10, diff = 15, t = 4))

Recover inter-block information (REML)

Description

In incomplete block designs (alpha, lattice, BIBD, cyclic, augmented), the intra-block analysis of design_anova() treats blocks as fixed and uses only comparisons within blocks. When blocks are random, block totals also carry information on the treatments. This function fits blocks as a random effect, estimates the block and error variances by restricted maximum likelihood (REML) and returns the treatment means as generalised least-squares estimates (BLUEs), with their standard errors and the efficiency gained over the intra-block analysis and over a complete block design.

Usage

recover_interblock(fit)

Arguments

fit

An "ad_anova" object of an incomplete block design (designs "ibd", "bib", "augmented", "rcbd" with incomplete blocks).

Value

An object of class "ad_recovery" with the variance components (sigma2_block, sigma2), the adjusted treatment means and SEs (means), the average standard error of a difference for the combined, intra-block and complete-block analyses, and the REML log-likelihood.

Examples

lay <- make_design("alpha", trt = 12, r = 3, k = 3, seed = 4)
b <- field_book(lay, "Yield")
b$Yield <- 10 + as.integer(factor(b$Treatment)) / 5 + rep(c(-1, 0, 1), length.out = nrow(b))
fit <- design_anova(b, "Yield", "Treatment", block = c("Block", "IncBlock"))
recover_interblock(fit)

Save a figure to a file

Description

Opens the graphics device that matches the extension of file (.png, .tiff, .jpg, .pdf, .svg or .eps), evaluates the plotting code and closes the device. Raster formats carry the resolution in their header, as journals ask.

Usage

save_figure(
  file,
  expr,
  width = 16,
  height = 11,
  units = c("cm", "mm", "in"),
  res = 600,
  pointsize = 10
)

Arguments

file

Output file; its extension chooses the format.

expr

Plotting code, for instance plot(cmp); it is evaluated with the device open.

width, height

Size of the figure.

units

"cm", "mm" or "in".

res

Resolution in dots per inch of raster formats.

pointsize

Base size of the text, in points.

Value

The path of the file, invisibly.

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
f <- tempfile(fileext = ".png")
save_figure(f, plot(compare_means(fit, "Nitrogen_kg_ha")), width = 12, height = 9)
file.exists(f)

Smith's index of soil heterogeneity

Description

From a uniformity trial (one crop, uniformly managed, harvested in small basic units) builds every plot shape that tiles the field exactly (length units along the rows times width units along the columns), computes for each the variance per unit area among plots, V_x = var(T / x) with T the plot totals and x the plot size in basic units, and fits Smith's empirical law V_x = V_1 / x^b by least squares on the log scale (weighted by the degrees of freedom of each variance, plots - 1, unless weights = "none").

Usage

smith_index(
  data,
  cost_ratio = NULL,
  weights = c("df", "none"),
  min_plots = 2,
  strips = FALSE
)

Arguments

data

A numeric matrix (or data frame) of yields of the basic units, with the rows and columns of the field.

cost_ratio

Optional ratio of the cost per plot to the cost per unit area of experimental land (both per basic unit).

weights

"df" (default) or "none".

min_plots

Smallest number of plots a shape must give to enter the fit (at least 2).

strips

Use in the fit the shapes that span the whole length or width of the field. They are left out by default (as in agricolae): one strip per row or column averages out any gradient along it, so a few such shapes can dominate the fit, and they cannot be blocked.

Details

The index b lies usually between 0 and 1. Near 1, adjacent units are nearly uncorrelated and larger plots reduce the variance per unit area efficiently; near 0, adjacent units are much alike and enlarging plots gains little, so more replicates pay off better. Given the ratio of the cost per plot to the cost per unit area (cost_ratio = K1 / K2), Smith's optimum plot size is ⁠b K1 / ((1 - b) K2)⁠ basic units; see hatheway_size() for the size needed to detect a given difference.

Value

An object of class "ad_smith" with the table of shapes (table: size, width, length, plots, df, variance, cv, used), the index b, the fitted V1, the R squared of the log-log fit, the mean yield, the coefficient of variation of the basic units (cv1) and Smith's optimum plot size (optimum).

References

Smith, H. F. (1938). An empirical law describing heterogeneity in the yields of agricultural crops. Journal of Agricultural Science 28, 1-23.

Gomez, K. A. and Gomez, A. A. (1984). Statistical Procedures for Agricultural Research, 2nd ed. Wiley, New York, chapter 12.

Examples

sm <- smith_index(uniformity_trial, cost_ratio = 2)
sm
plot(sm)

Irrigation systems by varieties (split-plot in RCBD)

Description

Two irrigation systems on main plots and four varieties on sub-plots, in three blocks.

Usage

split_irrigation

Format

A data frame with 24 rows and 4 columns:

Block

Block (1-3).

Irrigation

Irrigation system (main-plot factor).

Variety

Variety (sub-plot factor).

Yield_t_ha

Yield, t/ha.

Examples

design_anova(split_irrigation, "Yield_t_ha", c("Irrigation", "Variety"),
             block = "Block", design = "split_rcbd")

Stability statistics of a multi-environment trial

Description

Parametric and rank-based stability statistics computed from the table of genotype means in every environment and the pooled error of the trial:

"eberhart"

Eberhart and Russell (1966): regression coefficient b on the environmental index (with its standard error from the genotype's own deviations, and a t test of b = 1), deviation mean square s2d (mean scale, minus the error of a mean) with its F test against the pooled error, and their analysis of variance.

"finlay"

Finlay and Wilkinson (1963): regression on the environment mean, optionally on the log scale.

"shukla"

Shukla's (1972) stability variance sigma2 and the same after removing the linear regression on the environmental index (s2), with F tests against the pooled error (plot scale).

"wricke"

Wricke's (1962) ecovalence (plot scale) and its share of the interaction.

"kang"

Kang's (1993) yield-stability statistic YS: the rank of the mean (highest = g), adjusted by the LSD, plus the stability rating from Shukla's test (-8, -4, -2 at 0.01, 0.05, 0.10).

"huehn"

Huehn's (1979) rank statistics S1 and S2 on the ranks corrected for the genotype effects, with the Z tests of Nassar and Huehn (1987).

The common analysis of variance follows Shukla (1972): the interaction is split into the heterogeneity of the regressions and the residual, with (g - 1)(e - 2) degrees of freedom (Eberhart and Russell printed g(e - 2), but e - 2 of them belong to environments and are identically zero).

Usage

stability(
  data,
  response,
  genotype,
  environment,
  block = NULL,
  mse = NULL,
  df_error = NULL,
  reps = 1,
  method = c("eberhart", "finlay", "shukla", "wricke", "kang", "huehn"),
  alpha = 0.05,
  log_finlay = FALSE
)

Arguments

data

A data frame in long format.

response

Name of the numeric response column.

genotype, environment

Names of the genotype and environment columns.

block

Optional name of the block (replicate) column; blocks are taken as nested within environments.

mse, df_error

Error mean square (plot scale) and its degrees of freedom, only when the data hold one mean per cell.

reps

Number of replicates behind each mean, when the data hold one mean per cell.

method

One or more of "eberhart", "finlay", "shukla", "wricke", "kang" and "huehn" (default: all).

alpha

Significance level of the LSD in Kang's statistic and of the critical values of Huehn's tests.

log_finlay

Fit the regression of Finlay and Wilkinson on the natural logarithm of the means, as in their paper.

Value

An object of class "ad_stability": the analysis of variance (anova) and one element per method.

References

Eberhart, S. A. and Russell, W. A. (1966) Crop Science 6, 36-40. Finlay, K. W. and Wilkinson, G. N. (1963) Australian Journal of Agricultural Research 14, 742-754. Shukla, G. K. (1972) Heredity 29, 237-245. Wricke, G. (1962) Zeitschrift fur Pflanzenzuchtung 47, 92-96. Kang, M. S. (1993) Agronomy Journal 85, 754-757. Huehn, M. (1979) EDV in Medizin und Biologie 10, 112-117. Nassar, R. and Huehn, M. (1987) Biometrics 43, 45-53.

Examples

st <- stability(maize_met, "Yield_t_ha", "Hybrid", "Environment", block = "Block")
st
st$kang

Test contrasts among the levels of a factor

Description

A contrast compares groups of treatments with coefficients that sum to zero, one per level in the order of levels(fit$data[[factor]]); for instance a control against the other three treatments is c(3, -1, -1, -1).

Usage

test_contrasts(fit, factor, coef)

Arguments

fit

An "ad_anova" object from design_anova().

factor

Treatment factor whose means are compared; two names compare all their combinations together (not available for split- or strip-plots, where by should be used).

coef

A vector of coefficients, or a matrix with one contrast per row (row names are used as labels).

Value

A data frame with the estimate, its SE, t, p, the sum of squares of the contrast and F (1 and df_error degrees of freedom).

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
test_contrasts(fit, "Nitrogen_kg_ha", rbind("0 vs fertilised" = c(3, -1, -1, -1),
                                      "120 vs 180" = c(0, 0, 1, -1)))

Tomato varieties by fertiliser (factorial in RCBD)

Description

Three tomato varieties by three fertiliser levels in three blocks.

Usage

tomato_factorial

Format

A data frame with 27 rows and 5 columns:

Block

Block (1-3).

Variety

Tomato variety.

Fertilizer

Fertiliser level (F0, F1, F2).

Yield_kg_plant

Fruit yield, kg per plant.

Height_cm

Plant height, cm.

Examples

design_anova(tomato_factorial, "Yield_kg_plant", c("Variety", "Fertilizer"),
             block = "Block")

Compare transformations of the response

Description

Refits the design after each transformation that suits the range of the response and repeats the assumption checks. A transformation is suggested only when the original scale fails some check and the transformed scale passes all of them: the conventional power nearest to the Box-Cox estimate when it passes, otherwise the candidate with the least evidence against the assumptions.

Usage

transformations(fit, alpha = 0.05)

Arguments

fit

An "ad_anova" object from design_anova().

alpha

Significance level of the checks.

Value

An object of class "ad_transformations": the table of candidates (table), the identifier of the suggested transformation (suggested, NULL when none is needed or none works), a short verdict and the Box-Cox profile (box_cox).

Examples

fit <- design_anova(tomato_factorial, "Yield_kg_plant", c("Variety", "Fertilizer"),
                    block = "Block")
transformations(fit)

Trend analysis of a quantitative factor

Description

Splits the sum of squares of a factor with numeric levels (doses, rates, dates) into linear, quadratic, cubic... components with orthogonal polynomial contrasts (also with unequal spacing) and fits the polynomial of the highest significant degree to the observations. A fitted quadratic reports where the maximum (or minimum) response lies.

Usage

trend(fit, factor, degree = NULL, alpha = 0.05)

Arguments

fit

An "ad_anova" object from design_anova().

factor

Treatment factor whose means are compared; two names compare all their combinations together (not available for split- or strip-plots, where by should be used).

degree

Highest degree to test (default: up to 4, at most the number of levels minus one).

alpha

Significance level.

Value

An object of class "ad_trend" with the table of components (components), the fitted coefficients (coef, intercept first), its R squared and the optimum of a quadratic (optimum).

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
trend(fit, "Nitrogen_kg_ha")

Uniformity trial of 24 x 16 basic units (simulated)

Description

Simulated yields (kg) of a uniformity trial harvested in 384 basic units (24 rows by 16 columns), with a fertility gradient along the rows and patchy variation; suited to Smith's index of soil heterogeneity.

Usage

uniformity_trial

Format

A numeric matrix with 24 rows (R1...R24) and 16 columns (C1...C16).

Examples

smith_index(uniformity_trial)

van der Waerden normal-scores test

Description

Compares the treatments of a one-way layout (no blocks) after replacing every observation by its normal score qnorm(R / (N + 1)), where R is its rank among all N observations (average ranks for ties). The statistic is chi-square with t - 1 degrees of freedom; the pairwise comparisons are Conover's t tests on the mean scores with N - t degrees of freedom. It is as powerful as the F test under normality and more robust than it.

Usage

waerden_test(
  x,
  response = NULL,
  treatment = NULL,
  alpha = 0.05,
  p_adjust = "holm"
)

Arguments

x

An "ad_anova" object of a one-factor design without blocks, or a data frame.

response, treatment

Column names when x is a data frame.

alpha

Significance level of the pairwise comparisons.

p_adjust

Adjustment of the pairwise p-values, as in stats::p.adjust(); "none" gives Conover's protected comparisons (to be read only when the overall test is significant).

Value

An object of class c("ad_waerden", "ad_nonparametric"); the groups carry the mean normal score of every level (mean_score).

References

van der Waerden, B. L. (1952). Order tests for the two-sample problem and their power. Indagationes Mathematicae 14, 453-458.

Conover, W. J. (1999). Practical Nonparametric Statistics, 3rd ed. Wiley, New York, section 5.10.

Examples

waerden_test(bean_varieties, "Yield_kg_plot", "Variety")

Critical t of the Waller-Duncan k-ratio test

Description

The Bayesian critical value t_B(K, F, q, f) of Waller and Duncan (1969), computed by numerical integration of the posterior expected losses (see waller_duncan()). Two means differ when their difference exceeds t_B * SE, the Bayes least significant difference. The value decreases as the observed F grows: with a small F the means are shrunk towards each other and few differences are declared.

Usage

waller_critical(K = 100, q, f, F_ratio)

Arguments

K

Ratio of the seriousness of a type I error to that of a type II error (50, 100 and 500 roughly match alpha = 0.10, 0.05 and 0.01).

q, f

Degrees of freedom of the treatments and of the error.

F_ratio

Observed F ratio of the treatments.

Value

A numeric vector of critical values (arguments are recycled).

References

Waller, R. A. and Duncan, D. B. (1969). A Bayes rule for the symmetric multiple comparisons problem. Journal of the American Statistical Association 64, 1484-1503.

Waller, R. A. and Kemp, K. E. (1975). Computations of Bayesian t-values for multiple comparisons. Journal of Statistical Computation and Simulation 4, 169-171.

Examples

waller_critical(100, q = 5, f = 24, F_ratio = 14.37)
waller_critical(100, q = 4, f = 20, F_ratio = c(2, 5, 10, 100))

Waller-Duncan k-ratio t test

Description

Bayesian separation of the means of a treatment factor (Waller and Duncan 1969). Instead of a fixed significance level, the user gives the ratio K of the seriousness of a type I to a type II error; the critical t then adapts to the evidence of the analysis of variance: with a large F it approaches an unprotected LSD, with an F near 1 almost no difference is declared. The result is an "ad_comparison" object, so print(), plot() and plot_differences() work as with compare_means().

Usage

waller_duncan(fit, factor, K = 100, alpha = NULL)

Arguments

fit

An "ad_anova" object from design_anova().

factor

One treatment factor of fit.

K

Seriousness ratio of type I to type II errors (default 100).

alpha

Optional nominal level that sets K by the usual correspondence: 0.10 gives K = 50, 0.05 gives K = 100 and 0.01 gives K = 500. When NULL, the alpha reported is the comparison-wise error rate implied by the critical t.

Details

The F, its degrees of freedom and the error come from the stratum that tests the factor in fit (for instance Error a for the main plots of a split-plot). With unequal replication every pair uses its own standard error, as in the Tukey-Kramer form.

Value

An object of class "ad_comparison" (see compare_means()), with the extra elements K, t_critical and F.

References

Waller, R. A. and Duncan, D. B. (1969). A Bayes rule for the symmetric multiple comparisons problem. Journal of the American Statistical Association 64, 1484-1503.

See Also

waller_critical(), compare_means()

Examples

fit <- design_anova(maize_nitrogen, "Yield_t_ha", "Nitrogen_kg_ha", block = "Block")
wd <- waller_duncan(fit, "Nitrogen_kg_ha")
wd
plot(wd)

Wheat yield in a 4 x 4 Latin square

Description

Wheat yield in a 4 x 4 Latin square

Usage

wheat_latin

Format

A data frame with 16 rows and 4 columns:

Row

Row of the field (1-4).

Column

Column of the field (1-4).

Treatment

Treatment (A-D).

Yield_t_ha

Grain yield, t/ha.

Examples

design_anova(wheat_latin, "Yield_t_ha", "Treatment", row = "Row", col = "Column")