Created
August 29, 2015 08:20
-
-
Save tslumley/77d3653b5a43fc129d15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
expit<-function(eta) exp(eta)/(1+exp(eta)) | |
one.nri<-function(N=1000){ | |
x<-rnorm(50) | |
y<-rbinom(50,1,expit(x)) | |
z<-rnorm(50) | |
m_old<-glm(y~x,family=binomial()) | |
m_new<-glm(y~x+z,family=binomial()) | |
x<-rnorm(N) | |
y<-rbinom(N,1,expit(x)) | |
z<-rnorm(N) | |
p_old<-expit(cbind(1,x)%*%coef(m_old)) | |
p_new<-expit(cbind(1,x,z)%*%coef(m_new)) | |
mean((p_new>p_old)[y==1])-mean((p_new>p_old)[y==0]) | |
} | |
r<-replicate(1000,one.nri()) | |
summary(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment