# [R] Re : Generate a random bistochastic matrix

From: Florent Bresson <f_bresson_at_yahoo.fr>
Date: Mon 16 Oct 2006 - 15:03:00 GMT

Thanks, I think it's a shrewd solution, but the problem is that it cannot generate every N*N bistochastic matrix and every cell tends to 1/N as B tends to infinity

Florent Bresson

• Message d'origine ---- De : Dimitris Rizopoulos <dimitris.rizopoulos@med.kuleuven.be> À : Florent Bresson <f_bresson@yahoo.fr> Cc : r-help@stat.math.ethz.ch Envoyé le : Lundi, 16 Octobre 2006, 16h35mn 02s Objet : Re: [R] Generate a random bistochastic matrix

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

```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@yahoo.fr> To: <r-help@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@stat.math.ethz.ch mailing list