TransWikia.com

Obtaining the complete confidence intervals of binary interacted variables

Cross Validated Asked by Arun on November 9, 2020

I have an OLS regression with a binary treatment X and a binary moderating variable M, where the regression equation is:

$$
Y = alpha + beta_1 X + beta_2 M + beta_3(X times M).
$$

The effect of $X$ on $Y$ is $beta_1$ when $M=0$ and $(beta_1 +beta_3)$ when $M=1$. How can I calculate the standard errors/confidence intervals of $(beta_1 +beta_3)$?

In the working example below, the estimated effects of $X$ on $Y$ are $144$ ($M=0$) and $185$ ($M=1$). While the standard error for $X$ if $M=0$ is $22.76$, I am a bit confused about how to calculate the standard error for $X$ on $Y$ given $M=1$.

set.seed(1)

X <- sample(0:1, 200, replace = T)
M <- sample(0:1, 200, replace = T)

# effect of X on Y is 150 if M==0 and 200 if M==1
Y <- 450 +  150 * X + 500 * M + 50 * (X * M) + rnorm(200, sd = 100)

summary(lm(Y ~ X + M + X*M))

Call:
lm(formula = Y ~ X + M + X * M)

Residuals:
     Min       1Q   Median       3Q      Max 
-285.362  -83.993   -6.954   82.133  267.919 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   441.38      16.01  27.569  < 2e-16 ***
X             144.49      22.76   6.347 1.49e-09 ***
M             508.27      22.52  22.566  < 2e-16 ***
X:M            40.22      31.20   1.289    0.199    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 109.8 on 196 degrees of freedom
Multiple R-squared:  0.8702,    Adjusted R-squared:  0.8682 
F-statistic: 437.8 on 3 and 196 DF,  p-value: < 2.2e-16

One Answer

Using Gaussian error propagation:

summary(fit <- lm(Y ~ X + M + X*M))

sigma2mat <- vcov(fit)[-c(1, 3), -c(1, 3)]

sum(coef(fit)[-c(1, 3)]) + c(-1.96, 1.96) * sqrt(sum(sigma2mat))
#[1] 147.3562 226.2858

Using bootstrapping:

library(boot)
DF <- data.frame(X, M, Y)
set.seed(42)
myboot <- boot(DF, function(DF, i) {
  fit <- lm(Y ~ X + M + X*M, data = DF[i,])
  sum(coef(fit)[-c(1, 3)])
}, 999)

boot.ci(myboot)
#Intervals : 
#Level      Normal              Basic         
#95%   (146.4, 226.5 )   (147.6, 226.3 )  
#
#Level     Percentile            BCa          
#95%   (147.3, 226.1 )   (143.2, 221.9 )  
#Calculations and Intervals on Original Scale

Correct answer by Roland on November 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP