Delta method for approximating the standard error of a transformation g(X) of a random variable X = (x1, x2, …), given estimates of the mean and covariance matrix of X.
A formula representing the transformation. The variables must
If the transformation returns a vector, then a list of formulae representing (g1, g2, …) can be provided, for example
The estimated mean of X
The estimated covariance matrix of X
The delta method expands a differentiable function of a random variable about its mean, usually with a first-order Taylor approximation, and then takes the variance. For example, an approximation to the covariance matrix of g(X) is given by
Cov(g(X)) = g'(mu) Cov(X) [g'(mu)]^T
where mu is an estimate of the mean of X. This
function uses symbolic differentiation via
A limitation of this function is that variables created by the user
are not visible within the formula
g. To work around this, it
is necessary to build the formula as a string, using functions such as
sprintf, then to convert the string to a formula using
as.formula. See the example below.
If you can spare the computational time, bootstrapping is a more
accurate method of calculating confidence intervals or standard errors
for transformations of parameters. See
Simulation from the asymptotic distribution of the MLEs (see e.g. Mandel 2013)
is also a convenient alternative.
A vector containing the standard errors of g1(X), g2(X), … or a matrix containing the covariance of g(X).
C. H. Jackson [email protected]
Oehlert, G. W. (1992) A note on the delta method. American Statistician 46(1).
Mandel, M. (2013) Simulation based confidence intervals for functions with complicated derivatives. The American Statistician 67(2):76-81.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
## Simple linear regression, E(y) = alpha + beta x x <- 1:100 y <- rnorm(100, 4*x, 5) toy.lm <- lm(y ~ x) estmean <- coef(toy.lm) estvar <- summary(toy.lm)$cov.unscaled * summary(toy.lm)$sigma^2 ## Estimate of (1 / (alphahat + betahat)) 1 / (estmean + estmean) ## Approximate standard error deltamethod (~ 1 / (x1 + x2), estmean, estvar) ## We have a variable z we would like to use within the formula. z <- 1 ## deltamethod (~ z / (x1 + x2), estmean, estvar) will not work. ## Instead, build up the formula as a string, and convert to a formula. form <- sprintf("~ %f / (x1 + x2)", z) form deltamethod(as.formula(form), estmean, estvar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.