Samples a p x p uniformly random rotation matrix via QR decomposition of a matrix with elements sampled iid from a standard normal distribution.
Examples
set.seed(220828)
(RandRot(10))
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.004089438 0.092784118 -0.04768148 0.29468196 0.27523552 0.5569504
#> [2,] 0.663646964 0.009810906 0.55264934 -0.06325634 0.24661496 0.0294133
#> [3,] -0.020873539 -0.063554137 -0.40145339 0.50696035 -0.05420152 0.1860007
#> [4,] 0.066758845 0.178588115 -0.29990998 -0.68088711 0.11939604 0.2496002
#> [5,] 0.388689304 -0.055940018 -0.33624068 0.13538789 0.09979185 -0.2133235
#> [6,] -0.082892327 -0.535972020 -0.18785759 -0.03513325 0.71666347 -0.3026466
#> [7,] 0.272220201 0.331995688 -0.12946882 0.17075487 0.32464169 0.3110954
#> [8,] 0.095942954 -0.475896114 -0.19936269 -0.33182589 -0.14450619 0.4848229
#> [9,] 0.328928834 -0.537895427 0.09331814 0.16202069 -0.38116729 0.1238993
#> [10,] 0.453001055 0.197324556 -0.47710602 -0.05886047 -0.22606533 -0.3282654
#> [,7] [,8] [,9] [,10]
#> [1,] 0.2406591 -0.12293853 0.64072530 -0.180984786
#> [2,] -0.2248341 0.34223682 0.10951828 0.093268660
#> [3,] -0.3824591 0.61037413 -0.14087146 -0.033781333
#> [4,] -0.1023218 0.21420220 -0.07151225 -0.521607407
#> [5,] -0.5360606 -0.57437687 0.10210402 -0.176758014
#> [6,] 0.2148600 0.13219435 -0.02147308 -0.005936893
#> [7,] 0.2761220 -0.21561482 -0.64521037 0.168977955
#> [8,] -0.1304103 -0.10355794 0.03794325 0.573897093
#> [9,] 0.3376664 -0.05444565 -0.21272763 -0.494610777
#> [10,] 0.4404470 0.20434887 0.28043285 0.226936364