DeltaMethod {mirt} | R Documentation |
Numerical derivative version of delta method
Description
Delta method using numerical derivatives
(via numerical_deriv
) for the provided function.
Convenient when target transformation function is
easier to automate programmatically
instead of using explicit formula or math expressions. Can
also be useful for checking analytic results.
Usage
DeltaMethod(fn, par, acov, ...)
Arguments
fn |
a function specifying the type of
transformation to make for each new parameter of interest.
Must be of the form |
par |
numerical vector passed to |
acov |
numeric matrix for the ACOV of the MLEs |
... |
additional arguments passed to fn |
Value
returns a list of the transformed parameters, ACOV, and SEs
Examples
# Slightly modified example from ?msm::deltamethod
# Multiple linear regression, E(y) = alpha + beta1 x + beta2 g
x <- 1:100
g <- rep(0:1, each=50)
y <- rnorm(100, 4*x, 5)
toy.lm <- lm(y ~ x + g)
estmean <- coef(toy.lm)
estvar <- vcov(toy.lm)
# Estimate of (1 / (b0 + b1)) and (1 / (b0 + b1 + b2))
1 / (estmean[1] + estmean[2])
1 / (estmean[1] + estmean[2] + estmean[3])
## Approximate standard error (uncomment to check)
# msm::deltamethod (~ 1 / (x1 + x2), estmean, estvar)
# msm::deltamethod (~ 1 / (x1 + x2 + x3), estmean, estvar)
# with DeltaMethod
fn <- function(par) 1 / sum(par[1:2])
fn2 <- function(par) 1 / sum(par[1:3])
DeltaMethod(fn, estmean, estvar)$se
DeltaMethod(fn2, estmean, estvar)$se
# index argument for easier flexibility
fn <- function(par, index) 1 / sum(par[index])
DeltaMethod(fn, estmean, estvar, index=1:2)$se
DeltaMethod(fn, estmean, estvar, index=1:3)$se
[Package mirt version 1.44.0 Index]