Skip to content

Instantly share code, notes, and snippets.

@tslumley
Created August 29, 2015 08:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tslumley/6d3aeb0a8148c0f03028 to your computer and use it in GitHub Desktop.
one.nri<-function(N=1000){
x<-rnorm(50)
y<-rbinom(50,1,x/10+0.5)
z<-rnorm(50)
m_old<-lm(y~x)
m_new<-lm(y~x+z)
x<-rnorm(N)
y<-rbinom(N,1,x/10+0.5)
z<-rnorm(N)
p_old<-cbind(1,x)%*%coef(m_old)
p_new<-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