My name is Michela Marignani and I'm an ecologist trying to solve a problem linked to knight' s tour algorithm. I need a program to create random matrices with presence/absence (i.e. 1,0 values), with defined colums and rows sums, to create null models for statistical comparison of species distribution phenomena. I've seen on the web many solutions of the problem, but none provides the freedom to easily change row+colums constraint and none of them produce matrices with 1 and 0. Also, I've tryied to use R, but it is too complicated for a not-statistician as I am....can you help me? Thank you for your attention, so long Michela Marignani University of Siena Environmental Science Dept. Siena, Italy michela.marignani at uniroma1.it
If I understand your problem properly, then your matrices have a known number of zeros and ones in them. So you can create a matrix with just this constraint binding via: mat <- matrix(sample(rep(0:1, c(nzeros, nones))), nr, nc) That command first generates the appropriate number of zeros and ones (via 'rep'), then does a random permutation of them (with 'sample') and finally turns it into a matrix. You could then test for the row and column constraints, and permute the sub-matrix of rows and columns that do not obey their constraints. It could look something like: mat[bad.rows, bad.cols] <- sample(mat[bad.rows, bad.cols]) where 'bad.rows' and 'bad.cols' are logical vectors stating if the constraints are satisfied or not. You do not need to be a statistician to use R -- far from it. The 'Guide for the Unwilling' gives you a brief introduction. There is also a lot of introductory material in the contributed documentation section of the R Project website. It would be good to use a more descriptive subject for messages to R-help. Patrick Burns Burns Statistics patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Michela Marignani wrote:> My name is Michela Marignani and I'm an ecologist trying to solve a > problem linked to knight' s tour algorithm. > I need a program to create random matrices with presence/absence (i.e. > 1,0 values), with defined colums and rows sums, to create null models > for statistical comparison of species distribution phenomena. > I've seen on the web many solutions of the problem, but none provides > the freedom to easily change row+colums constraint and none of them > produce matrices with 1 and 0. Also, I've tryied to use R, but it is > too complicated for a not-statistician as I am....can you help me? > > Thank you for your attention, > so long > > Michela Marignani > University of Siena > Environmental Science Dept. > Siena, Italy > michela.marignani at uniroma1.it > > ______________________________________________ > 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 > > >
Persi Diaconis and Bernd Sturmfels have an article on generating random contingency tables uniformly distributed subject to having fixed marginals for the same purpose (null distribution of conditional test) and they used Markov Chain Monte Carlo to sample. That could perhaps be adapted here. The article is in Annals of Statistics from several years ago, and if you google for "algebraic statistics" you'll probably find several recent expositions of the ideas, possibly even code. Reid Huntsinger -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Michela Marignani Sent: Thursday, January 27, 2005 3:52 AM To: r-help at stat.math.ethz.ch Subject: [R] Request for help My name is Michela Marignani and I'm an ecologist trying to solve a problem linked to knight' s tour algorithm. I need a program to create random matrices with presence/absence (i.e. 1,0 values), with defined colums and rows sums, to create null models for statistical comparison of species distribution phenomena. I've seen on the web many solutions of the problem, but none provides the freedom to easily change row+colums constraint and none of them produce matrices with 1 and 0. Also, I've tryied to use R, but it is too complicated for a not-statistician as I am....can you help me? Thank you for your attention, so long Michela Marignani University of Siena Environmental Science Dept. Siena, Italy michela.marignani at uniroma1.it ______________________________________________ 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