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 [EMAIL PROTECTED] +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 [EMAIL PROTECTED]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
