# Getting the equation from R's lm when using a product

Similar to this question: How to translate the results from lm() to an equation? in which the top voted answer said how to get the form of an equation from lm(y ~ x) and equivalently for lm(z ~ y + x) and other sums, I'm wondering: how can the equation be obtained from the form of lm(z ~ y*x)?

I have:

> summary(lm(log(z) ~ x*y))

Call:
lm(formula = log(z) ~ x * y)

Residuals:
Min        1Q    Median        3Q       Max
-0.181142 -0.073755  0.000481  0.082088  0.200902

Coefficients:
Estimate Std. Error  t value Pr(>|t|)
(Intercept)  -9.85368    0.09304 -105.906  < 2e-16 ***
x           -97.41166    6.28269  -15.505  < 2e-16 ***
y            -2.26398    0.14243  -15.895  < 2e-16 ***
x:y          91.69016    9.77390    9.381 6.95e-14 ***


It returns 4 coefficients -- (Intercept), x, y, and x:y -- but I'm not sure how to put them together to get the final equation.

Is it simply that x:y term multiplied by x*y plus the intercept? That is, in this case $\log z = 91.69 xy -9.853$?

-
By inspecting model.fit(lm(log(z) ~ x*y)) you will quickly see what x:y represents and then you can directly apply the solutions you reference. It's a good idea, though, not to transcribe coefficients from the output, because they are rounded. To retain their full precision--which becomes more important with interaction terms like x:y--extract the coefficients from the result of lm as doubles and use those for subsequent formulas. –  whuber Jul 10 '14 at 20:56

The equation is $\widehat{\log z} = -9.853 -97.41166x -2.26398y + 91.69xy$ where $\widehat{\log z}$ is the estimated value of $\log z$.
+1, this is the answer. I think the confusion might be about manually creating the new x*y variable. You'll want to put the 'hat' over the entire "$\log z$", not just the $z$. –  gung Jul 10 '14 at 20:58
You might ask that as a new question, @rhombidodecahedron. Briefly, $E(\log z)\ne \log E(z)$. –  gung Jul 10 '14 at 21:04
If you're having trouble with the $\LaTeX$, you can use \$\widehat{\log z}\$ to get $\widehat{\log z}$. –  gung Jul 10 '14 at 21:06