Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

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 6x6 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.

share|improve this question
Where did you get the idea that the standard deviation for b$_3$ is given by the formula you gave? That is the formula for the variance of b$_1$+b$_2$. The coefficient b$_3$ is not b$_1$ + b$_2$ –  Michael Chernick Aug 26 '12 at 23:11
If Isidora said that she KNEW that this is the "right" formula to calculate the standard error, then somebody must have taught her that way. For the benefit of the community, Isidora would really want to explain where this formula is coming from... so that everybody else would know which book to avoid :-\. Also, why did you tag this "multilevel"? Are the factors measured at different levels? –  StasK Aug 27 '12 at 0:24
@Isidora I have merged your accounts, but please register so that you won't lose control of your posts again. –  mbq Aug 27 '12 at 13:38
@Stask The formula comes from the referenced paper, which (correctly) identifies it as the standard error of a linear combination, not an "SE for the interaction term." Part of this question concerns how to identify the correct rows (and columns) of the covariance matrix of estimates in R. The statistical content concerns how to extend the paper's analysis from binary factors to n-ary factors. –  whuber Aug 27 '12 at 13:45
@whuber, I see. The covariances of the coefficient estimates should be in the output, but the marginal effects would either require direct calculation or finding the right R package (Stata does it with the official margins command, so there is no question of how to compute the standard error of the marginal effect unless you want to verify the formula.) The "multilevel" tag question still remains. –  StasK Aug 27 '12 at 14:30
show 4 more comments

1 Answer 1

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.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.