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))

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

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

             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$?

  • 2
    $\begingroup$ 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. $\endgroup$ – 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$.

  • 4
    $\begingroup$ +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$. $\endgroup$ – gung Jul 10 '14 at 20:58
  • 4
    $\begingroup$ I suggest to put an expectation around the left hand side - especially if someone tries to get rid of the log simply by exponentiation. Otherwise the answer is nice. $\endgroup$ – Michael M Jul 10 '14 at 21:02
  • $\begingroup$ I was intending to get rid of the log by simple exponentiation. What's the problem with doing that? $\endgroup$ – rhombidodecahedron Jul 10 '14 at 21:02
  • 5
    $\begingroup$ You might ask that as a new question, @rhombidodecahedron. Briefly, $E(\log z)\ne \log E(z)$. $\endgroup$ – gung Jul 10 '14 at 21:04
  • 2
    $\begingroup$ If you're having trouble with the $\LaTeX$, you can use \$\widehat{\log z}\$ to get $\widehat{\log z}$. $\endgroup$ – gung Jul 10 '14 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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