Estimating standard errors using the Delta Method in R


Vinh Nguyen


February 5, 2018

I just discovered the msm package in R that offers the deltamethod function for calculating the standard error of a transformation of estimated regression coefficients. A tutorial could be found here. I had to use it recently to calculate the standard error for a difference in proportions when logistic regression model was used to estimate the log-odds of an event:

fit <- glm(Response ~ treat, data=my_data, family=binomial(link='logit')) # treat is binary
diff <- 1/(1 + exp(-coef(fit)[1] - coef(fit)[2])) - 1/(1 + exp(-coef(fit)[1])) # difference in proportion
se.diff <- deltamethod(~ 1/(1 + exp(-x1 - x2)) - 1/(1 + exp(-x1)), coef(fit), vcov(fit)) # returns standard error