Orth <- rorth(4)
crossprod(Orth)
tcrossprod(Orth)
# comparison with the uncorrected QR decomposition: for a Haar
# distributed matrix both proportions should be close to 1/2
naiveOrth <- function(k) qr.Q(qr(matrix(rnorm(k * k), k)))
sapply(list(qr = naiveOrth, rorth = rorth), function(f) {
Q <- replicate(500, f(4), simplify = FALSE)
c("P(Q[1,1] < 0)" = mean(sapply(Q, function(q) q[1, 1] < 0)),
"P(det < 0)" = mean(sapply(Q, det) < 0))
})
Run the code above in your browser using DataLab