14
$\begingroup$

It seems that if I have a regression model such as $y_i \sim \beta_0 + \beta_1 x_i+\beta_2 x_i^2 +\beta_3 x_i^3$ I can either fit a raw polynomial and get unreliable results or fit an orthogonal polynomial and get coefficients that don't have a direct physical interpretation (e.g. I cannot use them to find the locations of the extrema on the original scale). Seems like I should be able to have the best of both worlds and be able to transform the fitted orthogonal coefficients and their variances back to the raw scale. I've taken a graduate course in applied linear regression (using Kutner, 5ed) and I looked through the polynomial regression chapter in Draper (3ed, referred to by Kutner) but found no discussion of how to do this. The help text for the poly() function in R does not. Nor have I found anything in my web searching, including here. Is reconstructing raw coefficients (and obtaining their variances) from coefficients fitted to an orthogonal polynomial...

  1. impossible to do and I'm wasting my time.
  2. maybe possible but not known how in the general case.
  3. possible but not discussed because "who would want to?"
  4. possible but not discussed because "it's obvious".

If the answer is 3 or 4, I would be very grateful if someone would have the patience to explain how to do this or point to a source that does so. If it's 1 or 2, I'd still be curious to know what the obstacle is. Thank you very much for reading this, and I apologize in advance if I'm overlooking something obvious.

$\endgroup$
  • 1
    $\begingroup$ I don't understand your points. x, x$^2$ and x$^3$ are not orthogonal. Hence they are correlated and the regression parameters could be unstable, but it is not automatically the case that they are unreliable. Conversion to orthognonal polynomials may be more reliable. But what makes the coefficient of the original powers of x any more interpretable than the coefficients of the orthogonal polynomials? If x is the only variable as in the model y=a + bx then ∆y=yi-yi-1=b∆x and b is interpretable as the change in y per unit change in x. But with powers involved such interpretation is lost. $\endgroup$ – Michael Chernick Jul 7 '12 at 22:48
  • $\begingroup$ I used a model with just x as the variable for simplicity, but in reality I'm comparing curves between treatment groups. So, depending on which terms are significant and their magnitude, I can interpret them-- for example an upward/downward overall shift, or a greater/lesser initial slope. Also, as my question says, a natural comparison to make between curves is the location of the maxima/minima, which is easier to interpret if it's on the original scale. So, your vote is for choice 3, I take it? $\endgroup$ – f1r3br4nd Jul 8 '12 at 4:44
  • $\begingroup$ No I haven't figured out whether or not it is possible yet. I just did understand why you want to do it. $\endgroup$ – Michael Chernick Jul 8 '12 at 21:33
  • 4
    $\begingroup$ Well, note that the model fit with orthogonal polynomials will have the exact same fit (i.e. the same $R^2$, same fitted values, etc.) as the model fit with the raw polynomial terms. So, if you're looking to relate this back to the original data, you can look at the coefficients for the raw terms but use the orthogonal polynomials to do inference for the individual terms in a way that "accounts for" the dependency between them. $\endgroup$ – Macro Jul 9 '12 at 12:27
  • 1
    $\begingroup$ As it turns out, cubic splines and B-splines are in a class all by themselves, and are the best of two worlds. $\endgroup$ – Carl Nov 27 '16 at 1:35
6
$\begingroup$

Yes, it's possible.

Let $z_1, z_2, z_3$ be the non-constant parts of the orthogonal polynomials computed from the $x_i$. (Each is a column vector.) Regressing these against the $x_i$ must give a perfect fit. You can perform this with the software even when it does not document its procedures to compute orthogonal polynomials. The regression of $z_j$ yields coefficients $\gamma_{ij}$ for which

$$z_{ij} = \gamma_{j0} + x_i\gamma_{j1} + x_i^2\gamma_{j2} + x_i^3\gamma_{j3}.$$

The result is a $4\times 4$ matrix $\Gamma$ that, upon right multiplication, converts the design matrix $X=\pmatrix{1;&x;&x^2;&x^3}$ into $$Z=\pmatrix{1;&z_1;&z_2;&z_3} = X\Gamma.\tag{1}$$

After fitting the model

$$\mathbb{E}(Y) = Z\beta$$

and obtaining estimated coefficients $\hat\beta$ (a four-element column vector), you may substitute $(1)$ to obtain

$$\hat Y = Z\hat\beta = (X\Gamma)\hat\beta = X(\Gamma\hat\beta).$$

Therefore $\Gamma\hat\beta$ is the estimated coefficient vector for the model in terms of the original (raw, un-orthogonalized) powers of $x$.

The following R code illustrates these procedures and tests them with synthetic data.

n <- 10        # Number of observations
d <- 3         # Degree
#
# Synthesize a regressor, its powers, and orthogonal polynomials thereof.
#
x <- rnorm(n)
x.p <- outer(x, 0:d, `^`); colnames(x.p) <- c("Intercept", paste0("x.", 1:d))
z <- poly(x, d)
#
# Compute the orthogonal polynomials in terms of the powers via OLS.
#
xform <- lm(cbind(1, z) ~ x.p-1)
gamma <- coef(xform)
#
# Verify the transformation: all components should be tiny, certainly
# infinitesimal compared to 1.
#
if (!all.equal(as.vector(1 + crossprod(x.p %*% gamma - cbind(1,z)) - 1), 
    rep(0, (d+1)^2)))
  warning("Transformation is inaccurate.")
#
# Fit the model with orthogonal polynomials.
#
y <- x + rnorm(n)
fit <- lm(y ~ z)
#summary(fit)
#
# As a check, fit the model with raw powers.
#
fit.p <- lm(y ~ .-1, data.frame(x.p))
#summary(fit.p)
#
# Compare the results.
#
(rbind(Computed=as.vector(gamma %*% coef(fit)), Fit=coef(fit.p)))

if (!all.equal(as.vector(gamma %*% coef(fit)), as.vector(coef(fit.p))))
  warning("Results were not the same.")
$\endgroup$
  • $\begingroup$ Nice answer, especially $\Gamma$. In 8th line of code, do you have (1 + cross... - 1). Why we need +1 - 1.? $\endgroup$ – pauljohn32 Nov 29 '17 at 7:44
  • $\begingroup$ @Paul Adding $1$ turns all components smaller than about $10^{-16}$ into true zeros due to floating point imprecision and subtracting $1$ cancels out that effect. This implements the test announced in the preceding code comment block. $\endgroup$ – whuber Nov 29 '17 at 15:50
  • $\begingroup$ Two years later... @whuber, is it possible to expand this to the 95% CIs of the coefficients as well? $\endgroup$ – user2602640 Sep 21 '18 at 18:49
  • $\begingroup$ @user2602640 Yes. You need to extract the variance-covariance matrix of the coefficients (use vcov in R) to convert variances computed in one basis to variances in the new basis, and then compute the CIs manually in the usual way. $\endgroup$ – whuber Sep 21 '18 at 19:00
  • $\begingroup$ @whuber I followed your comment about halfway through, then lost you entirely... any chance you would take pity on a mathematically-challenged biologist and write it out in code? $\endgroup$ – user2602640 Sep 21 '18 at 19:03

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.