---
title: "AMMI analysis and AMMI stability values"
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{AMMI analysis and AMMI stability values}
  %\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 AMMI model, its biplots and the stability values built on its axes.

# The model

```{r ammi}
am <-
  ammi(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
am$pc_anova
am$ammi_model
plot(x = am, which = "scree")
```

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

# Biplots

```{r biplot, fig.height = 6}
ab <-
  ammi_biplot(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
plot(x = ab, which = "ammi1")
plot(x = ab, which = "ammi2")
```

# Stability values

```{r asv}
asv <-
  stab_asv(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
head(x = asv$ASD, n = 6)
masv <-
  stab_masv(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    , .m    = 4
    )
head(x = masv$MASD, n = 6)
dst <-
  stab_dist(
      .data = ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    , .m    = 4
    )
head(x = dst$stabDist, n = 6)
plot(x = asv, which = "ranks")
```

`stab_masv()` is the MASV of Zali et al. (2012). The earlier versions computed it on two axes; the function now takes
any number of axes `.m`, from 2 to the number of non-zero interaction axes. The ratio of the sums of squares of each
axis to the next weighs the first axes heavily. `stab_dist()` is the AMMI stability distance developed by the
package author: the Euclidean distance from the origin over the first `.m` axes of the AMMI scores, in which every
axis enters only through its scores. Use for `.m` the number of significant axes found by `ammi()`.

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

# Summary

Many significant axes mean the interaction has several independent patterns; the first two show only part of it,
and indices over more axes (`stab_masv()`) describe the stability more fully.

# References

Gauch, H. G. (1992). *Statistical Analysis of Regional Yield Trials: AMMI Analysis of Factorial Designs*. Elsevier, Amsterdam.

Gollob, H. F. (1968). A statistical model which combines features of factor analytic and analysis of variance techniques. *Psychometrika*, 33(1), 73--115.

Purchase, J. L., Hatting, H. and van Deventer, C. S. (2000). Genotype x environment interaction of winter wheat in South Africa: II. Stability analysis of yield performance. *South African Journal of Plant and Soil*, 17(3), 101--107.

Zali, H., Farshadfar, E., Sabaghpour, S. H. and Karimizadeh, R. (2012). Evaluation of genotype x environment interaction in chickpea using measures of stability from AMMI model. *Annals of Biological Research*, 3(7), 3126--3136.
