# 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


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

## Related Questions

### How do betting sites update odds during a sporting match in real-time?

1  Asked on December 13, 2020 by svexo

### How to interpret the negative variances

1  Asked on December 12, 2020 by aakash-bashyal

### How to interpret balances after ILR transform for compositional data?

0  Asked on December 12, 2020 by samme-galanakis

### Specifying specific priors for a correlation matrix via Stan

1  Asked on December 11, 2020 by sue-doh-nimh

### Example of mean independent variables but dependent still

0  Asked on December 11, 2020 by luchonacho

### When are observations not weakly exchangeable?

1  Asked on December 11, 2020 by rumtscho

### How big should my subsample be?

1  Asked on December 11, 2020 by kaecvtionr

### Spirtes’ example of d-separation not leading to independence in a directed cyclic graph with non-linear structural equations

1  Asked on December 10, 2020 by quant_dev

### Asymptotic normality for nonsmooth objective functions

1  Asked on December 10, 2020

### Regression: is it wrong to bin a continuous variable to overcome overfitting?

1  Asked on December 10, 2020 by st4co4

### How do you compare standard deviations?

2  Asked on December 10, 2020 by yaynikkiprograms

### How to interpret the beta estimates of a generalized linear model with a square root power link?

0  Asked on December 10, 2020 by statboy_41

### Can k-fold CV help reduce sampling bias?

0  Asked on December 9, 2020 by aite97

### Why is the standard deviation of the average of averages smaller than the standard deviation of the total?

0  Asked on December 9, 2020 by pinocchio

### Calculating bias of ML estimate of AR(1) coefficient

1  Asked on December 9, 2020 by andrew-kirk

### Using residuals from linear regression for normality testing for ANOVA

0  Asked on December 9, 2020 by s-ramagokula-krishnan

### How does scaled conjugate gradient work in neural network training? Comparison with gradient descent

0  Asked on December 9, 2020 by johanna

### For B-spline what does $sum_{i=0,n}N_{i,k}(t)=1$ mean?

1  Asked on December 9, 2020

### Is it possible to detect overfitting automatically/programmatically after model creation?

0  Asked on December 9, 2020 by ayberk-yavuz

### R lmer model: degree of freedom and chi square values are zero

1  Asked on December 9, 2020 by roromario