Skip to content

Instantly share code, notes, and snippets.

@apoorvalal
Created February 13, 2022 18:11
Show Gist options
  • Save apoorvalal/281e1112a9b26e45d410edea185ad49a to your computer and use it in GitHub Desktop.
Save apoorvalal/281e1112a9b26e45d410edea185ad49a to your computer and use it in GitHub Desktop.
Hypothesis testing on linear and nonlinear combinations of coefficients using the Delta method
# %%
library(car); library(sandwich)
m1 <- lm(time ~ t1 + t2, data = Transact)
m1 |> summary()
vcovmat = vcovHC(m1)
# %%
deltaMethod(m1, "t1/t2")
deltaMethod(m1, "t1/t2", vcov = vcovmat)
# %%
deltaMethod(m1, "t1+t2")
deltaMethod(m1, "t1+t2", vcov = vcovmat)
# %% binary
d <- read.csv("https://stats.idre.ucla.edu/stat/data/hsbdemo.csv")
d$honors <- factor(d$honors, levels=c("not enrolled", "enrolled"))
m3 <- glm(honors ~ female + math + read, data=d, family=binomial)
summary(m3)
vcovmat2 = vcovHC(m3)
# %%
deltaMethod(m3, "math/read")
deltaMethod(m3, "math/read", vcov = vcovmat2)
# %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment