Skip to contents

The `compute_ancova` function performs an exhaustive Analysis of Covariance across agricultural experimental records. It adjusts the treatment (genotypic) means for differences in a concomitant variable (covariate) to improve experimental precision and error control.

Usage

compute_ancova(data, response_trait, covariate_trait, reporting_level = 2)

Arguments

data

A verified data.frame containing the experimental trial records.

response_trait

A character string specifying the dependent phenotypic trait column.

covariate_trait

A character string specifying the auxiliary covariate column.

reporting_level

An integer vector flag defining console trace settings: 0 for silent execution, 1 for printing the variance partitioning table, and 2 for exhaustive diagnostic tracking logs. Defaults to 2.

Value

Invisibly returns a structured named list of class "list" containing 5 computational components:

response_trait

A character string indicating the target phenotypic response variable evaluated.

covariate_trait

A character string indicating the concomitant covariate variable utilized for model adjustment.

model

The underlying fitted linear model object of class aov.

ancova_table

A summary list structure of class "summary.aov" containing the Analysis of Covariance table with degrees of freedom, sums of squares, mean squares, F-values, and p-values.

adjusted_means

A data.frame containing the covariate-adjusted genotypic/cultivar means (least-squares means) calculated at the mean value of the covariate.

If reporting_level >= 1, the compiled ANCOVA table is printed directly to the console before returning the output object.

Details

In agricultural experiments, variation in a dependent phenotypic trait can sometimes be partially controlled by measuring a secondary auxiliary property (covariate, e.g., initial stand count or flowering duration). This engine fits a linear model incorporating both the categorical genotypic design structure and the continuous covariate vector, extracting the adjusted sums of squares, F-statistics, and adjusted marginal means.

Examples

data(gv_data, package = "AgriDataTools")

# Perform ANCOVA using Plant Height (PH) as response and Spike Length (SL) as covariate
ancova_res <- compute_ancova(
  data = gv_data,
  response_trait = "PH",
  covariate_trait = "SL",
  reporting_level = 2
)
#> =====================================================================================
#> AGRIDATATOOLS PACKAGED ENGINE v0.1.0 - ANALYSIS OF COVARIANCE (ANCOVA)
#> Computation Inception:  2026-08-17 12:02:15.44884 
#> -------------------------------------------------------------------------------------
#> [DIAGNOSTIC - ANCOVA]: Fitting linear model with covariate adjustment...
#> [DIAGNOSTIC - ANCOVA]: Computing covariate-adjusted genotypic means...
#> 
#> ---------------------------------------------------------------------------
#>  COMPILED ANCOVA VARIANCE PARTITIONING TABLE
#> ---------------------------------------------------------------------------
#>             Df Sum Sq Mean Sq F value Pr(>F)    
#> Replication  2   17.9    8.97   1.530  0.223    
#> Genotype    39 2367.1   60.69  10.358 <2e-16 ***
#> SL           1   11.3   11.30   1.928  0.169    
#> Residuals   77  451.2    5.86                   
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> =====================================================================================
#> 
#> [LOG - FINALIZE]: ANCOVA execution completed in  0.00746  seconds.
print(ancova_res$ancova_table)
#>             Df Sum Sq Mean Sq F value Pr(>F)    
#> Replication  2   17.9    8.97   1.530  0.223    
#> Genotype    39 2367.1   60.69  10.358 <2e-16 ***
#> SL           1   11.3   11.30   1.928  0.169    
#> Residuals   77  451.2    5.86                   
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1