bayes_met {ProbBreed}R Documentation

Bayesian model for multi-environment trials

Description

This function runs a Bayesian model for analyzing data from Multi-environment trials using rstan, the R interface to Stan.

Usage

bayes_met(
  data,
  gen,
  loc,
  repl,
  trait,
  reg = NULL,
  year = NULL,
  res.het = FALSE,
  iter = 2000,
  cores = 2,
  chains = 4,
  pars = NA,
  warmup = floor(iter/2),
  thin = 1,
  seed = sample.int(.Machine$integer.max, 1),
  init = "random",
  verbose = FALSE,
  algorithm = c("NUTS", "HMC", "Fixed_param"),
  control = NULL,
  include = TRUE,
  show_messages = TRUE,
  ...
)

Arguments

data

A data frame containing the observations.

gen, loc

A string. The name of the column that corresponds to the evaluated genotype and location, respectively. If the environment is a combination of other factors (for instance, location-year), the name of the column that contains this information must be attributed to loc.

repl

A string, a vector, or NULL. If the trial is randomized in complete blocks, repl will be a string representing the name of the column that corresponds to the blocks. If the trial is randomized in incomplete blocks design, repl will be a string vector containing the name of the column that corresponds to the replicate and block effects on the first and second positions, respectively. If the data do not have replicates, repl will be NULL.

trait

A string. The name of the column that corresponds to the analysed variable.

reg

A string or NULL. If the data has information of regions, reg will be a string with the name of the column that corresponds to the region information. Otherwise, reg = NULL (default).

year

A string or NULL. If the data set has information of time-related environmental factors (years, seasons...), year will be a string with the name of the column that corresponds to the time information. Otherwise, year = NULL (default).

res.het

Logical, indicating if the model should consider heterogeneous residual variances. Default is FALSE. If TRUE, the model will estimate one residual variance per location.

iter

A positive integer specifying the number of iterations for each chain (including warmup). The default is 2000.

cores

Number of cores to use when executing the chains in parallel, which defaults to 1 but we recommend setting the mc.cores option to be as many processors as the hardware and RAM allow (up to the number of chains).

chains

A positive integer specifying the number of Markov chains. The default is 4.

pars

A vector of character strings specifying parameters of interest. The default is NA indicating all parameters in the model. If include = TRUE, only samples for parameters named in pars are stored in the fitted results. Conversely, if include = FALSE, samples for all parameters except those named in pars are stored in the fitted results.

warmup

A positive integer specifying the number of warmup (aka burnin) iterations per chain. If step-size adaptation is on (which it is by default), this also controls the number of iterations for which adaptation is run (and hence these warmup samples should not be used for inference). The number of warmup iterations should be smaller than iter and the default is iter/2.

thin

A positive integer specifying the period for saving samples. The default is 1, which is usually the recommended value.

seed

The seed for random number generation. The default is generated from 1 to the maximum integer supported by R on the machine. Even if multiple chains are used, only one seed is needed, with other chains having seeds derived from that of the first chain to avoid dependent samples. When a seed is specified by a number, as.integer will be applied to it. If as.integer produces NA, the seed is generated randomly. The seed can also be specified as a character string of digits, such as "12345", which is converted to integer.

init

Initial values specification. See the detailed documentation for the init argument in stan.

verbose

TRUE or FALSE: flag indicating whether to print intermediate output from Stan on the console, which might be helpful for model debugging.

algorithm

One of sampling algorithms that are implemented in Stan. Current options are "NUTS" (No-U-Turn sampler, Hoffman and Gelman 2011, Betancourt 2017), "HMC" (static HMC), or "Fixed_param". The default and preferred algorithm is "NUTS".

control

A named list of parameters to control the sampler's behavior. See the details in the documentation for the control argument in stan.

include

Logical scalar defaulting to TRUE indicating whether to include or exclude the parameters given by the pars argument. If FALSE, only entire multidimensional parameters can be excluded, rather than particular elements of them.

show_messages

Either a logical scalar (defaulting to TRUE) indicating whether to print the summary of Informational Messages to the screen after a chain is finished or a character string naming a path where the summary is stored. Setting to FALSE is not recommended unless you are very sure that the model is correct up to numerical error.

...

Additional arguments can be chain_id, init_r, test_grad, append_samples, refresh, enable_random_init. See the documentation in stan.

Details

More details about the usage of bayes_met and other function of the ProbBreed package can be found at https://saulo-chaves.github.io/ProbBreed_site/. Information on solutions to solve convergence or mixing issue can be found at https://mc-stan.org/misc/warnings.html.

Value

An object of S4 class stanfit representing the fitted results. Slot mode for this object indicates if the sampling is done or not.

Methods

sampling

signature(object = "stanmodel") Call a sampler (NUTS, HMC, or Fixed_param depending on parameters) to draw samples from the model defined by S4 class stanmodel given the data, initial values, etc.

See Also

rstan::sampling(), rstan::stan(), rstan::stanfit()

Examples


mod = bayes_met(data = maize,
                gen = "Hybrid",
                loc = "Location",
                repl = c("Rep", "Block"),
                year = NULL,
                reg = 'Region',
                res.het = FALSE,
                trait = 'GY',
                iter = 6000, cores = 4, chains = 4)
                

[Package ProbBreed version 1.0.3.2 Index]