if (FALSE) {
# Example with simulated data in which null hypothesis holds
n=2000
x=rnorm(n)
z1=rnorm(n)
z2=rnorm(n)
d=1*(0.5*x+0.5*z1+rnorm(n)>0) # Treatment equation
m=0.5*x+0.5*d+0.5*z2+rnorm(n) # Mediator equation
y=0.5*x+d+0.5*m+rnorm(n) # Outcome equation
# Run test and report p-value
testmedident(y=y, d=d, m=m, x=x, z1=z1, z2=z2)$pval
}
Run the code above in your browser using DataLab