try this:

a <- c(0.5343909, -0.7784353, -0.0568370, 1.8772838, -1.3183407, 0.8227418)
mean <- c(0, 0)
Sigma <- matrix(c(1, 0, 0, 1), 2, 2)

library(mvtnorm)
ind <- combn(length(a), 2)
x <- cbind(a[ind[1, ]], a[ind[2, ]])
dmvnorm(x, mean, Sigma)


I hope it helps.

Best,
Dimitris


On 2/23/2010 8:04 AM, sunivon wrote:


Hello all,
Is there a way in R to compute the multivariate normal density of every pair of 
entries in a vector efficiently instead of using for loop?
For example

Suppose I have a vector a=c(v_1,...,v_p)=c(0.5343909, -0.7784353, -0.0568370,  
1.8772838, -1.3183407,  0.8227418,...)
I want to compute density(v_i, v_j) for every pair of entries (i,j) (i!=j) in 
a.  The joint bivariate distribution is known to be the same for each pair.

Thanks a lot!
Ivon



                                        
_________________________________________________________________
[[elided Hotmail spam]]

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to