Description Usage Arguments Value Functions Author(s) Examples
Fit and setup functions for linear mixed-effect model (Gaussian responses).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | gremlin(
formula,
random = NULL,
rcov = ~units,
data = NULL,
ginverse = NULL,
Gstart = NULL,
Rstart = NULL,
Bp = NULL,
Gcon = NULL,
Rcon = NULL,
maxit = 20,
algit = NULL,
vit = 1,
v = 1,
control = gremlinControl(),
...
)
gremlinR(
formula,
random = NULL,
rcov = ~units,
data = NULL,
ginverse = NULL,
Gstart = NULL,
Rstart = NULL,
Bp = NULL,
Gcon = NULL,
Rcon = NULL,
maxit = 20,
algit = NULL,
vit = 1,
v = 1,
control = gremlinControl(),
...
)
## S3 method for class 'gremlin'
getCall(x, ...)
## S3 method for class 'gremlin'
update(object, ...)
gremlinSetup(
formula,
random = NULL,
rcov = ~units,
data = NULL,
ginverse = NULL,
Gstart = NULL,
Rstart = NULL,
Bp = NULL,
Gcon = NULL,
Rcon = NULL,
maxit = 20,
algit = NULL,
vit = 1,
v = 1,
control = gremlinControl(),
...
)
## S3 method for class 'gremlin'
is(x)
## S3 method for class 'grMod'
is(x)
mkModMats(
formula,
random = NULL,
rcov = ~units,
data = NULL,
subset = NULL,
ginverse = NULL,
na.action = na.pass,
offset = NULL,
contrasts = NULL,
Xsparse = TRUE,
...
)
|
formula |
A |
random |
A |
rcov |
A |
data |
A |
ginverse |
A |
Gstart |
A |
Rstart |
A |
Bp |
A prior specification for fixed effects. |
Gcon, Rcon |
A |
maxit |
An |
algit |
A |
vit |
An |
v |
An |
control |
A |
... |
Additional arguments to be passed to control the model fitting. |
x, object |
An object of class |
subset |
An expression for the subset of |
na.action |
What to do with NAs. |
offset |
Should an offset be specified. |
contrasts |
Specify the type of contrasts for the fixed effects. |
Xsparse |
Should sparse matrices be used for the fixed effects design matrix. |
A list
containing an object of class grMod
and, if a
model was fit (gremlin
or gremlinR
) then an object containing
details of the REML iterations (object itMat
). An object of class
grMod
contains:
The model call
.
A list
of the model matrices used to construct the
mixed model equations.
The response vector.
The number of responses.
The number of columns of the original response.
The fixed effects design matrix.
The number of columns in X.
The residual design matrix.
A list of the design matrices for each random term.
The number of parameters in the G structure.
A list of generalized inverse matrices.
The log-determinants of the generalized inverse matrices - necessary to calculate the log-likelihood.
A numeric
value containing the sum
of the log determinants of the random effects that do not change between
log-likelihood iterations (i.e., the part of the log determinants of
(co)variance matrices to be estimated that have been factored out).
A logical
indicating which terms in the random
formula have generalized inverses associated with them (non-diagonal
matrices in the Kronecker product.
Numeric
vectors or scalars
describing the numbers of random effects or some function of random and
fixed effects.
(Co)variance component constraints and boundaries of the allowable parameter space for each component.
A vector
of the (co)variance parameters to
be estimated by REML withe the attribute “skel” giving the
skeleton to recreate a list of matrices
from this vector.
Vectors
indexing the random and residual
(co)variances, respectively, in a list of (co)variance matrices (i.e.,
theta
).
A list
of transformed (co)variance matrices
to be fit by REML. If a residual variance has been factored out of the
mixed model equations, nu
contains the ‘lambda’
parameterization with expresses the (co)variance components as ratios
of variance parameters with the residual variance. The ‘nu’ scale
(co)variances are the ones actually fit by REML.
The estimate of the factored out residual variance from the mixed model equations (i.e., the ‘lambda’ scale) σ^{2}_{e}.
An integer
for the total number of (co)variances to be
estimated.
A logical
indicating whether the ‘lambda’
scale parameterization has been used.
A logical
to indicate if the model is univariate or not.
Sparse matrices of class Matrix
that
form the mixed model equations and do not change between iterations of
REML. These are the column binded ‘X’ and ‘Z’ design
matrices for fixed and random effects, the cross-product of W
,
the Right-Hand Side of the mixed model equations, and the inverse of
the fixed effect prior matrix (zeroes on the diagonal if no priors have
been specified). Note, these may be NULL
if lambda=FALSE
,
because the NULL
objects are not used or do change between
REML iterations.
A Matrix
containing the symbolic Cholesky factorization
of the coefficient matrix of the Mixed Model Equations.
A one column matrix
of solutions in the mixed model
equations.
A one column matrix
of variances for the solutions
to the mixed model equations. These are obtained from the diagonal of
the inverse Coefficient matrix in the mixed model equations. If lambda
is TRUE
then these are on the lambda scale and must be
multiplied by sigma2e
to be converted to the original data scale.
A one column matrix
of residual deviations, response minus
the values expected based on the solutions, corresponding to the order
in modMats$y
.
A matrix
of values containing the Average Information
matrix, or second partial derivatives of the likelihood with respect to
the transformed (co)variance components (‘nu’). The inverse of
this matrix gives the sampling (co)variances of these transformed
(co)variance components.
A single column matrix
of first derivatives of
the transformed (co)variance parameters (‘nu’) with respect to
the log-Likelihood.
See the parameter described above.
A character
vector of REML algorithms to use in each
iteration.
See the parameter described above.
See the parameter described above.
A numeric
vector of convergence criteria thresholds.
See gremlinControl
for more details.
numeric
values for the effective numbers to
use as “zero” and maximum negative or positive numbers. Values
less than ezero
are treated as zero and fixed to this value.
Values less than -1*einf
or greater than einf
are
restricted to these values. See gremlinControl
for more
details.
A numeric
value indicating the step-reduction to use.
See gremlinControl
for more details.
A matrix
of details about each iteration. Rows
indicate each REML iteration (rownames reflect the REML algorithm used)
and columns contain:
(Co)variance parameters.
See ‘sigma2e’ described above.
Estimates for two these two components of the log of the REML likelihoods. These are obtained from Cholesky factorization of the coefficient matrix of the mixed model equations.
The REML log-likelihood.
Time elapsed for each REML iteration.
mkModMats
: Generates model matrices.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | grSire <- gremlin(WWG11 ~ sex, random = ~ sire, data = Mrode11)
# Now drop sire random effects and use the `anova` method to compare models
grLM <- update(grSire, random = ~ 1) #<-- use `~1` to drop all random effects
anova(grSire, grLM)
# Modular functions
## get model matrices for a mixed model
mM11 <- mkModMats(WWG11 ~ sex - 1, random = ~ sire, data = Mrode11)
## setup model, but do not evaluate the log-likelihood
grSetup <- gremlinSetup(WWG11 ~ sex - 1, random = ~ sire, data = Mrode11)
## maximize the restricted maximum likelihood
grOut <- remlIt(grSetup)
summary(grOut)
## Not run:
# Following the example from Mrode 2005, chapter 11.
library(nadiv) #<-- to construct inverse of the numerator relatedness matrix
Ainv <- makeAinv(Mrode11[, 1:3])$Ainv
gr11lmm <- gremlin(WWG11 ~ sex - 1,
random = ~ calf,
data = Mrode11,
ginverse = list(calf = Ainv),
Gstart = matrix(0.2), Rstart = matrix(0.4), #<-- specify starting values
maxit = 15, #<-- maximum iterations
v = 2, vit = 1, #<-- moderate screen output (`v`) every iteration (`vit`)
algit = "AI") #<-- only use Average Information algorithm iterations
summary(gr11lmm)
# Compare the model to a Linear Model with no random effects
## Use `update()` to update the model
gr11lm <- update(gr11lmm, random = ~ 1) #<-- `~1`=drop all random effects
summary(gr11lm)
# Do analysis of variance between the two models
## See AIC or evaluate likelihood ratio against a Chi-squared distribution
anova(gr11lm, gr11lmm)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.