Title: | Case-Wise and Cluster-Wise Derivatives for Mixed Effects Models |
---|---|
Description: | Compute case-wise and cluster-wise derivative for mixed effects models with respect to fixed effects parameter, random effect (co)variances, and residual variance. This material is partially based on work supported by the National Science Foundation under Grant Number 1460719. |
Authors: | Ting Wang [aut, cre], Edgar Merkle [aut] , Yves Rosseel [ctb] |
Maintainer: | Ting Wang <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2-5 |
Built: | 2024-11-19 05:41:43 UTC |
Source: | https://github.com/nctingwang/merderiv |
This function calculates the bread component of the Huber-White
sandwich estimator (variance covariance matrix multiplied by
the number of clusters) for a generalized linear mixed effects model
of class glmerMod
.
## S3 method for class 'glmerMod' bread(x, ...)
## S3 method for class 'glmerMod' bread(x, ...)
x |
An object of class |
... |
additional arguments,
including |
A p by p "bread" matrix for the Huber-White sandwich estimator
(variance-covariance matrix based on observed Fisher information
multiplied by the number of clusters), where
p represents the number of parameters.
If full = FALSE
, returns the
variance-covariance matrix of only fixed effect
parameters. If full = TRUE
, returns the variance-covariance matrix
for all fitted parameters (including fixed effect parameters,
random effect (co)variances, and residual variance.
If ranpar = "var"
, the random effects are parameterized as
variance/covariance; If ranpar = "sd"
, the random effects are
parameterized as standard deviation/correlation; If ranpar = "theta"
,
the random effects are parameterized as components of Cholesky
decomposition.
Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.
Zeileis, A. (2006). Object-Oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1-16. https://www.jstatsoft.org/v16/i09/
## Not run: # The cbpp example data(finance, package = "smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # bread component for all parameters bread(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)
## Not run: # The cbpp example data(finance, package = "smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # bread component for all parameters bread(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)
This function calculates the bread component of the Huber-White
sandwich estimator (variance covariance matrix multiplied by
the number of clusters) for a linear mixed effects model
of class lmerMod
.
## S3 method for class 'lmerMod' bread(x, ...)
## S3 method for class 'lmerMod' bread(x, ...)
x |
An object of class |
... |
additional arguments, including |
A p by p "bread" matrix for the Huber-White sandwich estimator
(variance-covariance matrix multiplied by the number of clusters), where
p represents the number of parameters.
If full = FALSE
, returns the
variance-covariance matrix of only fixed effect
parameters. If full = TRUE
, returns the variance-covariance matrix
for all fitted parameters (including fixed effect parameters,
random effect (co)variances, and residual variance.
If information = "expected"
, the variance-covariance matrix
is based on the inversion of Fisher information matrix.
If information = "observed"
, the variance-covariance matrix
is based on the observed Fisher information, which is the negative
of Hessian matrix. If ranpar = "var"
, the random effects are
parameterized as variance/covariance; If ranpar = "sd"
,
the random effects are parameterized as standard deviation/correlation.
Wang, T. & Merkle, E. C. (2018). Derivative Computations and Robust Standard Errors for Linear Mixed Effects Models in lme4. Journal of Statistical Software, 87(1), 1-16. doi:10.18637/jss.v087.c01
Zeileis, A. (2006). Object-Oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1-16. https://www.jstatsoft.org/v16/i09/
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # bread component for all parameters bread(lme4fit, full = TRUE, information = "expected", ranpar = "var") ## End(Not run)
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # bread component for all parameters bread(lme4fit, full = TRUE, information = "expected", ranpar = "var") ## End(Not run)
A function for extracting the cluster-wise derivatives of a generalized linear mixed effects models fitted via lme4. This function returns the cluster-wise scores, evaluated at the ML estimates.
## S3 method for class 'glmerMod' estfun(x, ...)
## S3 method for class 'glmerMod' estfun(x, ...)
x |
An object of class |
... |
Additional arguments, including |
.
A g by p score matrix, corresponding to
g clusters and p parameters.
For models with multiple clustering variables (three-level models,
crossed random effects), an error is thrown.
If ranpar = "var"
, the random effects are parameterized as
variance/covariance; If ranpar = "sd"
, the random effects are
parameterized as standard deviation/correlation; If ranpar = "theta"
,
the random effects are parameterized as components of Cholesky decomposition.
Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.
## Not run: data(finance, package = "smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # clusterwise scores estfun(lme4fit, ranpar = "var") ## End(Not run)
## Not run: data(finance, package = "smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # clusterwise scores estfun(lme4fit, ranpar = "var") ## End(Not run)
A function for extracting the case-wise and cluster-wise derivatives of a linear mixed effects models fitted via lme4. This function returns the case-wise and cluster-wise scores, evaluated at the ML estimates.
## S3 method for class 'lmerMod' estfun(x, ...)
## S3 method for class 'lmerMod' estfun(x, ...)
x |
An object of class |
... |
additional arguments, including |
If level = 2
, a g by p score matrix, corresponding to
g clusters and p parameters. If level = 1
, a n by
p score matrix, corresponding to
n observations and p parameters.
For models with multiple clustering variables (three-level models,
crossed random effects), an error is thrown if level = 2
.
If ranpar = "var"
, the random effects are parameterized as
variance/covariance; If ranpar = "sd"
, the random effects are
parameterized as standard deviation/correlation.
Wang, T. & Merkle, E. C. (2018). Derivative Computations and Robust Standard Errors for Linear Mixed Effects Models in lme4. Journal of Statistical Software, 87(1), 1-16. doi:10.18637/jss.v087.c01
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # casewise scores estfun(lme4fit, level = 1, ranpar = "var") # clusterwise scores estfun(lme4fit, level = 2, ranpar = "sd") ## End(Not run)
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # casewise scores estfun(lme4fit, level = 1, ranpar = "var") # clusterwise scores estfun(lme4fit, level = 2, ranpar = "sd") ## End(Not run)
A function for extracting the cluster-wise log likelihoods of a generalized linear mixed effects model fitted via lme4. This function returns the cluster-wise log likelihoods, evaluated at the ML estimates.
## S3 method for class 'glmerMod' llcont(x, ...)
## S3 method for class 'glmerMod' llcont(x, ...)
x |
An object of class |
... |
Additional arguments. |
A vector of log-likelihoods whose length is the number of clusters.
Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.
Merkle, E. C., You, D. and Preacher, K. J., 2016. Testing Nonnested Structural Equation Models. Psychological Methods, 21(2), 151. https://arxiv.org/pdf/1402.6720v3
## Not run: data(finance, package="smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # clusterwise log likelihood llcont(lme4fit) ## End(Not run)
## Not run: data(finance, package="smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # clusterwise log likelihood llcont(lme4fit) ## End(Not run)
A function for extracting the case-wise log likelihoods of a linear mixed effects model fitted via lme4. This function returns the case-wise log likelihoods, evaluated at the ML estimates.
## S3 method for class 'lmerMod' llcont(x, ...)
## S3 method for class 'lmerMod' llcont(x, ...)
x |
An object of class |
... |
additional arguments, including |
If level = 2
, a vector of log-likelihoods whose length is
the number of clusters. If level = 1
, a vector of length n,
containing log-likelihoods for all n observations.
Wang, T. & Merkle, E. C. (2018). Derivative Computations and Robust Standard Errors for Linear Mixed Effects Models in lme4. Journal of Statistical Software, 87(1), 1-16. doi:10.18637/jss.v087.c01
Merkle, E. C., You, D. and Preacher, K. J., 2016. Testing Nonnested Structural Equation Models. Psychological Methods, 21(2), 151. https://arxiv.org/pdf/1402.6720v3
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # clusterwise log likelihood llcont(lme4fit) ## End(Not run)
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # clusterwise log likelihood llcont(lme4fit) ## End(Not run)
This function calculates the variance-covariance
matrix for all parameters (fixed and random effect) in a generalized linear
mixed effects model of class glmerMod
.
## S3 method for class 'glmerMod' vcov(object, ...)
## S3 method for class 'glmerMod' vcov(object, ...)
object |
An object of class |
... |
additional arguments, including |
A p by p variance-covariance matrix, where p
represents the number of parameters.
If full = FALSE
, returns the
variance-covariance matrix of only fixed effect
parameters. If full = TRUE
, returns the variance-covariance matrix
for all fitted parameters (including fixed effect parameters and random
effect (co)variances). The variance-covariance matrix
is based on the negative of Hessian matrix, which is extracted from
lme4
. If ranpar = "var"
, the random effects are
parameterized as variance/covariance; If ranpar = "sd"
,
the random effects are parameterized as standard
deviation/correlation; If ranpar = "theta"
,
the random effects are parameterized as components of Cholesky decomposition.
Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.
## Not run: # The cbpp example data(finance, package="smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # variance covariance matrix for all parameters vcov(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)
## Not run: # The cbpp example data(finance, package="smdata") lme4fit <- glmer(corr ~ jmeth + (1 | item), data = finance, family = binomial, nAGQ = 20) # variance covariance matrix for all parameters vcov(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)
This function calculates the variance-covariance
matrix for all parameters (fixed, random effect, and residual) in a linear
mixed effects model of class lmerMod
.
## S3 method for class 'lmerMod' vcov(object, ...)
## S3 method for class 'lmerMod' vcov(object, ...)
object |
An object of class |
... |
additional arguments, including |
A p by p variance-covariance matrix, where p
represents the number of parameters.
If full = FALSE
, returns the
variance-covariance matrix of only fixed effect
parameters. If full = TRUE
, returns the variance-covariance matrix
for all fitted parameters (including fixed effect parameters,
random effect (co)variances, and residual variance.
If information = "expected"
, the variance-covariance matrix
is based on the inversion of Fisher information matrix.
If information = "observed"
, the variance-covariance matrix
is based on the observed Fisher information, which is the negative
of Hessian matrix. If ranpar = "var"
, the random effects are
parameterized as variance/covariance; If ranpar = "sd"
,
the random effects are parameterized as standard deviation/correlation.
Wang, T. & Merkle, E. C. (2018). Derivative Computations and Robust Standard Errors for Linear Mixed Effects Models in lme4. Journal of Statistical Software, 87(1), 1-16. doi:10.18637/jss.v087.c01
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # variance covariance matrix for all parameters vcov(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)
## Not run: # The sleepstudy example lme4fit <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy, REML = FALSE) # variance covariance matrix for all parameters vcov(lme4fit, full = TRUE, ranpar = "var") ## End(Not run)