---
title: "Analyses of variance"
author: "Muhammad Yaseen"
date: last-modified
format:
  html:
    self-contained: true
    number-sections: true
    toc: true
    toc-depth: 3
    highlight-style: pygments
    code-tools: true
    html-math-method: mathjax
vignette: >
  %\VignetteIndexEntry{Analyses of variance}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
execute:
  echo: true
  warning: false
  message: false
---

{{< include _stability-macros.txt >}}

```{r setup, include = FALSE}
knitr::opts_chunk$set(collapse = FALSE, comment = "", fig.width = 7, fig.height = 4.6,
                      dev = if (knitr::is_latex_output()) "cairo_pdf" else
                        if (requireNamespace("svglite", quietly = TRUE)) "svglite" else "png")
if (requireNamespace("stability", quietly = TRUE)) library(stability) else
  pkgload::load_all(export_all = FALSE, helpers = FALSE, quiet = TRUE)
```

# Abstract

The analysis of each environment, the combined analysis and Eberhart and Russell's analysis, with what each tells
before the stability statistics.

# Each environment

```{r indiv}
ia <-
  indiv_anova(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
ia$Summary
ia$Homogeneity
plot(x = ia, which = "error")
```

The error mean squares differ more than three-fold; Bartlett's test rejects equality. The combined analysis below
still pools them, which is the usual practice, but the comparison of environments should keep this in mind.

```{r indiv-int}
stab_interpret(
    x             = ia
  , higher_better = TRUE
  , top           = 5
  )
```

# Combined analysis

```{r add}
aa <-
  add_anova(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
aa$anova
aa$Summary
```

The interaction is significant and larger than the genotype effect: genotype means alone would mislead.

# Eberhart and Russell

```{r er}
er <-
  er_anova(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
er$er_anova[c(1:6, nrow(er$er_anova)), ]
head(x = er$Parameters[order(-Mean)], n = 8)
```

```{r er-int}
stab_interpret(
    x             = er
  , higher_better = TRUE
  , top           = 5
  )
```

# Summary

`indiv_anova()` checks precision and the pooling of errors, `add_anova()` the size of the interaction, and
`er_anova()` splits it into a linear part (different slopes) and deviations (unpredictable response).

# References

Eberhart, S. A. and Russell, W. A. (1966). Stability parameters for comparing varieties. *Crop Science*, 6(1), 36--40.

Singh, R. K. and Chaudhary, B. D. (2004). *Biometrical Methods in Quantitative Genetic Analysis*. Kalyani Publishers, New Delhi.
