Interpretations and the optional text service

Muhammad Yaseen

2026-11-09

1 Abstract

Every result in StabilityApp comes with an interpretation computed by the package stability. A longer written interpretation can also be requested from an external text service. This vignette explains both, what is sent to the service, and how the request is made specific to each method.

2 The computed interpretation

stability::stab_interpret() reads a result with rules for its method: the tests of an analysis of variance, the slopes and deviations of a regression, the axes and scores of AMMI, the sectors and axes of the GGE biplot. Every sentence comes from the numbers of the result; nothing is sent anywhere.

fit <-
  stability::ammi(
      .data = stability::ge_data
    , .y    = Yield
    , .rep  = Rep
    , .gen  = Gen
    , .env  = Env
    )
it <-
  stability::stab_interpret(
      x             = fit
    , higher_better = TRUE
    , top           = 5
    )
it
AMMI analysis

AMMI8: 8 interaction axes are significant; the first two axes explain 20.1%
and 17.3% of the interaction.

Findings:
- The interaction is significant (p < 0.001).
- Genotypes with a mean above average and the smallest first-axis scores
  (stable): NIBGE GANDUM3, PR119, V14154, V14170 and TWS12464.
- Environments with the strongest interaction (largest first-axis scores):
  Gujranwala, FSD and KSK; the weakest: FSDR, Sahiwal and Khanewal.
- Genotypes and environments with first-axis scores of the same sign interact
  positively (the genotype does better there than its mean predicts).

Recommendations:
- Use AMMI8 for predictions and the stability indices (stab_asv(),
  stab_masv() with .m = 8).
- Look at the AMMI1 biplot (plot(x, which = "ammi1")) to see mean and
  interaction together.

Cautions:
- The first two axes explain less than half of the interaction; biplots show
  it only partly.

3 The request to a text service

sa_prompt() builds the request. It contains how the method is read, what to concentrate on for that method, the computed findings (which the text must keep to), their facts and the first rows of the main table:

p <-
  sa_prompt(
      x             = fit
    , higher_better = TRUE
    , trait         = "grain yield (kg/ha)"
    , rows          = 8
    )
cat(p$system)
You write the interpretation of one statistical analysis of a multi-environment plant-breeding trial for plant breeders and agronomists. Rules: use only the numbers, names and findings given in the material; do not contradict the computed findings; name genotypes and environments exactly as given; do not invent values, locations or seasons; when the material does not allow a conclusion, say so. Write plain, precise English.
cat(substr(x = p$user, start = 1, stop = 1600))
Analysis: AMMI analysis (function ammi of the R package stability)
Trait: grain yield (kg/ha); higher values are better
Trial: 60 genotypes in 11 environments, 2 replicates; grand mean 4060.8

How this method is read:
AMMI: additive genotype and environment effects plus principal components of the interaction, each tested (Gollob's F). The number of significant axes chooses the model (AMMI1, AMMI2, ...). Scores near zero = stable; genotype and environment scores of the same sign = positive interaction.

Concentrate on: the number of significant interaction axes, the genotypes with small scores (stable) and the environments with the strongest interaction.

Computed findings (keep to them):
- AMMI8: 8 interaction axes are significant; the first two axes explain 20.1% and 17.3% of the interaction.
- The interaction is significant (p < 0.001).
- Genotypes with a mean above average and the smallest first-axis scores (stable): NIBGE GANDUM3, PR119, V14154, V14170, TWS12464, PR115, MSH3 and PR118.
- Environments with the strongest interaction (largest first-axis scores): Gujranwala, FSD and KSK; the weakest: FSDR, Sahiwal and Khanewal.
- Genotypes and environments with first-axis scores of the same sign interact positively (the genotype does better there than its mean predicts).
- The first two axes explain less than half of the interaction; biplots show it only partly.

Facts:
p_env: 1.995e-08
p_gen: 3.507e-72
p_gxe: 1.907e-51
ss_env: 263900000
ss_gen: 71660000
ss_gxe: 201300000
n_axes: 8
pct: 20.08, 17.31
model: AMMI8
stable_high: NIBGE GANDUM3, PR119, V14154, V14170, TWS12464, 

Because every analysis has its own reading guide, focus and findings, the request for a GGE biplot asks about winners and mega-environments, the request for a regression about slopes and deviations, and so on.

4 Services and keys

The services are listed in the file services.csv of the package (system.file("services", "services.csv", package = "StabilityApp")), one line per service with these columns; the list itself is shown on the Settings page and by sa_services():

names(sa_services())
[1] "id"      "label"   "format"  "url"     "model"   "key_env" "header" 
nrow(sa_services())
[1] 3

On the Settings page choose the service and the model and enter your key, or set the environment variable of the service (for instance in .Renviron) so that the key need not be typed. The key stays in the session. sa_ask() sends a request from R:

txt <-
  sa_ask(
      service    = sa_services()$id[1]
    , prompt     = p
    , model      = sa_services()$model[1]
    , key        = ""
    , max_tokens = 1500
    , timeout    = 90
    )
cat(txt)

5 What is sent

Only the text of sa_prompt(): the name of the analysis, the trait, the size of the trial, the computed interpretation with its facts and the first rows of the main table. No data file is sent.

6 Summary

Use the computed interpretation as the reference: it is reproducible and specific to the method. The written text of a service is a draft for a report; check it against the computed findings, the tables and the plots.