1

I used the delta method to estimate the difference between two coefficients from a glm fit (attached code below). Now, I want to compare this estimate to zero (i.e., a null hypothesis of no difference). One article mentions using a one-sample location, two-way approximate Z test to compute this difference.

However, I cannot find an easy way to do that in R using the delta difference. I looked over the two-sample Z test documentation and possibly thought of using the difference as a substitute in the z-stat formula...but I am not sure if that's the best way to go about it.

##GENERATE DATA SET
y <- c(1:12)
x1 <- rep(c(1000, 4000, 0), each = 4)
x2 <- rep(c(0, 1000, 4000), each = 4)
df <- data.frame(y, x1, x2)

##RUN GLM
library(lmerTest)
g1 <- glm(log(y) ~ x1 + x2, data = df)

##Use delta-method to estimate the difference between coefficients of x1 and x2 (Ritz & Streibig 2008)
library(car)
g1.delta <- deltaMethod(g1,"(-x1) - (-x2)")


              Estimate   SE         2.5 %       97.5 % 
(-x1) - (-x2) 2.3217e-04 7.3180e-05 8.8738e-05  4e-04
Rspacer
  • 2,369
  • 1
  • 14
  • 40
  • 2
    You have an estimate of the mean difference and its standard error. Divide the former by the latter and use `qnorm` to derive the corresponding p-value. The quoted (central, two-sided 95%) CI provides a sanity check. – Limey Jan 11 '22 at 13:16
  • @Limey Thanks for the suggestion. But it seems like you need to provide qnorm a vector to compute the p-value. I tried `qnorm(qnorm(g1.delta[1,1]/g1.delta[1,2]))` but it simply produced NaNs. – Rspacer Jan 11 '22 at 14:39
  • 2
    Why the nested `qnorms`? And there's a typo in my comment. Apologies. You need `pnorm` for the p-value: `2*(1 - pnorm(abs(2.3217E-04/7.318E-05))` is the two sided p-value (0.0015). The lower limit of the CI is obtained as `2.3217E-04 - (qnorm(1-0.025) * 7.318E-05)` (8.873E-05, as in your output). The lower limit of the CI is above zero, so your p-value should be less that 0.05, which it is. – Limey Jan 11 '22 at 15:24
  • 2
    @Limey, please post as an answer ... – Ben Bolker Jan 11 '22 at 18:48

0 Answers0