Compute the Mahalanobis distance using data from an experiment conducted in a randomized complete block design or completely randomized design.

## Usage

mahala_design(
.data,
gen,
rep,
resp,
design = "RCBD",
by = NULL,
return = "distance"
)

## Arguments

.data

The dataset containing the columns related to Genotypes, replication/block and response variables, possible with grouped data passed from dplyr::group_by().

gen

The name of the column that contains the levels of the genotypes.

rep

The name of the column that contains the levels of the replications/blocks.

resp

The response variables. For example resp = c(var1, var2, var3).

design

The experimental design. Must be RCBD or CRD.

by

One variable (factor) to compute the function by. It is a shortcut to dplyr::group_by(). To compute the statistics by more than one grouping variable use that function.

return

What the function return? Default is 'distance', i.e., the Mahalanobis distance. Alternatively, it is possible to return the matrix of means return = 'means', or the variance-covariance matrix of residuals return = 'covmat'.

## Value

A symmetric matrix with the Mahalanobis' distance. If .data is a grouped data passed from dplyr::group_by() then the results will be returned into a list-column of data frames.

## Author

Tiago Olivoto tiagoolivoto@gmail.com

## Examples

# \donttest{
library(metan)
maha <- mahala_design(data_g,
gen = GEN,
rep = REP,
resp = everything(),
return = "covmat")

# Compute one distance for each environment (all numeric variables)
maha_group <- mahala_design(data_ge,
gen = GEN,
rep = REP,
resp = everything(),
by = ENV)

# Return the variance-covariance matrix of residuals
cov_mat <- mahala_design(data_ge,
gen = GEN,
rep = REP,
resp = c(GY, HM),
return = 'covmat')
# }