Nick Cutler sms.ed.ac.uk> writes:
>
> I would like to be able to randomise presence-absence (i.e. binary)
> matrices whilst keeping both the row and column totals constant. Is
> there a function in R that would allow me to do this?
>
> I'm working with vegetation presence-absence matrices bas
On Fri, 2007-04-27 at 09:45 +0100, Nick Cutler wrote:
Hi Nick
(Been meaning to reply to your private email to me but I've been away on
vacation and at meeting for several weeks)
> I would like to be able to randomise presence-absence (i.e. binary)
> matrices whilst keeping both the row and colu
Try
?r2dtable
On 4/27/07, Nick Cutler <[EMAIL PROTECTED]> wrote:
> I would like to be able to randomise presence-absence (i.e. binary)
> matrices whilst keeping both the row and column totals constant. Is
> there a function in R that would allow me to do this?
>
> I'm working with vegetation pres
Stephanie Dray's comments are absolutely correct. This method will
only work with small matrics. The below modification is much faster
than the first version that I wrote, but still slow on large
matrices.
shuffle_matrix <- function(x) {
nrow = dim(x)[1]
ncol = dim(x)[2]
cmargins <- apply
Your solution is not suitable for quite large matrices.
There are several papers on the subject :
e.g. :
@ARTICLE{SD751,
author = {Gotelli, N.J. and Entsminger, G.L.},
title = {Swap and fill algorithms in null model analysis:rethinking
the knight's
tour},
journal = {Oecologia},
year
Hi Nick,
This way isn't the most elegant but works well, especially if the
matrices aren't too large:
# This function works on 2x2 arrays, randomizing them, but
# preserving row and column totals
shuffle_matrix <- function(x) {
nrow = dim(x)[1]
ncol = dim(x)[2]
rmargins <- apply(x,1,sum)
I would like to be able to randomise presence-absence (i.e. binary)
matrices whilst keeping both the row and column totals constant. Is
there a function in R that would allow me to do this?
I'm working with vegetation presence-absence matrices based on field
observations. The matrices are forma