\encoding{UTF-8}
\name{Random.Start}
\alias{Random.Start}
\title{Random Starting Matrix for Factor Rotation}
\usage{
    Random.Start(k = 2L)
}
\arguments{
    \item{k}{a positive integer specifying the dimension of the square
         orthogonal matrix to generate (default 2).}
}
\description{
  Generates a random orthogonal matrix for use as an initial rotation
  matrix (\code{Tmat}) in gradient projection rotation functions.
}
\value{
  A \eqn{k \times k}{k x k} orthogonal matrix drawn uniformly from the
  Haar measure on the orthogonal group O(k). Columns have unit length
  and are mutually orthogonal.
}
\details{
  The function generates a random orthogonal matrix using QR decomposition
  of a matrix of standard normal variates, with a sign correction applied
  to the diagonal of R to ensure uniform sampling from the Haar measure.
  This follows the approach of Stewart (1980) and Mezzadri (2007).

  The naive approach of \code{qr.Q(qr(matrix(rnorm(k*k), k)))} does not
  guarantee uniform sampling from the Haar measure. The sign correction
  \code{Q \%*\% diag(sign(diag(R)))} is required to achieve this. This
  was updated in GPArotation 2024.2-1 following a suggestion by Yves
  Rosseel.

  For oblique rotation a random starting transformation matrix can be
  generated by normalizing the columns of a random matrix:
  \code{X \%*\% diag(1/sqrt(diag(crossprod(X))))} where
  \code{X <- matrix(rnorm(k*k), k)}.
}
\examples{
  # Generate a 5 x 5 random orthogonal matrix
  Random.Start(5)

  # Verify orthogonality: t(Q) %*% Q should be the identity matrix
  Q <- Random.Start(4)
  round(t(Q) \%*\% Q, 10)

  # Use as starting matrix for rotation
  data("Thurstone", package = "GPArotation")
  simplimax(box26, Tmat = Random.Start(3))
}
\seealso{
  \code{\link{GPFRSorth}},
  \code{\link{GPFRSoblq}},
  \code{\link{GPForth}},
  \code{\link{GPFoblq}},
  \code{\link{rotations}}
}
\references{
  Stewart, G.W. (1980). The efficient generation of random orthogonal
    matrices with an application to condition estimators.
    \emph{SIAM Journal on Numerical Analysis}, \bold{17}(3), 403--409.
    doi: 10.1137/0717034

  Mezzadri, F. (2007). How to generate random matrices from the classical
    compact groups. \emph{Notices of the American Mathematical Society},
    \bold{54}(5), 592--604. arXiv:math-ph/0609050
}
\author{Coen A. Bernaards and Robert I. Jennrich
        with some R modifications by Paul Gilbert.
        Updated following a suggestion by Yves Rosseel.}
\concept{rotation}
\keyword{multivariate}