| gremlin {gremlin} | R Documentation |
Mixed-effect modeling functions.
Description
Fit and setup functions for linear mixed-effect model (Gaussian responses).
Usage
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,
...
)
Arguments
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. |
Value
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:
- call
The model
call.- modMats
A
listof the model matrices used to construct the mixed model equations.- y
The response vector.
- ny
The number of responses.
- ncy
The number of columns of the original response.
- X
The fixed effects design matrix.
- nb
The number of columns in X.
- Zr
The residual design matrix.
- Zg
A list of the design matrices for each random term.
- nG
The number of parameters in the G structure.
- listGeninv
A list of generalized inverse matrices.
- logDetG
The log-determinants of the generalized inverse matrices - necessary to calculate the log-likelihood.
- rfxIncContrib2loglik
A
numericvalue 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).- ndgeninv
A
logicalindicating which terms in the random formula have generalized inverses associated with them (non-diagonal matrices in the Kronecker product.- dimsZg, nminffx, rfxlvls, nminfrfx
Numericvectors or scalars describing the numbers of random effects or some function of random and fixed effects.- conv, bounds
(Co)variance component constraints and boundaries of the allowable parameter space for each component.
- thetav
A
vectorof the (co)variance parameters to be estimated by REML withe the attribute “skel” giving the skeleton to recreate a list ofmatricesfrom this vector.- thetaG, thetaR
Vectorsindexing the random and residual (co)variances, respectively, in a list of (co)variance matrices (i.e.,theta).- nu
A
listof transformed (co)variance matrices to be fit by REML. If a residual variance has been factored out of the mixed model equations,nucontains 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.- sigma2e
The estimate of the factored out residual variance from the mixed model equations (i.e., the ‘lambda’ scale)
\sigma^{2}_{e}.- p
An
integerfor the total number of (co)variances to be estimated.- lambda
A
logicalindicating whether the ‘lambda’ scale parameterization has been used.- uni
A
logicalto indicate if the model is univariate or not.- W, tWW, RHS, Bpinv
Sparse matrices of class
Matrixthat 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 ofW, 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 beNULLiflambda=FALSE, because theNULLobjects are not used or do change between REML iterations.- sLc
A
Matrixcontaining the symbolic Cholesky factorization of the coefficient matrix of the Mixed Model Equations.- sln
A one column
matrixof solutions in the mixed model equations.- Cinv_ii
A one column
matrixof 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 isTRUEthen these are on the lambda scale and must be multiplied bysigma2eto be converted to the original data scale.- r
A one column
matrixof residual deviations, response minus the values expected based on the solutions, corresponding to the order inmodMats$y.- AI
A
matrixof 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.- dLdnu
A single column
matrixof first derivatives of the transformed (co)variance parameters (‘nu’) with respect to the log-Likelihood.- maxit
See the parameter described above.
- algit
A
charactervector of REML algorithms to use in each iteration.- vit
See the parameter described above.
- v
See the parameter described above.
- cctol
A
numericvector of convergence criteria thresholds. SeegremlinControlfor more details.- ezero, einf
numericvalues for the effective numbers to use as “zero” and maximum negative or positive numbers. Values less thanezeroare treated as zero and fixed to this value. Values less than-1*einfor greater thaneinfare restricted to these values. SeegremlinControlfor more details.- step
A
numericvalue indicating the step-reduction to use. SeegremlinControlfor more details.- itMat
A
matrixof details about each iteration. Rows indicate each REML iteration (rownames reflect the REML algorithm used) and columns contain:- nu, theta
(Co)variance parameters.
- sigma2e
See ‘sigma2e’ described above.
- tyPy, logDetC
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.
- loglik
The REML log-likelihood.
- itTime
Time elapsed for each REML iteration.
Functions
-
mkModMats: Generates model matrices.
Author(s)
Examples
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)