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.

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

share|improve this question
2  
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 at 20:56

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
4  
+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 at 20:58
4  
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. –  Michael Mayer Jul 10 at 21:02
    
I was intending to get rid of the log by simple exponentiation. What's the problem with doing that? –  rhombidodecahedron Jul 10 at 21:02
5  
You might ask that as a new question, @rhombidodecahedron. Briefly, $E(\log z)\ne \log E(z)$. –  gung Jul 10 at 21:04
2  
If you're having trouble with the $\LaTeX$, you can use \$\widehat{\log z}\$ to get $\widehat{\log z}$. –  gung Jul 10 at 21:06

Your Answer

 
discard

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.