metan (version 1.2.1)

mahala_design: Mahalanobis distance from designed experiments

Description

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. Alternatively, it is possible to use an object of class 'split_factors' to compute the distance for each level of the grouping factor. See ?split_factors.

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 split the data into subsets. The function is then applied to each subset and returns a list where each element contains the results for one level of the variable in by. To split the data by more than one factor variable, use the function split_factors to pass subsetted data to .data.

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 the .data is an object of class split_factors then a list of distances will be returned.

Examples

Run this code
# NOT RUN {
library(metan)
maha_group <- mahala_design(data_ge,
                            gen = GEN,
                            rep = REP,
                            resp = c(GY, HM))

# Compute one distance for each environment
maha_group <- mahala_design(data_ge, GEN, REP, 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')
# }

Run the code above in your browser using DataLab