Delta Method Standard Error Calculation
Contents |
transformed regression parameters in R using the delta method? The purpose of this page is to introduce estimation of delta method standard error of variance standard errors using the delta method. Examples include manual calculation of standard delta method standard error stata errors via the delta method and then confirmation using the function deltamethod so that the reader may understand standard error calculation excel the calculations and know how to use deltamethod. This page uses the following packages Make sure that you can load them before trying to run the examples on this page. standard error of mean calculation We will need the msm package to use the deltamethodfunction. If you do not have a package installed, run: install.packages("packagename"), or if you see the version is out of date, run: update.packages(). library(msm) Version info: Code for this page was tested in R version 3.1.1 (2014-07-10)
On: 2014-08-01
With: pequod 0.0-3; msm 1.4; phia 0.1-5; effects 3.0-0; colorspace
Standard Error Of Measurement Calculation
1.2-4; RColorBrewer 1.0-5; xtable 1.7-3; car 2.0-20; foreign 0.8-61; Hmisc 3.14-4; Formula 1.1-2; survival 2.37-7; lattice 0.20-29; mgcv 1.8-1; nlme 3.1-117; png 0.1-7; gridExtra 0.9.1; reshape2 1.4; ggplot2 1.0.0; vcd 1.3-1; rjson 0.2.14; RSQLite 0.11.4; DBI 0.2-7; knitr 1.6 Background to delta method Often in addition to reporting parameters fit by a model, we need to report some transformation of these parameters. The transformation can generate the point estimates of our desired values, but the standard errors of these point estimates are not so easily calculated. They can, however, be well approximated using the delta method. The delta method approximates the standard errors of transformations of random variable using a first-order Taylor approximation. Regression coefficients are themselves random variables, so we can use the delta method to approximate the standard errors of their transformations. Although the delta method is often appropriate to use with large samples, this page is by no means an endorsement of the use of the delta method over other methods to estimate standard errors, such as bootstrapping. Essentially, the delta method involves calculating th
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of
Standard Error Calculation In Regression
this site About Us Learn more about Stack Overflow the company Business Learn standard error calculation in r more about hiring developers or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ Cross standard error calculation without standard deviation Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute: Sign up Here's how http://www.ats.ucla.edu/stat/r/faq/deltamethod.htm it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to use delta method for standard errors of marginal effects? up vote 9 down vote favorite 6 I am interested in better understanding the delta method for approximating the standard errors of the average marginal effects of a regression model that includes http://stats.stackexchange.com/questions/122066/how-to-use-delta-method-for-standard-errors-of-marginal-effects an interaction term. I've looked at related questions under delta-method but none have provided quite what I'm looking for. Consider the following example data as a motivating example: set.seed(1) x1 <- rnorm(100) x2 <- rbinom(100,1,.5) y <- x1 + x2 + x1*x2 + rnorm(100) m <- lm(y ~ x1*x2) I am interested in the average marginal effects (AMEs) of x1 and x2. To calculate these, I simply do the following: cf <- summary(m)$coef me_x1 <- cf['x1',1] + cf['x1:x2',1]*x2 # MEs of x1 given x2 me_x2 <- cf['x2',1] + cf['x1:x2',1]*x1 # MEs of x2 given x1 mean(me_x1) # AME of x1 mean(me_x2) # AME of x2 But how do I use the delta method to calculate the standard errors of these AMEs? I can calculate the SE for this particular interaction by hand: v <- vcov(m) sqrt(v['x1','x1'] + (mean(x2)^2)*v['x1:x2','x1:x2'] + 2*mean(x2)*v['x1','x1:x2']) But I don't understand how to use the delta method. Ideally, I'm looking for some guidance on how to think about (and code) the delta method for AMEs of any arbitrary regression model. For example, this question provides a formula for the SE for a particular interaction effect and this document from
non-linear transformation * Stata do file * The Delta method can be used to estimate the standard errors after a regression estimation. * Imagine you have some parameter G = (3*b0-b1)*b2^2 http://www.econometricsbysimulation.com/2012/12/the-delta-method-to-estimate-standard.html = 3*b0*b2^2-b1*b2^2 * Where y = bo + b1*x1 + b2*x2 + u * The delta method can be used to estimate the standard errors of G. * The delta method states that var_hat(G)=(dG/db) var(b) (dG/db) * dG/db is a gradient vector: * dG/db = [dG/db0, dG/db1, dG/db2] * dG/db = [b2^2, -b2^2, 2*(b0-b1)*b2] * var_hat(G) = (3*b2^2)^2 * se(b0)^-2 standard error + (-b2^2)^2 * se(b1)^-2 + (2*(b0-b1)*b2)^2 * se(b2)^-2 [There is an error in the code because I failed to include a covariance term for the coefficients. Please see the more recent update on the method.] clear set obs 1000 gen x1 = rnormal() gen x2 = rnormal() * 4 global b0 = 1 global b1 = 1.5 global b2 = standard error calculation .3 local true_G = (3*${b0}-${b1})*${b2}^2 di `true_G' gen y = ${b0} + ${b1}*x1 + ${b2}*x2 + rnormal()*8 reg y x1 x2 * G = (3*b0-b1)*b2^2 = 3*b0*b2^2 - b1*b2^2 local Ghat = (3*_b[_cons]-_b[x1])*_b[x2]^2 di "Ghat = `Ghat' is our estimate (true = `true_G')" * Let's see if we can't use the delta method to derive a standard error. local var_hatG = (3*_b[x2]^2)^2 * _se[_cons]^2 + (-_b[x2]^2)^2 * _se[x1]^2 + (2*(_b[_cons]-_b[x1])*_b[x2])^2 * _se[x2]^2 di "Standard error estimate is " `var_hatG'^.5 * Alternatively, let us attempt to bootstrap our standard errors. cap program drop deltaOLS program define deltaOLS, rclass reg y x1 x2 return scalar Ghat = (3*_b[_cons]-_b[x1])*_b[x2]^2 end bs Ghat=r(Ghat), rep(500): deltaOLS * The bootstrap standard errors are similar to that of the delta method's standard errors. cap program drop deltaMonteCarlo program define deltaMonteCarlo, rclass clear set obs 1000 gen x1 = rnormal() gen x2 = rnormal() * 4 gen y = ${b0} + ${b1}*x1 + ${b2}*x2 + rnormal()*8 reg y x1 x2 return scalar Ghat = (3*_b[_cons]-_b[x1])*_b[x2]^2 end simulate Ghat=r(Gha