# estimate.lmm: Delta Method for Mixed Models In LMMstar: Repeated Measurement Models for Discrete Times

 estimate.lmm R Documentation

## Delta Method for Mixed Models

### Description

Perform a first order delta method

### Usage

``````## S3 method for class 'lmm'
estimate(
x,
f,
df = !is.null(x\$df),
robust = FALSE,
type.information = NULL,
level = 0.95,
method.numDeriv = NULL,
average = FALSE,
transform.sigma = NULL,
transform.k = NULL,
transform.rho = NULL,
...
)
``````

### Arguments

 `x` a `lmm` object. `f` [function] function of the model coefficient computing the parameter(s) of interest. Can accept extra-arguments. `df` [logical] Should degree of freedom, computed using Satterthwaite approximation, for the parameter of interest be output. `robust` [logical] Should robust standard errors (aka sandwich estimator) be output instead of the model-based standard errors. `type.information` [character] Should the expected information be used (i.e. minus the expected second derivative) or the observed inforamtion (i.e. minus the second derivative). `level` [numeric,0-1] the confidence level of the confidence intervals. `method.numDeriv` [character] method used to approximate the gradient: either `"simple"` or `"Richardson"`. Passed to `numDeriv::jacobian`. `average` [logical] is the estimand the average output of argument `f`? Otherwise consider each individual output of argument `f`. `transform.sigma` [character] Transformation used on the variance coefficient for the reference level. One of `"none"`, `"log"`, `"square"`, `"logsquare"` - see details. `transform.k` [character] Transformation used on the variance coefficients relative to the other levels. One of `"none"`, `"log"`, `"square"`, `"logsquare"`, `"sd"`, `"logsd"`, `"var"`, `"logvar"` - see details. `transform.rho` [character] Transformation used on the correlation coefficients. One of `"none"`, `"atanh"`, `"cov"` - see details. `...` extra arguments passed to `f`.

### Examples

``````if(require(lava) && require(nlme)){

#### Random effect ####
set.seed(10)
dL <- sampleRem(1e2, n.times = 3, format = "long")
e.lmm1 <- lmm(Y ~ X1+X2+X3 + (1|id), repetition = ~visit|id, data = dL)
nlme::ranef(e.lmm1)
e.ranef <- estimate(e.lmm1, f  = function(p){nlme::ranef(e.lmm1, p = p)\$estimate})
e.ranef

if(require(ggplot2)){
df.gg <- cbind(index = 1:NROW(e.ranef), e.ranef)
gg.ranef <- ggplot(df.gg, aes(x = index, y=estimate, ymin=lower, ymax = upper))
gg.ranef + geom_point() + geom_errorbar() + ylab("estimated random effect") + xlab("id")
}

#### ANCOVA via mixed model ####
set.seed(10)
d <- sampleRem(1e2, n.time = 2)
e.ANCOVA1 <- lm(Y2~Y1+X1, data = d)

if(require(reshape2)){
dL2 <- melt(d, id.vars = c("id","Y1","X1"),  measure.vars = c("Y1","Y2"))
e.lmm <- lmm(value ~ variable + variable:X1, data = dL2, repetition = ~variable|id)

e.delta <- estimate(e.lmm, function(p){
c(Y1 = p["rho(Y1,Y2)"]*p["k.Y2"],
X1 = p["variableY2:X1"]-p["k.Y2"]*p["rho(Y1,Y2)"]*p["variableY1:X1"])
})
## same estimate and similar standard errors.
e.delta
summary(e.ANCOVA1)\$coef
## Degrees of freedom are a bit off though
}

}
``````

LMMstar documentation built on Nov. 9, 2023, 1:06 a.m.