Hello Petr.



First of all, thank you for your help!



"If i understand you correctly, your real table U has 32 rows and you want
to consider all subsets of at most 10 rows."



Sorry, I wasn’t clear: I have more datasets to analyse, some of them of just
10 samples, and others of 32.

So:

sum(choose(10,1:10))

[1] 1023

> sum(choose(32,1:32))

[1] 4294967295


Now I’m going to understand well the passages you wrote, and reflect about
what you suggested, concerning considerating only a random selection of k
rows.

Maybe for our aim  it can be fair enough to exclude some of the samples,
because some of the combinations of samples are nonsense, “biologically”
talking, and so a bit easier..
    Thanks a lot,

Serena Corezzola
Centro Nazionale per lo Studio e la Conservazione della Biodiversità
Forestale, “Bosco Fontana” di Verona
Strada Mantova 29
I-46045 MARMIROLO (MN)
Italy



2011/1/28 Petr Savicky <savicky@praha1.ff.cuni.cz>

> On Thu, Jan 27, 2011 at 05:30:15PM +0100, Petr Savicky wrote:
> > On Thu, Jan 27, 2011 at 11:30:37AM +0100, Serena Corezzola wrote:
> > > Hello everybody!
> > >
> > >
> > >
> > > I?m trying to define the optimal number of surveys to detect the
> highest
> > > number of species within a monitoring season/session.
> > >
>
> [...]
>
> > This can be partially automatized as follows
> >
> >   UM <- as.matrix(U)
> >   A <- rbind(
> >   c(1, 0, 0),
> >   c(0, 1, 0),
> >   c(0, 0, 1),
> >   c(1, 1, 0),
> >   c(1, 0, 1),
> >   c(0, 1, 1),
> >   c(1, 1, 1))
> >   rownam <- rep("U", times=nrow(A))
> >   for (i in 1:3) {
> >       rownam[A[, i] == 1] <- paste(rownam[A[, i] == 1], i, sep="")
> >   }
> >   dimnames(A) <- list(rownam, NULL)
> >   C <- A %*% UM
> >   C
> >
> >        Aadi Aagl Apap Aage Bdia Beup Crub Carc Cpam
> >   U1      0    0    0    0    7    0    5    0    1
> >   U2      0    0    0    0    4    2    1    0    0
> >   U3      0    0    0    0    0    0    0    0   14
> >   U12     0    0    0    0   11    2    6    0    1
> >   U13     0    0    0    0    7    0    5    0   15
> >   U23     0    0    0    0    4    2    1    0   14
> >   U123    0    0    0    0   11    2    6    0   15
> >
> >   rowSums(C != 0)
> >
> >     U1   U2   U3  U12  U13  U23 U123
> >      3    3    1    4    3    4    4
> >
> > Now I need to do this with 10 and 32 sample events??.: (
>
> Hello.
>
> In a previous email, i suggested the code above. However, it may
> be used only for a fixed matrix U. For testing the procedure for
> a larger matrix U, matrix A should be generated differently. For a
> fixed k, A should have choose(nrow(U), k) rows, nrow(U) columns and
> its rows should be all 0,1-vectors with k ones. The following code
> may be used, although better ways of computing A probably exist.
>
>  n <- nrow(U)
>  k <- 2
>  cmb <- combn(n, k)
>  A <- matrix(0, nrow=ncol(cmb), ncol=n)
>  ind <- cbind(1:nrow(A), 0L)
>  for (i in seq.int(length=k)) {
>      ind[, 2] <- cmb[i, ]
>      A[ind] <- 1
>  }
>  A
>
>       [,1] [,2] [,3]
>  [1,]    1    1    0
>  [2,]    1    0    1
>  [3,]    0    1    1
>
>  C <- A %*% as.matrix(U)
>  rowSums(C != 0)
>
>  [1] 4 3 4
>
> This output corresponds to U12, U13, U23.
>
> If n = 32, then the above may be used for computing the required
> counts exactly for a few small values of k. For k up to 10, an
> approximation may be more suitable. For example, simulation may
> be used, where random subsets are generated using sample(n, k).
>
> Petr Savicky.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

