Orthogonalize successive columns of a data frame or matrix
Orthogonalize successive columns of a data frame or matrix
gsorth uses sequential, orthogonal projections, as in the Gram-Schmidt method, to transform a matrix or numeric columns of a data frame into an uncorrelated set, possibly retaining the same column means and standard deviations as the original.
order: An integer vector specifying the order of and/or a subset of the columns of y to be orthogonalized. If missing, order=1:p
where p=ncol(y).
recenter: If TRUE, the result has same column means as original; else means = 0 for cols 2:p.
rescale: If TRUE, the result has same column standard deviations as original; else sd = residual variance for cols 2:p
adjnames: If TRUE, the column names of the result are adjusted to the form Y1, Y2.1, Y3.12, by adding the suffixes '.1', '.12', etc. to the original column names.
Returns
Returns a matrix or data frame with uncorrelated columns. Row and column names are copied to the result.
Details
In statistical applications, interpretation depends on the order of the variables orthogonalized. In multivariate linear models, orthogonalizing the response, Y variables provides the equivalent of step-down tests, where Y1 is tested alone, and then Y2.1, Y3.12, etc. can be tested to determine their additional contributions over the previous response variables.
Similarly, orthogonalizing the model X variables provides the equivalent of Type I tests, such as provided by anova.
The method is equivalent to setting each of columns 2:p to the residuals from a linear regression of that column on all prior columns, i.e.,
However, for accuracy and speed the transformation is carried out using the QR decomposition.
Examples
GSiris <- gsorth(iris[,1:4])GSiris <- gsorth(iris, order=1:4)# same, using orderstr(GSiris)zapsmall(cor(GSiris))colMeans(GSiris)# sd(GSiris) -- sd(<matrix>) now deprecatedapply(GSiris,2, sd)# orthogonalize Y sideGSiris <- data.frame(gsorth(iris[,1:4]), Species=iris$Species)iris.mod1 <- lm(as.matrix(GSiris[,1:4])~ Species, data=GSiris)car::Anova(iris.mod1)# orthogonalize X siderohwer.mod <- lm(cbind(SAT, PPVT, Raven)~ n + s + ns + na + ss, data=Rohwer)car::Anova(rohwer.mod)# type I tests for Rohwer dataRohwer.orth <- cbind(Rohwer[,1:5], gsorth(Rohwer[, c("n","s","ns","na","ss")], adjnames=FALSE))rohwer.mod1 <- lm(cbind(SAT, PPVT, Raven)~ n + s + ns + na + ss, data=Rohwer.orth)car::Anova(rohwer.mod1)# compare with anova()anova(rohwer.mod1)# compare heplots for original Xs and orthogonalized, Type Iheplot(rohwer.mod)heplot(rohwer.mod1)