# How to calculate the standard error of the marginal effects in interactions (robust regression)?

what I am interested in learning is how to calculate the std error of the marginal effects of a X variable when it is part of an interaction, especially in robust regression.

There are tipically two cases that interest me: when there is an interaction between two continuous variables and when there is an interaction between a continuous and a binary variable. Let's our model be a simple one:

$Y= b_0 + b_1X + b_2Z + b_3XZ + e$

I know how to calculate the marginal effect of X in both cases, but not how to calculate its standard error. Please, any hints on how to do this, both theoretically or in R code, may be very helpfull.

• I suspect your model is more complicated than the one you present. That model is just a linear model, so the marginal effect is b_3 and its standard error is typically directly returned by your estimation command. – Maarten Buis Apr 11 '13 at 6:56
• Hi Maarten, thanks for your comment. I edited the question to better reflecft what I want, as I was talking about the marginal effect of X, which in this case i not b_3, but b_1 + b_3*Z. Does it get clearer? Thanks again – R.Astur Apr 12 '13 at 21:33

If you treat $Z$ as non-random variable, then the marginal effect is $b_1 + b_3 \cdot Z$, a function of $Z$. The variance of a weighted sum is $Var(b_1) + Var(b_3) \cdot Z^2 + 2 \cdot Z \cdot Cov(b_1,b_3),$ and the standard error is just the square root of that. You can get the covariance from the right off-diagonal element of the variance-covariance matrix of the coefficients. The variances will be found on the diagonal.
If your software does not return it, you can estimate the variance-covariance matrix as $$V=\frac{\hat e'\hat e}{n-k}(D'D)^{-1},$$
where $\hat e$ is the vector of residuals $\hat e=y-\hat \beta'D$, and the $D$ matrix contains a column of ones, $X$, $Z$ and their interaction, $n$ is the number of observations and $k$ is the number of variables.