[R] Generate a random bistochastic matrix

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Mon Oct 16 16:35:02 CEST 2006


you can try something like the following:

B <- 10
N <- 5
mats <- r2dtable(B, rep(1, N), rep(1, N))
out <- matrix(0, N, N)
for(i in 1:length(mats))
    out <- out + mats[[i]]
out <- out / B
out
colSums(out)
rowSums(out)



I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Florent Bresson" <f_bresson at yahoo.fr>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, October 16, 2006 10:22 AM
Subject: [R] Generate a random bistochastic matrix


Please, I would like to generate a random bistochastic matrix, that is 
a squared matrix of non-negative numbers  with  each row and each 
column sum to 1, for example :

.2    .3    .5
.6    .3    .1
.2     .4     .4

I don't know of to code this. Do you have any idea ?

Thanks

Florent Bresson








___________________________________________________________________________



______________________________________________
R-help at stat.math.ethz.ch 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.


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list