Solved – Calculate standard errors: interaction between 2 factors, one of which has 3 levels in a regression model

interactionregressionstandard error

I have the following model:
$y \sim b_0 + b_1x_1 + b_2x_2 + b_3x_1x_2$.

$x_1$ is a factor with 2 levels (0 and 1), and $x_2$ is a factor with 3 levels.

I know that to calculate standard errors for the interaction term I should use
$\sqrt{\text{var}(b_1) + \text{var}(b_2) + 2\text{cov}(b_1,b_2)}$.

When I use vcov() in R to get the variance/covariance matrix I get a 6×6 matrix with the following column/row names:

  • (Intercept)
  • factor(x1)level1
  • factor(x2)level1
  • factor(x2)level2
  • factor(x1)level1:factor(x2)level1
  • factor(x1)level1:factor(x2)level2.

Where on this matrix is the cov(b1,b2)? Is it in the cell [factor(x1)level1, factor(x2)level1] or in the cell [factor(x1)level1,factor(x2)level2] or neither?
Or to put it better, if I want the standard errors for the marginal effects of x1 and x2 on y, how do I calculate them? When we have more than 2 levels in a factor does the above mentioned standard error equation change?

Many thanks in advance!

EDIT (migrated from OP answer): Maybe I should rephrase: I need the standard error for the marginal effect of x1 on y and the standard error for the marginal effect of x2 on y. the equation I put there supposedly gives that standard error (please see in this website How to calculate the interaction standard error of a linear regression model in R? and in Brambor T. et al Understanding Interaction Models: Improving Empirical Analyses. Political Analysis (2006) 14:63–82. doi:10.1093/pan/mpi014, equation 8). But maybe I am not using the correct terminology or references here? any ideas on how to calculate that standard error would be very wellcome.

Best Answer

In the paper you cite X and Z form an interaction term where Z is binary random variable equal to either 0 or 1. The model looks like

Y=b$_1$X+b$_2$XZ. Given Z=1 this reduces to Y=(b$_1$+b$_2$)X. So conditional on Z=1 the variance of the coefficient for X is Var(b$_1$)+Var(b$_2$)+2 Cov(b$_1$,b$_2$). But still it is b$_2$ that is the coefficient of the interaction term and it does not have that variance.

Note that in the linked CV post in response jbowman never claims that Var(b$_1$)+Var(b$_2$)+2 Cov(b$_1$,b$_2$) is the variance of the interaction term.

Related Question