Matrix X decomposed as Q and R (X=QR) where columns of Q are orthonormal. Ordinary QR or SVD may be used.
Details
To handle dependency a usual decomposition of X is PX=QR where P is a permutation matrix. This function returns RP^T as R. When SVD, Q=U and R=SV^T.
Examples
GenQR(matrix(rnorm(15),5,3))
#> $Q
#> [,1] [,2] [,3]
#> [1,] 0.6506141 -0.27552349 0.2724166
#> [2,] 0.1151541 0.03820916 0.2026521
#> [3,] 0.6413574 -0.26341410 -0.1602308
#> [4,] 0.2548852 0.78496298 0.5114434
#> [5,] 0.2951864 0.48690143 -0.7729638
#>
#> $R
#> [,1] [,2] [,3]
#> [1,] 2.055474 0.7641241 -0.2884700
#> [2,] 0.000000 2.2033898 -0.4408586
#> [3,] 0.000000 0.0000000 2.9917666
#>
GenQR(matrix(rnorm(15),5,3)[,c(1,2,1,3)])
#> $Q
#> [,1] [,2] [,3]
#> [1,] -0.1205333 0.50656586 0.4395228
#> [2,] 0.3359040 -0.01435155 0.7907968
#> [3,] -0.2956947 0.23189514 -0.2468838
#> [4,] 0.3283929 0.81442851 -0.2390882
#> [5,] 0.8230206 -0.16160416 -0.2516851
#>
#> $R
#> [,1] [,2] [,3] [,4]
#> [1,] 1.291708 -0.02523919 1.291708e+00 -0.3576097
#> [2,] 0.000000 2.06423395 4.799873e-17 0.2032711
#> [3,] 0.000000 0.00000000 1.402158e-17 1.8207790
#>
GenQR(matrix(rnorm(15),5,3)[,c(1,2,1,3)],TRUE)
#> $Q
#> [,1] [,2] [,3]
#> [1,] -0.4011668 0.03384302 -0.4412441
#> [2,] -0.2297930 -0.38528771 -0.2724030
#> [3,] -0.6943454 -0.49688334 0.2035029
#> [4,] -0.4966086 0.61889271 0.5132699
#> [5,] -0.2398433 0.46956022 -0.6528712
#>
#> $R
#> [,1] [,2] [,3] [,4]
#> [1,] 2.3030889 -0.07691417 2.3030889 -1.5551106
#> [2,] 0.4537752 -1.37823298 0.4537752 1.4122306
#> [3,] 0.3358033 1.18046938 0.3358033 0.9362517
#>