[R] How to solve A'A=S for A ?

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Feb 13 20:11:34 CET 2003


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
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
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




More information about the R-help mailing list