The details get in the way of seeing the simple relationships involved. This answer addresses the problem by generalizing it to the case of any two linear models that are related by a one-to-one linear reparameterization. The new coefficient estimates are related by the same reparametrization (equation $(1)$ below), while their covariance matrix is conjugated by that linear transformation (equation $(2)$).
The two models are parameterized differently. To understand how they are related, let $\beta$ be the parameters of the first model and $\gamma$ the parameters of the second. For the models to be equivalent, the parameters must be related by an invertible linear transformation $U$, so that
$$\gamma = U\beta;\ \beta = U^{-1}\gamma.$$
These models are
$$y = X\beta + \varepsilon = X(U^{-1}\gamma) + \varepsilon = (XU^{-1})\gamma + \varepsilon = Z\gamma + \varepsilon,$$
identifying $Z = XU^{-1}$ as the model matrix for the second model.
The least squares fits are solutions of the Normal equations,
$$\hat \beta = (X^\prime X)^{-1} X^\prime y$$
and
$$ \hat \gamma = (Z^\prime Z)^{-1} Z^\prime y = ((U^\prime)^{-1} X^\prime X U^{-1})^{-1} (U^\prime)^{-1} X^\prime y = U(X^\prime X)^{-1} X^\prime y = U\hat \beta.\tag{1}$$
(Incidentally, once we find a formula for $U$, this will provide a straightforward way to convert between $\hat\beta$ and $\hat\gamma$.)
Letting $\sigma^2$ be the common variance of the $\varepsilon$, the familiar formula for the variance-covariance matrix of the estimates gives
$$\eqalign{
\text{Cov}(\hat \beta) &= \sigma^2 (X^\prime X)^{-1};\\
\text{Cov}(\hat \gamma) &= \sigma^2 (Z^\prime Z)^{-1} = \sigma^2 ((U^\prime)^{-1} X^\prime X U^{-1})^{-1} \\
&= \sigma^2 U (X^\prime X)^{-1} U^\prime \\
&= U\left(\text{Cov}(\hat \beta)\right)U^\prime.
}\tag{2}$$
(The last equation employed the symmetry of $X^\prime X$.) In practice, $\sigma^2$ will be replaced by an estimate of it obtained from the residuals, $\hat\sigma^2$. That will not change this relationship between the two estimated covariances.
It all comes down to finding $U$. In principle, we already know it--it is determined by the two sets of variables we have created--but $U$, too, can be had by means of the Normal equations. The defining relationship $XU = Z$ is a (multivariate) regression problem that by construction of the variables in the two models has a perfect least squares fit given by
$$U = (X^\prime X)^{-1} X^\prime Z. \tag{3}$$
This, then, is the desired solution: from equations $(2)$ and $(3)$ we have obtained $\text{Cov}(\hat \gamma)$ in terms of $\text{Cov}(\hat \beta)$ and the two model matrices $X$ and $Z$.
To continue the example of the question, let's make the data generation reproducible by setting the seed at the outset:
set.seed(17)
After creating the variables a
, b
, ..., abi
as before, here are the R
commands to implement the foregoing calculations:
X <- cbind(1, a, b, aXb) # Model 1 matrix
Z <- cbind(1, ai, bi, abi) # Model 2 matrix
V <- zapsmall(solve(t(X) %*% X, t(X) %*% Z)) # This particular V has many exact zeros
U <- solve(V) # V^{-1}
colnames(U) <- rownames(U) <- colnames(Z)
fit.X <- lm(y ~ a + b + aXb) # Model 1
print(U %*% vcov(fit.X) %*% t(U), digits=13) # Model 2's covariance matrix
The last one outputs the covariance matrix of the second model in terms of the first one (which so far is the only one that has been calculated and stored in fit.X
):
ai bi abi
0.003780312655181 -0.003780312655181 -0.003780312655181 -0.003780312655181
ai -0.003780312655181 0.007430767242053 0.003780312655181 0.003780312655181
bi -0.003780312655181 0.003780312655181 0.007832935967726 0.003780312655181
abi -0.003780312655181 0.003780312655181 0.003780312655181 0.007621353224501
We may check by fitting the second model and extracting its covariance matrix directly:
fit.Z <- lm(y ~ ai + bi + abi) # Model 2
print(vcov(fit.Z), digits=13) # Model 2's covariance matrix, again
Compare its output to the preceding:
(Intercept) aiTRUE biTRUE abiTRUE
(Intercept) 0.003780312655181 -0.003780312655181 -0.003780312655181 -0.003780312655181
aiTRUE -0.003780312655181 0.007430767242053 0.003780312655181 0.003780312655181
biTRUE -0.003780312655181 0.003780312655181 0.007832935967726 0.003780312655181
abiTRUE -0.003780312655181 0.003780312655181 0.003780312655181 0.007621353224501
They agree through the first 13 significant figures. Switch the roles of the models to convert covariances from the second model to the first.
a
andai
differ; so dob
andbi
. That's why the var-covar matrices will be difficult to match--you need to compute the change-of-basis matrix from one model to the other. Incidentally, both models include (the same) "interaction" term, making it difficult to figure out what the title means--or even what the purpose of this exercise is. $\endgroup$a
andai
may be parameterized differently but they have identical estimates. in m1 you usea+b+aXb
to predict the mean ofabi
from m2. But I cannot get the se/variance to match. $\endgroup$