| Title: | Bayesian Stability Analysis of Genotype by Environment Interaction (GEI) |
|---|---|
| Description: | Performs the general Bayesian estimation method of linear-bilinear models for genotype x environment interaction of Perez-Elizalde, Jarquin and Crossa (2012) <doi:10.1007/s13253-011-0063-9>: the additive main effects and multiplicative interaction (AMMI) model and the sites regression (SREG, GGE) model, with the data of an earlier trial as the prior (conjugate normal and von Mises-Fisher priors weighted by its replicates) or with vague priors; a compiled Gibbs sampler; posterior summaries with highest posterior density intervals; convergence diagnostics; biplots with highest posterior density regions; DIC and WAIC; a plain-language interpretation of every result; and a built-in 'shiny' application. For Bayesian stability analysis in general (regression and variance models, stability indices, probabilities of superior performance), see the package 'bayesstability'. |
| Authors: | Muhammad Yaseen [aut, cre] (ORCID: <https://orcid.org/0000-0002-5923-1714>), Diego Jarquin [aut, ctb], Sergio Perez-Elizalde [aut, ctb], Juan Burgueno [aut, ctb], Jose Crossa [aut, ctb] |
| Maintainer: | Muhammad Yaseen <[email protected]> |
| License: | GPL-2 |
| Version: | 1.0.0 |
| Built: | 2026-11-07 07:31:35 UTC |
| Source: | https://github.com/myaseen208/baystability |
bayes_ammi() estimates the linear-bilinear models of a multi-environment trial by the general Bayesian method
of Perez-Elizalde et al. (2012): the additive main effects and multiplicative interaction (AMMI) model and the
sites regression (SREG, GGE) model. The data of an earlier trial with the same genotypes and environments can be
the prior (.prior_data): its cell means, effects and singular value decomposition give conjugate priors whose
weight is its number of replicates, as in the paper's analysis of two years of a maize trial. Without an earlier
trial the priors are vague but proper. The sampler is compiled (C++); every parameter has a posterior distribution,
and bayes_ammi_biplot() draws the biplot with highest posterior density (HPD) regions.
bayes_ammi( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .model = c("AMMI", "SREG", "GGE"), .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE ) ## Default S3 method: bayes_ammi( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .model = c("AMMI", "SREG", "GGE"), .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE )bayes_ammi( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .model = c("AMMI", "SREG", "GGE"), .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE ) ## Default S3 method: bayes_ammi( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .model = c("AMMI", "SREG", "GGE"), .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE )
.data |
a data frame with one row per plot. |
.y, .gen, .env, .rep
|
the columns of the response, genotypes, environments and replicates: bare names or
strings. The same names are used in |
.nIter |
number of iterations kept per chain before thinning (after the burn-in). |
.prior_data |
|
.n0 |
weight of the earlier trial: the number of its observations per cell in the prior (default its number of replicates). |
.model |
|
.k |
number of bilinear terms |
.burnin |
number of iterations discarded at the start of every chain (default 0). |
.thin |
keep every |
.chains |
number of chains (default 1). |
.priors |
the vague priors used without an earlier trial, from |
.level |
probability of the HPD intervals (default 0.95). |
.seed |
integer seed for a reproducible run, or |
.align |
keep the sign of every bilinear term (default |
.waic |
compute WAIC during sampling (default |
Models. For genotype , replicate and environment ,
, with , , and orthonormal
score matrices and , , and for AMMI also
(paper, eq. 1.2-1.3). By default all
terms are fitted ( for SREG), as in the
paper and the earlier versions; .k fits fewer.
An earlier trial as prior (.prior_data). With its number of replicates
(.n0), its table of cell means and ,
, , its least-squares fit (paper, Section 2.2):
truncated to the order
(eq. 2.9), von Mises-Fisher priors and (eq. 2.7-2.8), and with and the within-cell mean square of the earlier trial (eq. 2.11; the values of the
earlier versions of the package).
Conditional distributions (paper, Section 2.3). With the cell means of the trial,
its replicates and , the linear effects are normal with means
and so on; the singular values are
truncated normal with mean and variance (eq. 2.15); the score matrices are von Mises-Fisher (eq. 2.13-2.14), drawn one column at a
time on the sphere orthogonal to and the other columns (Hoff 2009) with parameters
and the same for ; and
As in the paper, the dependence of the priors on is left out of its conditional
distribution (it would involve the normalising constants of the von Mises-Fisher priors). Without an earlier trial
the priors of bys_priors() apply, which do not depend on , and all
conditionals are exact (Crossa et al. 2011).
Starting values and signs. With an earlier trial the first chain starts at its least-squares fit and every
draw keeps the orientation of its score vectors (.align); otherwise the first chain starts at the
least-squares fit of the trial. Other chains start at dispersed values. With all terms fitted and a prior trial that
disagrees with the data, the posterior of the scores can have several modes; compare chains (.chains) and
the potential scale reduction factors.
Unbalanced trials. Missing plots and cells are completed by data augmentation (see
bys_priors); an earlier trial with empty cells is completed by the EM algorithm before its fit.
Changes from version 0.2.0. The function no longer reads the earlier trial from objects in the workspace
(n0, mu0, tau0, ...; it stopped with "object 'n0' not found" without them): the earlier trial is
the argument .prior_data. The singular values were computed once and never sampled; tau1 held a
precision drawn from a residual matrix that was never updated; the scores were drawn without their constraints
and orthogonalised afterwards; the columns of delta1 were named for the genotypes. tau1 now holds
the draws of the error variance .
An object of class c("bys_bayes_ammi", "bys_result", "list"); the components of version 0.2.0
come first, the draws of all chains one after the other:
mu1data.table, column mu: draws of the overall mean.
tau1data.table, column tau: draws of the error variance .
tao1data.table, columns tao1, ..., taoG: draws of the genotype effects (no
columns for SREG).
delta1data.table, columns delta1, ..., deltaE: draws of the environment
effects.
lambdas1data.table, columns lambdas1, ...: draws of the singular values.
alphas1, gammas1
data.tables, one row per draw, columns alphas1, ...,
alphas<GK> (genotype scores, genotypes within terms) and gammas1, ... (environment scores).
Mean_Alphas, Mean_Gammas
data.tables, columns V1, ..., VK: posterior
means of the score matrices.
summarydata.table: posterior mean, standard deviation, Monte Carlo standard error, HPD
interval, effective sample size and potential scale reduction factor of every parameter.
scoresdata.table: posterior means of the biplot coordinates.
drawscoda::mcmc.list of all parameters.
diagnosticsGelman-Rubin, Raftery-Lewis and Heidelberger-Welch diagnostics.
lsleast-squares fit of the trial; prior: the fit of the earlier trial used as prior.
fitDIC and WAIC.
settingsiterations, burn-in, thinning, chains, terms, model, priors, level, seed, time used.
Methods: print(), summary(), plot(), bayes_ammi_biplot(),
bys_interpret(), bys_compare(), bys_cite().
Muhammad Yaseen ([email protected]), Diego Jarquin ([email protected]), Sergio Perez-Elizalde ([email protected]), Juan Burgueno, Jose Crossa ([email protected])
Perez-Elizalde, S., Jarquin, D. and Crossa, J. (2012). A general Bayesian estimation method of linear-bilinear models applied to plant breeding trials with genotype x environment interaction. Journal of Agricultural, Biological, and Environmental Statistics, 17(1), 15–37. doi:10.1007/s13253-011-0063-9
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. Crop Science, 51(4), 1458–1469. doi:10.2135/cropsci2010.06.0343
Hoff, P. D. (2009). Simulation of the matrix Bingham-von Mises-Fisher distribution, with applications to multivariate and relational data. Journal of Computational and Graphical Statistics, 18(2), 438–456. doi:10.1198/jcgs.2009.07177
Wood, A. T. A. (1994). Simulation of the von Mises Fisher distribution. Communications in Statistics - Simulation and Computation, 23(1), 157–164.
bayes_ammi_biplot, bys_priors, bys_interpret, bys_ls_ammi
data(cultivo2008) data(cultivo2009) fm3 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 300 , .prior_data = cultivo2008 , .n0 = NULL , .model = "AMMI" , .k = NULL , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) fm3 fm3$Mean_Alphas plot(x = fm3, which = "biplot")data(cultivo2008) data(cultivo2009) fm3 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 300 , .prior_data = cultivo2008 , .n0 = NULL , .model = "AMMI" , .k = NULL , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) fm3 fm3$Mean_Alphas plot(x = fm3, which = "biplot")
bayes_ammi_biplot() and bayes_gge_biplot() draw the Bayesian AMMI or GGE (SREG) biplot of the
first two bilinear terms with a highest posterior density
(HPD) region around every genotype and environment (Crossa et al. 2011, Fig. 3 and 4). A region that contains the
origin marks a genotype or environment whose interaction is not different from zero (stable); regions that
overlap mark genotypes or environments that cannot be told apart, a homogeneous group.
bayes_ammi_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) ## Default S3 method: bayes_ammi_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) bayes_gge_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) ## Default S3 method: bayes_gge_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L )bayes_ammi_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) ## Default S3 method: bayes_ammi_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) bayes_gge_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L ) ## Default S3 method: bayes_gge_biplot( fit, burnin = 0, thin = 0.5, pb = 0.05, plot_stable = TRUE, plot_unstable = TRUE, ncolors = 5, .which = c("both", "genotype", "environment"), .grid = 100L )
fit |
a result of |
burnin |
proportion of the stored draws of every chain discarded at its start (default 0). |
thin |
proportion of the remaining draws used (default 0.5: every second draw). |
pb |
one or more probabilities |
plot_stable, plot_unstable
|
draw the regions that contain the origin, and those that do not (default both). |
ncolors |
number of colours used for the regions (default 5). |
.which |
|
.grid |
number of grid points per axis of the density estimate (default 100). |
The points are the biplot coordinates of the paper,
computed draw by draw. For each genotype and environment a bivariate kernel density is estimated
from the draws (normal kernels, normal reference bandwidths); the % HPD region is
with the
-quantile of at the draws, so that the region holds % of
them. The region contains the origin when (stable). The
criterion of the paper, the marginal HPD interval of the first coordinate excluding zero, is given as
axis1_significant.
Changes from the earlier versions. The regions were drawn for the singular vectors without the factor
, with a fixed bandwidth of 0.2 whatever the scale; a genotype counted as
stable when the bounding box of its contour covered the origin.
An object of class c("bys_biplots", "bys_result", "list"), with the components of the earlier
version:
contornsdata.table of the region boundaries: byplot (Genotype, Environment),
ID (number), name, prob (the region, for instance "95%"), piece (a region can have
several pieces), x, y, stable.
biplot_datadata.table, one row per genotype and environment: byplot, ID,
name, x, y (posterior means of the coordinates), stable (region contains the
origin), axis1_lower, axis1_upper (marginal HPD interval of the first coordinate),
axis1_significant (it excludes zero), group (sign of the first coordinate when significant:
positive, negative, or not significant).
biplotthe ggplot.
Methods: print(), plot(), bys_interpret().
Julian Garcia Abadillo Velasco ([email protected]), Diego Jarquin ([email protected]), Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. Crop Science, 51(4), 1458–1469. doi:10.2135/cropsci2010.06.0343
Hyndman, R. J. (1996). Computing and graphing highest density regions. The American Statistician, 50(2), 120–126.
data(cultivo2009) fm1 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 1000 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = 2 , .burnin = 200 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) bp <- bayes_ammi_biplot( fit = fm1 , burnin = 0 , thin = 1 , pb = c(0.05, 0.01) , plot_stable = TRUE , plot_unstable = TRUE , ncolors = 5 , .which = "both" , .grid = 100 ) bp$biplot bp$biplot_datadata(cultivo2009) fm1 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 1000 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = 2 , .burnin = 200 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) bp <- bayes_ammi_biplot( fit = fm1 , burnin = 0 , thin = 1 , pb = c(0.05, 0.01) , plot_stable = TRUE , plot_unstable = TRUE , ncolors = 5 , .which = "both" , .grid = 100 ) bp$biplot bp$biplot_data
bayes_gge() fits the sites regression (SREG) model behind the GGE biplot by the method of Perez-Elizalde et
al. (2012): it is bayes_ammi(.model = "SREG"), under the name used by the package
bayesstability. The genotype main effect is part of the multiplicative terms; an earlier trial enters as
prior through .prior_data.
bayes_gge( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE ) ## Default S3 method: bayes_gge( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE )bayes_gge( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE ) ## Default S3 method: bayes_gge( .data, .y, .gen, .env, .rep, .nIter = 1000L, .prior_data = NULL, .n0 = NULL, .k = NULL, .burnin = 0L, .thin = 1L, .chains = 1L, .priors = bys_priors(), .level = 0.95, .seed = NULL, .align = TRUE, .waic = TRUE )
.data |
a data frame with one row per plot. |
.y, .gen, .env, .rep
|
the columns of the response, genotypes, environments and replicates: bare names or
strings. The same names are used in |
.nIter |
number of iterations kept per chain before thinning (after the burn-in). |
.prior_data |
|
.n0 |
weight of the earlier trial: the number of its observations per cell in the prior (default its number of replicates). |
.k |
number of bilinear terms |
.burnin |
number of iterations discarded at the start of every chain (default 0). |
.thin |
keep every |
.chains |
number of chains (default 1). |
.priors |
the vague priors used without an earlier trial, from |
.level |
probability of the HPD intervals (default 0.95). |
.seed |
integer seed for a reproducible run, or |
.align |
keep the sign of every bilinear term (default |
.waic |
compute WAIC during sampling (default |
An object of class c("bys_bayes_ammi", "bys_result", "list"); see bayes_ammi().
Muhammad Yaseen ([email protected])
Perez-Elizalde, S., Jarquin, D. and Crossa, J. (2012). A general Bayesian estimation method of linear-bilinear models applied to plant breeding trials with genotype x environment interaction. Journal of Agricultural, Biological, and Environmental Statistics, 17(1), 15–37. doi:10.1007/s13253-011-0063-9
data(cultivo2008) data(cultivo2009) fg <- bayes_gge( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 400 , .prior_data = cultivo2008 , .n0 = NULL , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) fg bp <- bayes_gge_biplot( fit = fg , burnin = 0 , thin = 1 , pb = 0.05 , plot_stable = TRUE , plot_unstable = TRUE , ncolors = 5 , .which = "both" , .grid = 100 ) bp$biplotdata(cultivo2008) data(cultivo2009) fg <- bayes_gge( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 400 , .prior_data = cultivo2008 , .n0 = NULL , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) fg bp <- bayes_gge_biplot( fit = fg , burnin = 0 , thin = 1 , pb = 0.05 , plot_stable = TRUE , plot_unstable = TRUE , ncolors = 5 , .which = "both" , .grid = 100 ) bp$biplot
bys_app() starts the application of baystability: load a trial (the example cultivo2009
or a CSV file with one row per plot) and, optionally, an earlier trial of the same genotypes and environments as the
prior (the example cultivo2008 or a CSV file), fit the Bayesian AMMI or SREG (GGE) model of
Perez-Elizalde et al. (2012), check convergence, draw the biplot with HPD regions and compare models of different
numbers of terms, with and without the earlier trial. Every page shows an interpretation computed from the results
(bys_interpret()), the output as R prints it, formatted tables, plots and the R code that repeats the
analysis, each with a Copy button.
bys_app(launch.browser = interactive(), ...) bys_app_object()bys_app(launch.browser = interactive(), ...) bys_app_object()
launch.browser |
passed to |
... |
further arguments to |
The application needs the suggested packages shiny, bslib and DT. Plots are sent to the browser as WebP images when magick is installed (smaller than PNG; PNG otherwise) and can be downloaded as PNG, PDF or WebP. Text is set in IBM Plex Sans and output in IBM Plex Mono when the browser can reach Google Fonts, in the system fonts otherwise.
bys_app() is called for its side effect and returns the value of shiny::runApp() when the
application is closed; bys_app_object() returns the application object (for shiny::runApp(),
shiny::testServer() or deployment on a server).
Muhammad Yaseen ([email protected])
Perez-Elizalde, S., Jarquin, D. and Crossa, J. (2012). A General Bayesian Estimation Method of Linear-Bilinear Models Applied to Plant Breeding Trials With Genotype x Environment Interaction. Journal of Agricultural, Biological, and Environmental Statistics, 17(1), 15–37. (doi:10.1007/s13253-011-0063-9)
bayes_ammi, bayes_ammi_biplot, bys_compare, bys_interpret
if (interactive()) { bys_app( launch.browser = TRUE ) }if (interactive()) { bys_app( launch.browser = TRUE ) }
bys_cite() gives the references of the methods behind a result of the package, or the references of
every method in the package, as text or BibTeX. citation("baystability") cites the package and its main
methods.
bys_cite(x = NULL, style = c("text", "bibtex")) ## Default S3 method: bys_cite(x = NULL, style = c("text", "bibtex"))bys_cite(x = NULL, style = c("text", "bibtex")) ## Default S3 method: bys_cite(x = NULL, style = c("text", "bibtex"))
x |
a result of a function of the package, or |
style |
|
An object of class bibentry (printed in the chosen style).
Muhammad Yaseen ([email protected])
bys_cite( x = NULL , style = "text" ) data(cultivo2009) g <- bys_ls_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) bys_cite( x = g , style = "bibtex" )bys_cite( x = NULL , style = "text" ) data(cultivo2009) g <- bys_ls_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) bys_cite( x = g , style = "bibtex" )
bys_compare() compares fits of bayes_ammi() that differ in the number of multiplicative
terms, the model (AMMI or GGE), the error variances or the priors, by the deviance information criterion (DIC)
and the widely applicable information criterion (WAIC). Smaller values predict new data better.
bys_compare(...) ## Default S3 method: bys_compare(...)bys_compare(...) ## Default S3 method: bys_compare(...)
... |
fits of |
With over the observed plots,
(Spiegelhalter et al. 2002), the deviance evaluated at the posterior means of the cell means and variances; and
(Watanabe 2010; Gelman et al. 2014), accumulated over all draws during sampling. All fits must use the same data.
The standard error of a difference in WAIC comes from the plot-by-plot differences of the contributions
to WAIC: (Vehtari et al. 2017). Because the models are fitted to the same plots, it is smaller
than the standard error of either WAIC. A difference of less than about two of its standard errors does not
separate two models.
An object of class c("bys_compare", "bys_result", "list") with table
(data.table sorted by WAIC: model, terms, variances, DIC, pD,
WAIC, p_waic, se (standard error of WAIC), lambda_last_lower (lower HPD limit of the
last singular value), lambda_last_mean, dWAIC (difference from the best) and dWAIC_se (its
standard error)).
Methods: print(), plot(), bys_interpret().
Muhammad Yaseen ([email protected])
Spiegelhalter, D. J., Best, N. G., Carlin, B. P. and van der Linde, A. (2002). Bayesian measures of model complexity and fit. Journal of the Royal Statistical Society B, 64(4), 583–639. doi:10.1111/1467-9868.00353
Watanabe, S. (2010). Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory. Journal of Machine Learning Research, 11, 3571–3594.
Gelman, A., Hwang, J. and Vehtari, A. (2014). Understanding predictive information criteria for Bayesian models. Statistics and Computing, 24(6), 997–1016. doi:10.1007/s11222-013-9416-2
Vehtari, A., Gelman, A. and Gabry, J. (2017). Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC. Statistics and Computing, 27(5), 1413–1432. doi:10.1007/s11222-016-9696-4
data(cultivo2009) fits <- lapply( X = 1:2 , FUN = function(K) { bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 600 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = K , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) } ) bys_compare( AMMI1 = fits[[1]] , AMMI2 = fits[[2]] )data(cultivo2009) fits <- lapply( X = 1:2 , FUN = function(K) { bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 600 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = K , .burnin = 100 , .thin = 1 , .chains = 1 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) } ) bys_compare( AMMI1 = fits[[1]] , AMMI2 = fits[[2]] )
bys_contrasts() returns the matrix whose rows are
orthonormal and orthogonal to (Helmert contrasts). bayes_ammi() writes the
main effects as , which keeps them summing to
zero.
bys_contrasts(n) ## Default S3 method: bys_contrasts(n)bys_contrasts(n) ## Default S3 method: bys_contrasts(n)
n |
number of columns (at least 2). |
Row () has in its first
positions, in position and after it, with
, so that
The matrix .
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
K <- bys_contrasts( n = 4 ) K round(x = K %*% t(K), digits = 10)K <- bys_contrasts( n = 4 ) K round(x = K %*% t(K), digits = 10)
bys_interpret() turns a result of bayes_ammi(), bayes_ammi_biplot() or
bys_ls_ammi() into a plain-language interpretation: whether the chains have converged, which genotypes
and environments differ from the average (main effects whose HPD interval excludes zero), how strong the bilinear
terms are, which genotypes and environments interact significantly and in which direction, which are stable, and
what to check before acting on the results. Every statement is computed from the numbers of the result.
bys_interpret(x, higher_better = TRUE, top = 5L, ...) ## Default S3 method: bys_interpret(x, higher_better = TRUE, top = 5L, ...) ## S3 method for class 'bys_interpretation' print(x, ...) ## S3 method for class 'bys_interpretation' format(x, style = c("text", "markdown"), width = getOption("width", 80L), ...)bys_interpret(x, higher_better = TRUE, top = 5L, ...) ## Default S3 method: bys_interpret(x, higher_better = TRUE, top = 5L, ...) ## S3 method for class 'bys_interpretation' print(x, ...) ## S3 method for class 'bys_interpretation' format(x, style = c("text", "markdown"), width = getOption("width", 80L), ...)
x |
a result of |
higher_better |
|
top |
number of genotypes or environments named in lists (default 5). |
... |
unused. |
style |
|
width |
line width of the text (default |
The rules:
convergence: potential scale reduction factor below 1.1 (two or more chains), effective sample size of at least 400, Raftery-Lewis dependence factor below 5 and the Heidelberger-Welch tests passed (Crossa et al. 2011);
main effects: a genotype or environment differs from the average when the HPD interval of its effect excludes zero;
bilinear terms: a term whose HPD interval of reaches down to near zero (lower
limit below a tenth of the posterior mean) is weakly supported;
interaction: a genotype (environment) interacts significantly on the first term when the HPD interval of its first score excludes zero; genotypes and environments with significant scores of the same sign interact positively (the genotype does better there than its main effect predicts), of opposite sign negatively;
stability (bayes_ammi_biplot()): a genotype is stable when its HPD region contains the origin.
An object of class "bys_interpretation": a list with analysis, title,
headline, findings, recommendations and cautions (sentences), facts (the
numbers and lists behind the sentences), guide (how the method is read) and sources (the full
references of the method; bys_cite() gives them as BibTeX). print() shows the text;
format(x, style = "markdown") returns it as Markdown.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. Crop Science, 51(4), 1458–1469. doi:10.2135/cropsci2010.06.0343
data(cultivo2009) fm1 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 500 , .prior_data = NULL , .n0 = NULL , .model = c("AMMI", "GGE") , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 2 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) txt <- bys_interpret( x = fm1 , higher_better = TRUE , top = 5 ) txt cat(format(x = txt, style = "markdown"))data(cultivo2009) fm1 <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 500 , .prior_data = NULL , .n0 = NULL , .model = c("AMMI", "GGE") , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 2 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) txt <- bys_interpret( x = fm1 , higher_better = TRUE , top = 5 ) txt cat(format(x = txt, style = "markdown"))
bys_ls_ammi() computes the least-squares estimates of the AMMI model with all interaction axes: grand mean,
genotype and environment effects, singular values and vectors of the interaction, and the error variance. They
are the starting values of bayes_ammi() and the classical estimates it is compared with.
bys_ls_ammi(.data, .y, .gen, .env, .rep) ## Default S3 method: bys_ls_ammi(.data, .y, .gen, .env, .rep)bys_ls_ammi(.data, .y, .gen, .env, .rep) ## Default S3 method: bys_ls_ammi(.data, .y, .gen, .env, .rep)
.data |
a data frame with one row per plot. |
.y, .gen, .env, .rep
|
the columns of the response, genotypes, environments and replicates: bare names, strings or vectors. |
With the cell means of replicates, ,
, and the singular value decomposition of the interaction effects
(bys_ls_ge_effects()), axes. The error variance is the residual
variance of the model with random replicates within environments (bys_ls_model()), in closed form for
balanced data:
when the replicate mean square is not smaller, otherwise (the replicate variance component estimated as zero)
; SSW is the within-cell and
the replicate-within-environment sum of squares.
Change from the earlier versions. The error variance came from lme4::lmer(); the closed form gives
the same value for balanced data without needing lme4.
A list (class c("bys_ge_ammi", "bys_result", "list")) with the components of the earlier versions:
g, e, Rep, k
numbers of genotypes, environments, replicates and axes.
ge_meansthe result of bys_ls_means().
mu, sigma2, tau
grand mean, error variance and its reciprocal (precision).
tao, delta
genotype and environment effects (bys_ls_gen_effects(), bys_ls_env_effects()).
lambdas, alphas, gammas
singular values and genotype and environment singular vectors of the interaction.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
Gauch, H. G. (1992). Statistical Analysis of Regional Yield Trials: AMMI Analysis of Factorial Designs. Elsevier, Amsterdam.
data(cultivo2009) fit <- bys_ls_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) fit$lambdas fit$sigma2data(cultivo2009) fit <- bys_ls_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) fit$lambdas fit$sigma2
bys_ls_env_effects() computes the environment main effects, the deviations of the environment means from the grand mean.
bys_ls_env_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_env_effects(.data, .y, .gen, .env)bys_ls_env_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_env_effects(.data, .y, .gen, .env)
.data |
a data frame with one row per plot. |
.y, .gen, .env
|
the columns of the response, genotypes and environments: bare names, strings or vectors. |
An matrix with column EEffs (row names: environments).
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
bys_ls_gen_effects, bys_ls_ge_effects
data(cultivo2009) bys_ls_env_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site )data(cultivo2009) bys_ls_env_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site )
bys_ls_ge_effects() computes the interaction effects (the cell means centred on genotype and environment means) and
their singular value decomposition, the least-squares estimate of the multiplicative part of the AMMI model.
bys_ls_ge_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_ge_effects(.data, .y, .gen, .env)bys_ls_ge_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_ge_effects(.data, .y, .gen, .env)
.data |
a data frame with one row per plot. |
.y, .gen, .env
|
the columns of the response, genotypes and environments: bare names, strings or vectors. |
with singular values and orthonormal
singular vectors orthogonal to .
A list (class c("bys_ge_eff", "bys_result", "list")) with ge_effects (the matrix ) and ge_svd (svd() of it: d, u, v).
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
Gauch, H. G. (1992). Statistical Analysis of Regional Yield Trials: AMMI Analysis of Factorial Designs. Elsevier, Amsterdam.
data(cultivo2009) fit <- bys_ls_ge_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site ) fit$ge_svd$ddata(cultivo2009) fit <- bys_ls_ge_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site ) fit$ge_svd$d
bys_ls_gen_effects() computes the genotype main effects, the deviations of the genotype means from the grand mean.
bys_ls_gen_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_gen_effects(.data, .y, .gen, .env)bys_ls_gen_effects(.data, .y, .gen, .env) ## Default S3 method: bys_ls_gen_effects(.data, .y, .gen, .env)
.data |
a data frame with one row per plot. |
.y, .gen, .env
|
the columns of the response, genotypes and environments: bare names, strings or vectors. |
the least-squares estimates of the AMMI model (equal to the deviations of the plot means when the data are balanced).
A matrix with column GEffs (row names: genotypes).
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
bys_ls_env_effects, bys_ls_ge_effects
data(cultivo2009) bys_ls_gen_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site )data(cultivo2009) bys_ls_gen_effects( .data = cultivo2009 , .y = y , .gen = entry , .env = site )
bys_ls_means() computes the table of genotype-by-environment cell means and the grand mean, the data of the
AMMI model.
bys_ls_means(.data, .y, .gen, .env) ## Default S3 method: bys_ls_means(.data, .y, .gen, .env)bys_ls_means(.data, .y, .gen, .env) ## Default S3 method: bys_ls_means(.data, .y, .gen, .env)
.data |
a data frame with one row per plot. |
.y, .gen, .env
|
the columns of the response, genotypes and environments: bare names, strings or vectors. |
With the response of genotype in replicate of environment
and the number of replicates of the cell,
Genotypes and environments are in the order of their factor levels (sorted values when the columns are not factors).
A list (class c("bys_ge_mean", "bys_result", "list")) with ge_means, the matrix of means (row and column names: genotypes and environments), and grand_mean.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
bys_ls_var, bys_ls_ge_effects, bys_ls_ammi
data(cultivo2009) bys_ls_means( .data = cultivo2009 , .y = y , .gen = entry , .env = site )data(cultivo2009) bys_ls_means( .data = cultivo2009 , .y = y , .gen = entry , .env = site )
bys_ls_model() fits the two-way model with interaction and random replicates within environments by restricted
maximum likelihood (lme4::lmer()). Its residual variance is the error variance of the least-squares AMMI
fit (bys_ls_ammi(), which computes it in closed form).
bys_ls_model(.data, .y, .gen, .env, .rep) ## Default S3 method: bys_ls_model(.data, .y, .gen, .env, .rep)bys_ls_model(.data, .y, .gen, .env, .rep) ## Default S3 method: bys_ls_model(.data, .y, .gen, .env, .rep)
.data |
a data frame with one row per plot. |
.y, .gen, .env, .rep
|
the columns of the response, genotypes, environments and replicates: bare names, strings or vectors. |
The package lme4 is needed (it is suggested, not required, since version 1.0.0).
The lmerMod object of lme4::lmer(Y ~ Env + Gen + Env:Gen + (1 | Env:Rep)).
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
Bates, D., Maechler, M., Bolker, B. and Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1–48. doi:10.18637/jss.v067.i01
data(cultivo2009) if (requireNamespace("lme4", quietly = TRUE)) { fm <- bys_ls_model( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) stats::sigma(fm)^2 }data(cultivo2009) if (requireNamespace("lme4", quietly = TRUE)) { fm <- bys_ls_model( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep ) stats::sigma(fm)^2 }
bys_ls_var() computes the variance of the replicates of every genotype-by-environment cell.
bys_ls_var(.data, .y, .gen, .env) ## Default S3 method: bys_ls_var(.data, .y, .gen, .env)bys_ls_var(.data, .y, .gen, .env) ## Default S3 method: bys_ls_var(.data, .y, .gen, .env)
.data |
a data frame with one row per plot. |
.y, .gen, .env
|
the columns of the response, genotypes and environments: bare names, strings or vectors. |
NA for a cell with one replicate. The within-cell sum of squares of the Bayesian AMMI model is
.
Change from the earlier versions. bayes_ammi() used the sum of these variances in place of the
within-cell sum of squares.
A list (class c("bys_ge_var", "bys_result", "list")) with ge_variances, the matrix of variances.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
data(cultivo2009) bys_ls_var( .data = cultivo2009 , .y = y , .gen = entry , .env = site )data(cultivo2009) bys_ls_var( .data = cultivo2009 , .y = y , .gen = entry , .env = site )
The symbols used in the help pages and vignettes of baystability, with their meaning and the argument or result
component that holds them. The notation follows one rule throughout: scalars are upper-case letters in normal
face (, ), indices lower-case italic (), vectors lower-case bold
(, ) and matrices upper-case bold (,
).
bys_notation(format = c("table", "path", "tex"))bys_notation(format = c("table", "path", "tex"))
format |
|
See format.
Muhammad Yaseen ([email protected])
Other baystability utilities:
bys_reference(),
bys_save(),
bys_theme()
bys_notation( format = c("table", "path", "tex")[1] )bys_notation( format = c("table", "path", "tex")[1] )
bys_orthonormal() orthogonalises the columns of a matrix by the Gram-Schmidt process, optionally completes them to
a basis of the whole space and scales them to unit length.
bys_orthonormal(u = NULL, basis = TRUE, norm = TRUE) ## Default S3 method: bys_orthonormal(u = NULL, basis = TRUE, norm = TRUE)bys_orthonormal(u = NULL, basis = TRUE, norm = TRUE) ## Default S3 method: bys_orthonormal(u = NULL, basis = TRUE, norm = TRUE)
u |
a matrix (or vector) whose columns are orthogonalised. |
basis |
complete the columns to a basis of the whole space (default |
norm |
scale the columns to unit length (default |
For columns ,
each divided by its length when norm = TRUE. With basis = TRUE and fewer columns than rows, unit
vectors are added (those least explained by the given columns) to complete a basis.
The matrix of orthogonal (orthonormal with norm = TRUE) columns; NULL for u = NULL.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. \emphCrop Science, \strong51(4), 1458–1469. \doi10.2135/cropsci2010.06.0343
V <- bys_orthonormal( u = cbind(1, 1:4) , basis = TRUE , norm = TRUE ) round(x = crossprod(V), digits = 10)V <- bys_orthonormal( u = cbind(1, 1:4) , basis = TRUE , norm = TRUE ) round(x = crossprod(V), digits = 10)
bys_priors() sets the hyperparameters of the prior distributions of bayes_ammi(). The
defaults are the vague but proper priors of Crossa et al. (2011): normal priors with mean zero and variance
for the overall mean, the main effects and the singular values, and a scaled inverse
chi-square prior with one degree of freedom for the error variance.
bys_priors( mu_mean = 0, mu_var = 1e+08, tau_mean = 0, tau_var = 1e+08, delta_mean = 0, delta_var = 1e+08, lambda_mean = 0, lambda_var = 1e+08, nu = 1, s2 = NULL ) ## S3 method for class 'bys_priors' print(x, ...)bys_priors( mu_mean = 0, mu_var = 1e+08, tau_mean = 0, tau_var = 1e+08, delta_mean = 0, delta_var = 1e+08, lambda_mean = 0, lambda_var = 1e+08, nu = 1, s2 = NULL ) ## S3 method for class 'bys_priors' print(x, ...)
mu_mean, mu_var
|
prior mean and variance of the overall mean |
tau_mean, tau_var
|
prior mean (a scalar or a vector of length |
delta_mean, delta_var
|
prior mean (scalar or length |
lambda_mean, lambda_var
|
prior mean and variance of the singular values |
nu, s2
|
degrees of freedom |
x |
a |
... |
unused. |
With genotypes, environments and bilinear terms,
each main effect restricted to sum zero,
and spherical uniform priors for the singular vectors on the subspaces orthogonal to and to
the other vectors. = NULL (default) takes the residual mean square of the
least-squares AMMI fit, so that the prior is equally vague whatever the unit of the trait; with it carries the information of a single observation. Crossa et al. (2011) report ;
their published posterior of is reproduced with the vague default (see the vignette on
validation).
A list of class "bys_priors" with these elements.
Muhammad Yaseen ([email protected])
Crossa, J., Perez-Elizalde, S., Jarquin, D., Cotes, J. M., Viele, K., Liu, G. and Cornelius, P. L. (2011). Bayesian estimation of the additive main effects and multiplicative interaction model. Crop Science, 51(4), 1458–1469. doi:10.2135/cropsci2010.06.0343
Hobert, J. P. and Casella, G. (1996). The effect of improper priors on Gibbs sampling in hierarchical linear mixed models. Journal of the American Statistical Association, 91(436), 1461–1473.
bys_priors( mu_mean = 0 , mu_var = 1e8 , tau_mean = 0 , tau_var = 1e8 , delta_mean = 0 , delta_var = 1e8 , lambda_mean = 0 , lambda_var = 1e8 , nu = 1 , s2 = NULL )bys_priors( mu_mean = 0 , mu_var = 1e8 , tau_mean = 0 , tau_var = 1e8 , delta_mean = 0 , delta_var = 1e8 , lambda_mean = 0 , lambda_var = 1e8 , nu = 1 , s2 = NULL )
Reads inst/extdata/reference.csv: one row per published number, with its source, the R call
that recomputes it with this package (call), the expression that extracts the number from the result
(extract, in terms of x), the printed value and the digits to compare. The same file drives the test
of published values and the vignette that reproduces the published examples. Each distinct call is evaluated once.
bys_reference(source = NULL, evaluate = FALSE, level = 1)bys_reference(source = NULL, evaluate = FALSE, level = 1)
source |
optional regular expression; keep rows whose |
evaluate |
logical; evaluate the rows and add columns |
level |
largest |
A data.table with columns id, source, quantity, call, extract,
value, digits, level, note (and computed, agrees).
Muhammad Yaseen ([email protected])
Other baystability utilities:
bys_notation(),
bys_save(),
bys_theme()
ref <- bys_reference( source = NULL , evaluate = FALSE , level = 1 ) ref bys_reference( source = "." , evaluate = TRUE , level = 1 )ref <- bys_reference( source = NULL , evaluate = FALSE , level = 1 ) ref bys_reference( source = "." , evaluate = TRUE , level = 1 )
A wrapper of ggsave with the defaults of the package: a vector PDF through
cairo_pdf (embedded fonts, correct glyphs), A4 landscape (11.69 x 8.27 inches) and 600
dpi for raster formats. The device follows the file extension for other formats (.png, .svg,
.tiff, ...).
bys_save( plot = ggplot2::last_plot(), filename, path = NULL, width = 11.69, height = 8.27, units = c("in", "cm", "mm"), dpi = 600, scale = 1, device = NULL, limitsize = TRUE, ... ) ## Default S3 method: bys_save( plot = ggplot2::last_plot(), filename, path = NULL, width = 11.69, height = 8.27, units = c("in", "cm", "mm"), dpi = 600, scale = 1, device = NULL, limitsize = TRUE, ... )bys_save( plot = ggplot2::last_plot(), filename, path = NULL, width = 11.69, height = 8.27, units = c("in", "cm", "mm"), dpi = 600, scale = 1, device = NULL, limitsize = TRUE, ... ) ## Default S3 method: bys_save( plot = ggplot2::last_plot(), filename, path = NULL, width = 11.69, height = 8.27, units = c("in", "cm", "mm"), dpi = 600, scale = 1, device = NULL, limitsize = TRUE, ... )
plot |
a |
filename |
file name; its extension chooses the format. |
path |
directory to save in (default |
width, height
|
size (default 11.69 x 8.27, A4 landscape, in |
units |
|
dpi |
resolution for raster formats (default 600). |
scale |
multiplicative scaling factor (default 1). |
device |
|
limitsize |
logical; refuse images larger than 50 x 50 inches (default |
... |
passed to |
The file name, invisibly.
Muhammad Yaseen ([email protected])
Other baystability utilities:
bys_notation(),
bys_reference(),
bys_theme()
library(ggplot2) p <- ggplot(data = data.frame(x = 1:10, y = (1:10)^2), mapping = aes(x = x, y = y)) + geom_line() + bys_theme( base_size = 11 , base_family = "serif" , ticks_inward = TRUE , legend_position = "bottom" ) f <- tempfile(fileext = ".pdf") bys_save( plot = p , filename = f , path = NULL , width = 11.69 , height = 8.27 , units = c("in", "cm", "mm")[1] , dpi = 600 , scale = 1 , device = NULL , limitsize = TRUE ) bys_save( plot = p , filename = basename(f) , path = tempdir() , width = 11.69 , height = 8.27 , units = c("in", "cm", "mm")[1] , dpi = 600 , scale = 1 , device = grDevices::cairo_pdf , limitsize = TRUE ) bys_save( plot = p , filename = tempfile(fileext = ".png") , path = NULL , width = 6 , height = 4 , units = c("in", "cm", "mm")[1] , dpi = 300 , scale = 1 , device = NULL , limitsize = TRUE )library(ggplot2) p <- ggplot(data = data.frame(x = 1:10, y = (1:10)^2), mapping = aes(x = x, y = y)) + geom_line() + bys_theme( base_size = 11 , base_family = "serif" , ticks_inward = TRUE , legend_position = "bottom" ) f <- tempfile(fileext = ".pdf") bys_save( plot = p , filename = f , path = NULL , width = 11.69 , height = 8.27 , units = c("in", "cm", "mm")[1] , dpi = 600 , scale = 1 , device = NULL , limitsize = TRUE ) bys_save( plot = p , filename = basename(f) , path = tempdir() , width = 11.69 , height = 8.27 , units = c("in", "cm", "mm")[1] , dpi = 600 , scale = 1 , device = grDevices::cairo_pdf , limitsize = TRUE ) bys_save( plot = p , filename = tempfile(fileext = ".png") , path = NULL , width = 6 , height = 4 , units = c("in", "cm", "mm")[1] , dpi = 300 , scale = 1 , device = NULL , limitsize = TRUE )
The theme used by every plot() method of baystability (identical in all packages of the
author): theme_classic with a serif font, black axis lines, ticks pointing inwards and no
grid, close to the look of TikZ/pgfplots figures in LaTeX documents. The plot() methods also use
scales::pretty_breaks(n = 10) on every continuous axis. Save figures with bys_save.
bys_theme( base_size = 11, base_family = "serif", ticks_inward = TRUE, legend_position = "bottom" )bys_theme( base_size = 11, base_family = "serif", ticks_inward = TRUE, legend_position = "bottom" )
base_size |
base font size in points (default 11). |
base_family |
font family (default |
ticks_inward |
logical; ticks point into the panel, as in pgfplots (default |
legend_position |
position of the legend (default |
A ggplot2 theme.
Muhammad Yaseen ([email protected])
Other baystability utilities:
bys_notation(),
bys_reference(),
bys_save()
library(ggplot2) p <- ggplot(data = data.frame(x = 1:20, y = cumsum(sin(1:20))), mapping = aes(x = x, y = y)) + geom_line() p + bys_theme( base_size = 11 , base_family = "serif" , ticks_inward = TRUE , legend_position = "bottom" ) p + bys_theme( base_size = 12 , base_family = "serif" , ticks_inward = FALSE , legend_position = "right" ) + scale_x_continuous(breaks = scales::pretty_breaks(n = 10))library(ggplot2) p <- ggplot(data = data.frame(x = 1:20, y = cumsum(sin(1:20))), mapping = aes(x = x, y = y)) + geom_line() p + bys_theme( base_size = 11 , base_family = "serif" , ticks_inward = TRUE , legend_position = "bottom" ) p + bys_theme( base_size = 12 , base_family = "serif" , ticks_inward = FALSE , legend_position = "right" ) + scale_x_continuous(breaks = scales::pretty_breaks(n = 10))
The draws of bayes_ammi() are a coda::mcmc.list (component draws). These methods hand
them to the packages posterior and coda; every plot of bayesplot (mcmc_trace(),
mcmc_areas(), mcmc_rank_overlay(), ...) then works on them, as does posterior::summarise_draws()
(rank-normalised , bulk and tail effective sample sizes).
## S3 method for class 'bys_bayes_ammi' as_draws_df(x, ...) ## S3 method for class 'bys_bayes_ammi' as_draws(x, ...) ## S3 method for class 'bys_bayes_ammi' as.mcmc.list(x, ...)## S3 method for class 'bys_bayes_ammi' as_draws_df(x, ...) ## S3 method for class 'bys_bayes_ammi' as_draws(x, ...) ## S3 method for class 'bys_bayes_ammi' as.mcmc.list(x, ...)
x |
a result of |
... |
unused. |
as_draws_df(): a posterior::draws_df; as_draws(): a posterior::draws_list;
as.mcmc.list(): the coda::mcmc.list.
Muhammad Yaseen ([email protected])
Gabry, J., Simpson, D., Vehtari, A., Betancourt, M. and Gelman, A. (2019). Visualization in Bayesian workflow. Journal of the Royal Statistical Society A, 182(2), 389–402. doi:10.1111/rssa.12378
Vehtari, A., Gelman, A., Simpson, D., Carpenter, B. and Burkner, P.-C. (2021). Rank-normalization, folding, and localization: an improved R-hat for assessing convergence of MCMC. Bayesian Analysis, 16(2), 667–718. doi:10.1214/20-BA1221
data(cultivo2009) fit <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 500 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 2 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) if (requireNamespace("posterior", quietly = TRUE)) { dr <- posterior::as_draws_df(x = fit) posterior::summarise_draws( .x = posterior::subset_draws( x = dr , variable = c("mu", "lambda[1]", "lambda[2]") ) ) } if (requireNamespace("bayesplot", quietly = TRUE)) { bayesplot::mcmc_trace(x = fit$draws, pars = c("lambda[1]", "lambda[2]")) }data(cultivo2009) fit <- bayes_ammi( .data = cultivo2009 , .y = y , .gen = entry , .env = site , .rep = rep , .nIter = 500 , .prior_data = NULL , .n0 = NULL , .model = "AMMI" , .k = 2 , .burnin = 100 , .thin = 1 , .chains = 2 , .priors = bys_priors( mu_mean = 0 , mu_var = 1e+8 , tau_mean = 0 , tau_var = 1e+8 , delta_mean = 0 , delta_var = 1e+8 , lambda_mean = 0 , lambda_var = 1e+8 , nu = 1 , s2 = NULL ) , .level = 0.95 , .seed = 1 , .align = TRUE , .waic = TRUE ) if (requireNamespace("posterior", quietly = TRUE)) { dr <- posterior::as_draws_df(x = fit) posterior::summarise_draws( .x = posterior::subset_draws( x = dr , variable = c("mu", "lambda[1]", "lambda[2]") ) ) } if (requireNamespace("bayesplot", quietly = TRUE)) { bayesplot::mcmc_trace(x = fit$draws, pars = c("lambda[1]", "lambda[2]")) }
The analysis functions of baystability return the named list they have always returned, now with the class
c("bys_<analysis>", "bys_result", "list"). Components are read as before (x$ANOVA,
x[["Means"]]); the methods below print, summarise and plot the result and turn any component into a
data.table.
## S3 method for class 'bys_result' print(x, digits = 4L, ...) ## S3 method for class 'bys_result' summary(object, ...) ## S3 method for class 'summary.bys_result' print(x, ...) ## S3 method for class 'bys_result' format(x, ...) ## S3 method for class 'bys_result' as.data.table(x, keep.rownames = FALSE, ..., component = 1L) ## S3 method for class 'bys_result' as.data.frame(x, row.names = NULL, optional = FALSE, ..., component = 1L) ## S3 method for class 'bys_result' plot(x, ...)## S3 method for class 'bys_result' print(x, digits = 4L, ...) ## S3 method for class 'bys_result' summary(object, ...) ## S3 method for class 'summary.bys_result' print(x, ...) ## S3 method for class 'bys_result' format(x, ...) ## S3 method for class 'bys_result' as.data.table(x, keep.rownames = FALSE, ..., component = 1L) ## S3 method for class 'bys_result' as.data.frame(x, row.names = NULL, optional = FALSE, ..., component = 1L) ## S3 method for class 'bys_result' plot(x, ...)
x, object
|
a baystability result. |
digits |
significant digits of printed numbers (default 4). |
... |
passed on (to |
keep.rownames, row.names, optional
|
as in |
component |
name or number of the component to convert (default: the first one). |
print() returns x invisibly; summary() an object of class
summary.bys_result; format() a character string; as.data.table() and
as.data.frame() the chosen component as a table; plot() a ggplot object.
Muhammad Yaseen ([email protected])
Grain yield of 12 maize hybrids in 25 environments in two consecutive years, the multi-environment trial of
Perez-Elizalde et al. (2012), Section 3.2: cultivo2008 (the first year, used as the prior) and
cultivo2009 (the second year). Randomized complete blocks with 3 replicates in every environment.
Data frames with 900 rows (12 genotypes x 25 environments x 3 replicates) and 4 columns:
siteenvironment, 1 to 25 (the same environments in both years).
repreplicate, 1 to 3.
entrygenotype, 1 to 12.
ygrain yield (kg/ha).
The paper describes two replicates; the data have three. The posterior means of its Table B.1 are, to within a posterior standard deviation of a hundredth, the averages of the least-squares estimates of the two years, as the method gives with equal weights for both years (see the vignette on the published analysis). The help page of version 0.2.0 described another data set.
Muhammad Yaseen ([email protected])
Perez-Elizalde, S., Jarquin, D. and Crossa, J. (2012). A general Bayesian estimation method of linear-bilinear models applied to plant breeding trials with genotype x environment interaction. Journal of Agricultural, Biological, and Environmental Statistics, 17(1), 15–37. doi:10.1007/s13253-011-0063-9
data(cultivo2008) data(cultivo2009) str(cultivo2009) bys_ls_means( .data = cultivo2009 , .y = y , .gen = entry , .env = site )$grand_meandata(cultivo2008) data(cultivo2009) str(cultivo2009) bys_ls_means( .data = cultivo2009 , .y = y , .gen = entry , .env = site )$grand_mean