isCompoundSymmetric.matrix: Tests whether an object of class matrix is compound symmetric

View source: R/asremlPlusUtilities.r

isCompoundSymmetric.matrixR Documentation

Tests whether an object of class matrix is compound symmetric

Description

Tests whether an object of class matrix is compound symmetric by checking whether all diagonal elements are equal and all off-diagonal elements are equal.

Usage

## S3 method for class 'matrix'
isCompoundSymmetric(object, tol = 100 * .Machine$double.eps, ...) 

Arguments

object

An object to be tested.

tol

a numeric scalar > 0 specifying that values smaller than it are considered to be zero.

...

Provision for passing arguments to functions called internally - not used at present.

Value

A logical.

Author(s)

Chris Brien

See Also

isSymmetric

Examples

  data(Oats.dat)
  
  ## Not run: 
  ## Use asreml to get the variance matrix of a set of predictions

  m1.asr <- asreml(Yield ~ Nitrogen*Variety, 
                   random=~Blocks/Wplots,
                   data=Oats.dat)
  current.asrt <- as.asrtests(m1.asr)
  Var.pred <- asreml::predict.asreml(m1.asr, classify="Nitrogen:Variety", 
                                      vcov = TRUE)
                                    est.status = "status")
  isCompoundSymmetrix(Var.pred$vcov)

## End(Not run)
  
  ## Use lmerTest and emmmeans to get the variance matrix of a set of predictions
  if (requireNamespace("lmerTest", quietly = TRUE) & 
      requireNamespace("emmeans", quietly = TRUE))
  {
    m1.lmer <- lmerTest::lmer(Yield ~ Nitrogen*Variety + (1|Blocks/Wplots),
                              data=Oats.dat)
    Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
    Var.vcov <- vcov(Var.emm)
  }

  if (exists("Var.vcov"))
  {
    ## Check the variance matrix of the predictions is compound symmetric
    isCompoundSymmetric(Var.vcov)
  }

asremlPlus documentation built on Oct. 27, 2024, 5:06 p.m.