| R2adj.asreml {asremlPlus} | R Documentation | 
Calculates the adjusted coefficient of determination for a specified combination of fixed and random terms.
Description
Calculates the adjusted coefficient of determination (R2) that measures the contributions to the total variance exhibited by the observations of a specified combination of fixed and random terms in a fitted linear mixed model.
Note that the adjusted R2 can be negative, which indicates that the contribution of the terms to the total variance is very small relative to the sum of the degrees of freedom of the terms.
Piepho's (2023) method for GLMMs has not been implemented. This function is not available for ASReml-R version 3.
Usage
## S3 method for class 'asreml'
R2adj(asreml.obj, 
      include.which.fixed = ~ ., orthogonalize = "hybrid", 
      include.which.random = NULL, 
      bound.exclusions = c("F","B","S","C"), ...)Arguments
| asreml.obj | An  | 
| include.which.fixed | A  Note that the contribution of a subset of the fixed terms is only unique if the effects for the fixed terms are orthogonal; if the effects are not orthogonal then the contributions will depend on the order of the terms in the formula. Also, determining the joint contribution of a subset of the fixed terms in the model may be computationally demanding because the projection matrices have to be formed for all fixed terms and these projections matrices have to be orthogonalized. A heavy computational burden is most likely when the effects for the fixed terms are not orthogonal, for example, when numeric covariates are included amongst the terms. | 
| orthogonalize | A  | 
| include.which.random | A  | 
| bound.exclusions | A  | 
| ... | Provision for passing arguments to functions called internally - not used at present. | 
Details
The method used to compute the adjusted R2 under a linear mixes model (LMM) is that 
described by Piepho (2023). Here, the method has been extended to allow computation  
of the adjusted R2 for a subset of the fixed terms. A set of orthogonalized 
projectors for all of the fixed terms in the model (a set of 
\mathbf{Q}_i\mathrm{s}) is obtained and the combined contribution of the 
fixed terms nominated in include.which.fixed is obtained by computing the 
average semisquared bias, ASSB, for the nominated fixed terms as:
\Sigma_i \{(\mathbf{Q}_i \mathbf{X}\boldsymbol{\beta})^\mathrm{T}\mathbf{Q}_i \mathbf{X}\boldsymbol{\beta} + \textnormal{trace}(\mathbf{X}^\mathrm{T} \mathbf{Q}_i \mathbf{X} \mathrm{var}(\boldsymbol{\beta})) \} / (n - 1)
Of the two methods, eigenmethods is least likely to fail, but it does 
not establish the marginality between the terms. It is often needed when 
there is nonorthogonality between terms, such as when there are several linear 
covariates. It can also be more efficient in these circumstances.
The process can be computationally expensive, particularly for a large data set (500 or more observations) and/or when many terms are to be orthogonalized, particularly if they are not orthogonal.
If the error "Matrix is not idempotent" should occur then, especially if 
there are  many terms, one might try using set.daeTolerance from the 
dae package to reduce the tolerance used in determining if values are 
either the same or are zero; it may be necessary to lower the tolerance to as 
low as 0.001. Also, setting orthogonalize to eigenmethods is 
worth a try.
In doing the computations, no changes are made to the fitted model, nor is the 
formula stored in asreml.obj referred to. Instead, the 
names of the terms referred to are those stored in the coefficients 
component of the asreml.obj.  Use 
attr(asreml.obj$coefficients$fixed, which = "terms") to access the attribute 
for fixed terms; substitute random for fixed to see the names of the 
random terms. For fixed terms. the term names are the same as those in the 
Wald table produced by wald.asreml, and, for random terms, the same as those 
in the vparameters component of the asreml.obj. Two asreml 
formula functions whose terms can differ from their formulation in a 
model formula are at and str.)
The function estimateV.asreml is used to calculate the variance matrices 
required in calculating the adjusted R2.
Value
A numeric that is the adjusted R2, expressed as a percentage. It has attributes 
include.which.fixed, include.which.random and missing.termmatrix 
(use attr(x, which = "name") to access the attribute name). 
The missing.termmatrix attribute will be NULL, unless the design matrix 
could not be obtained for one or more model terms. If is is not NULL, it will be 
a list of terms whose design matices could not be produced  and so are not included in 
the variance matrix estimate. An NA will be returned for the adjusted R2 if 
missing.termmatrix is not NULL or a generalized inverse could 
not be computed for the variance matrix estimate.
Author(s)
Chris Brien
References
Piepho, H.-P. (2023). An adjusted coefficient of determination (R2) for generalized linear mixed models in one go. Biometrical Journal, 65(7), 2200290. doi:10.1002/bimj.202200290.
See Also
asreml, estimateV.asreml.
Examples
## Not run: 
  data(Oats.dat)
  
  current.asr <- asreml(Yield ~ Nitrogen*Variety, 
                        random=~Blocks/Wplots,
                        data=Oats.dat)
  R2.adj.fix <- R2adj.asreml(current.asr)
  R2.adj.ran <- R2adj.asreml(current.asr, 
                             include.which.fixed = NULL, include.which.random = ~ .)
  R2.adj.tot <- R2adj.asreml(current.asr, include.which.random = ~ .)
  R2.adj.tot <- R2adj.asreml(current.asr, include.which.random = ~ Blocks)
  R2.adj.add <- R2adj.asreml(current.asr, include.which.fixed = ~ Nitrogen + Variety)
  R2.adj.int <- R2adj.asreml(current.asr, 
                             include.which.fixed = ~ . - (Nitrogen + Variety))
  R2.adj.int <- R2adj.asreml(current.asr, include.which.fixed = ~ Nitrogen:Variety)
## End(Not run)