# Difference between contr.poly e poly in regression and interpretation

I am confusing regarding the differences between poly and contr.poly in regression.

Both should generate the orthonormal polynomial transformation of a vector. But poly is influenced by the length of the vector while contr.poly only by the number of unique elements in the vector, giving therefore different results.

This is shown passing a vector of 1:10 to the functions:

poly(1:10, 1) %>% unique() %>% sort()
 -0.49543369 -0.38533732 -0.27524094 -0.16514456 -0.05504819  0.05504819  0.16514456  0.27524094  0.38533732  0.49543369

attr(C(as.ordered(1:10), ,1), 'contrasts') %>% as.vector()
 -0.49543369 -0.38533732 -0.27524094 -0.16514456 -0.05504819  0.05504819  0.16514456  0.27524094  0.38533732  0.49543369


Same result. But if I join the vector twice with c(1:10, 1:10) I get different results:

poly(c(1:10, 1:10), 1) %>% unique() %>% sort()
 -0.35032452 -0.27247463 -0.19462474 -0.11677484 -0.03892495  0.03892495  0.11677484  0.19462474  0.27247463  0.35032452

attr(C(as.ordered(c(1:10,1:10)), ,1), 'contrasts') %>% as.vector()
 -0.49543369 -0.38533732 -0.27524094 -0.16514456 -0.05504819  0.05504819  0.16514456  0.27524094  0.38533732  0.49543369


I guess it's because being the vector a factor in the second example the elements are considered only once.

Therefore, which is the difference in interpretation of the two in a regression setting? Which one should be used and in general how one should interpret the coefficients after an orthonormal transformation, what does a change of 1 mean?

Thanks

• It is instructive to read the help pages and to test the software while you do so. Compare, for instance, the values of poly(1:d, degree=d-1) and contr.poly(d). Start with d<-3 and try it for several more (larger integral) values of d.
– whuber
Jul 3, 2017 at 20:03
• Uhm, I tried it and as long there are only unique values both functions give the same results. In the manual pages doesn't say much. So I don't know which to use and how to interpretate the relative coefficients in a regression setting. Jul 4, 2017 at 7:17
• You will find useful information about poly at stats.stackexchange.com/questions/31858. As you have learned through your experimentation, contr.poly implements a special case of orthogonal polynomials.
– whuber
Jul 4, 2017 at 13:45