mat.random {dae} | R Documentation |
Calculates the variance matrix for the random effects from a mixed model, based on a supplied formula or a matrix.
Description
For n
observations, compute the variance matrix of the random effects.
The matrix
can be specified using a formula
for the random
effects and a list
of values of the
variance components for the terms specified in the random
formula
.
If a matrix
specifying the variances of
the nuisance random effects is supplied then it is returned as the value
from the function.
Usage
mat.random(random, G, design, keep.order = TRUE)
Arguments
random |
A |
G |
This term only needs to be set if |
design |
A |
keep.order |
A |
Details
If \bold{Z}_i
is the is incidence matrix for the random
nuisance effects
in \bold{u}_i
for a term in random
and \bold{u}_i
has
variance matrix \bold{G}_i
so that the contribution of the random effectst to
the variance matrix for \bold{Y}
is
\bold{V}_u = \Sigma (\bold{Z}_i\bold{G}_i(\bold{Z}_i)^T)
.
Value
A n x n
matrix
containing the variance matrix for the random effects.
Author(s)
Chris Brien
See Also
Examples
## Reduced example from Smith et al. (2015)
## Generate two-phase design
mill.fac <- fac.gen(list(Mrep = 2, Mday = 2, Mord = 3))
field.lay <- fac.gen(list(Frep = 2, Fplot = 4))
field.lay$Variety <- factor(c("D","E","Y","W","G","D","E","M"),
levels = c("Y","W","G","M","D","E"))
start.design <- cbind(mill.fac, field.lay[c(3,4,5,8,1,7,3,4,5,8,6,2),])
rownames(start.design) <- NULL
## Set gammas
terms <- c("Variety", "Frep", "Frep:Fplot", "Mrep", "Mrep:Mday", "Mrep:Mday:Mord")
gammas <- c(1, 0.1, 0.2, 0.3, 0.2, 1)
names(gammas) <- terms
## Specify matrices to calculate the variance matrix of the predicted fixed Variety effects
Vu <- with(start.design, fac.vcmat(Mrep, gammas["Mrep"]) +
fac.vcmat(fac.combine(list(Mrep,Mday)), gammas["Mrep:Mday"]) +
fac.vcmat(Frep, gammas["Frep"]) +
fac.vcmat(fac.combine(list(Frep,Fplot)), gammas["Frep:Fplot"]))
## Calculate the variance matrix of the predicted random Variety effects using formulae
Vu <- mat.random(random = ~ -1 + Mrep/Mday + Frep/Fplot,
G = as.list(gammas[c(4,5,2,3)]),
design = start.design)