That will work if S is unambiguously positive definite, but covariance matrices need not be, and then chol (without pivoting) will fail. Pivoting can be used: see ?chol.
A more expensive but safer solution is to use eigen: see the code for mvrnorm. On Thu, 13 Feb 2003, Sundar Dorai-Raj wrote: > > > Ralf Engelhorn wrote: > > Dear R helpers, > > > > is there a function or way within R to solve A'A=S for A, where all > > matrices have p x p order and S is a variance-covariance matrix? > > > > Thank you, > > Ralf Engelhorn > > > > ______________________________________________ > > [EMAIL PROTECTED] mailing list > > http://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > > See ?chol. Here's an example: > > R> S = diag(4) > R> S[row(S) < col(S)] = > + S[row(S) > col(S)] = 0.5 > R> S > [,1] [,2] [,3] [,4] > [1,] 1.0 0.5 0.5 0.5 > [2,] 0.5 1.0 0.5 0.5 > [3,] 0.5 0.5 1.0 0.5 > [4,] 0.5 0.5 0.5 1.0 > R> A = chol(S) > R> t(A) %*% A > [,1] [,2] [,3] [,4] > [1,] 1.0 0.5 0.5 0.5 > [2,] 0.5 1.0 0.5 0.5 > [3,] 0.5 0.5 1.0 0.5 > [4,] 0.5 0.5 0.5 1.0 > R> > > Sundar > > ______________________________________________ > [EMAIL PROTECTED] mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-help > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
