From: <davidr_at_rhotrading.com>

Date: Thu, 26 Jun 2008 12:09:03 -0500

}

cov

}

> ### Simualte multivarite gaussin data ( gives Error)

*> Sigma<-COV(p = 3, sd = 2, r= -0.6)
*

*> mu<-1:3
*

*> mvrnorm(5, mu=mu, Sigma=Sigma)
*

Error in mvrnorm(5, mu = mu, Sigma = Sigma) : 'Sigma' is not positive definite

Date: Thu, 26 Jun 2008 12:09:03 -0500

Well, if you think about the geometry, all correlations equal usually
won't work. Think of the SDs as the sides of a simplex and the
correlations as the cosines of the angles between the sides (pick one
variable as the 'origin'.) Only certain values will give a valid
covariance or correlation matrix.

**HTH,
**

David L. Reiner, PhD

Head Quant

Rho Trading Securities, LLC

-----Original Message-----

From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
On Behalf Of Mizanur Khondoker

Sent: Thursday, June 26, 2008 11:11 AM

To: r-help_at_r-project.org

Subject: [SPAM] - [R] constructing arbitrary (positive definite)
covariance matrix - Found word(s) list error in the Text body

Any help/ suggestion would be greatly appreciated.

Examples

########

COV<-function (p = 3, sd = 1, r= 0.5){

cov <- diag(sd^2, ncol=p, nrow=p)

for (i in 1:p) {

for (j in 1:p) { if (i != j) { cov[i, j] <- r * sd*sd } }

}

cov

}

> library(MASS)

*> ### Simualte multivarite gaussin data (works OK)
**> Sigma<-COV(p = 3, sd = 2, r= 0.5)
**> mu<-1:3
**> mvrnorm(5, mu=mu, Sigma=Sigma)
*

[,1] [,2] [,3]

[1,] 1.2979984 1.843248 4.460891 [2,] 2.1061054 1.457201 3.774833 [3,] 2.1578538 2.761939 4.589977 [4,] 0.8775056 4.240710 2.203712 [5,] 0.2698180 2.075759 2.869573 >

> ### Simualte multivarite gaussin data ( gives Error)

Error in mvrnorm(5, mu = mu, Sigma = Sigma) : 'Sigma' is not positive definite

-- Mizanur Khondoker Division of Pathway Medicine (DPM) The University of Edinburgh Medical School The Chancellor's Building 49 Little France Crescent Edinburgh EH16 4SB United Kingdom Tel: +44 (0) 131 242 6287 Fax: +44 (0) 131 242 6244 http://www.pathwaymedicine.ed.ac.uk/ ______________________________________________ R-help_at_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. ______________________________________________ R-help_at_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.Received on Thu 26 Jun 2008 - 17:12:16 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Thu 26 Jun 2008 - 18:31:45 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*