0
$\begingroup$

I created three variables in r using this code

set.seed(111)  
n = 10^6
trials = 1
intercept = -2

# confounder variable 
C = rbinom(n, trials, 0.5)
# exposure variable
X = rbinom(n, trials, inv.logit(intercept + 0.2*C))
# outcome variable
Y = rbinom(n, trials, inv.logit(intercept + 1.5*C + 2*X))

# create dataset
dset = data.frame(X, C, Y) 

# run models
summary(glm(Y~X+C, family = binomial, data=dset))

Coefficients Estimates: (Intercept)= -2.008271 X= 2.003713 C= 1.505544

summary(glm(Y~X, family = binomial, data=dset))

Coefficients Estimates: (Intercept)= -1.119542 X= 1.837607

summary(glm(X~C, family = binomial, data=dset))

Coefficients Estimates: (Intercept)= -1.998233 C= 0.198238

When I used inv.logit i.e. the logistic to set the probability, I thought the variables were created such that the values and effects were as follows:

enter image description here

But I am not sure if this is the correct way to think about this. I can reproduce the ORs from the data by hand, so they are fine. Additionally, my main interest of this is to try and understand what the true theoretical effect should be for the glm that does not contain C i.e. Y~X. The regression shows that the intercept would be around 1.12 with X being around 1.84 but I cannot find how to get there using the logistic, logit or odds. If I look at the effect of C on X I can reproduce the values I set there with the regression and theoretically i.e. Intercept is the same as above and then

enter image description here

So the effect of C on X is -1.8 - -2=0.2

Any help is appreciated.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.