I have two continuous variables, X and Y, that are correlated - they are not independent. To correct for non-independence, I have a known correlation structure, a matrix S.
If one calls gls(Y ~ X, correlation = S)
, what I think happens is that, internally, gls() transforms X and Y in some way so that the regression ends up being S^(-1)*Y = S^(-1) * X
.
How is this transformation actually performed? From the literature I've consulted, I've seen everything from:
X.transformed <- solve(chol(S)) %*% X
#The inverse of the Choleski decomposition of S times the vertical vector X,
#which in my case does nothing to the data
to
X.transformed <- chol(solve(S)) %*% X
# which has negative values and gives meaningless values of X
Another method I've seen is transforming the dependent variable by
chol(solve(S)) %*% Y
and the independent variable by
chol(solve(S)) %*% cbind(1,X)
and doing the linear model using the transformed intercept terms in the first column of the X matrix:
lm(Y ~ X - 1)
On a related note, is there any point to manually transforming the data in order to plot it? Do the transformed values have any meaning, or are they simply there to estimate regression coefficients? (In other words, if X is a variable of body mass figures, X values are not necessarily errant if they're negative since they're still linear?) I suppose it would follow from this that an $R^2$ statistic on transformed variables is also meaningless?