Estimating standard errors using the Delta Method in R

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

About Vinh Nguyen


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>