Created
February 13, 2022 18:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# %% | |
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