[R] Subsampling out of site*abundance matrix

David Winsemius dwinsemius at comcast.net
Tue Feb 8 01:53:23 CET 2011


On Feb 7, 2011, at 6:43 PM, B77S wrote:

>
> So, after thinking about this a bit, I realized that the previous  
> solution
> wasn't exactly what I needed.  I really needed replacement=F and to  
> be able
> to choose any sample size (n.sample) less than or equal to the site  
> (row)
> with the lowest total abundance.

The reason I suggested ,  replace =FALSE,  is that I thought those  
were population parameters. Furthermore, even if we think of them as  
samples, it seems unlikely that they are the entire universe for  
inference, since knowing such a universe would make statistics  
superfluous. My advice is to consult a statistician before you set  
replace=FALSE.

>
>
> Anyway, I think this works.  Forgive me if I have misunderstood  
> something
> regarding the previous solutions output.  I do not pretend to be
> intelligent.

Better watch out.... amusing utterances such as that are fortune-fodder.

>  Cheers!
>
> ############### start function ###############
>
> RAND_L <- function(L.matrix, n.sample){
> mainout <- vector("list")
> for(i in 1:nrow(L.matrix)){
> ## decomposes species (1:ncol(L.matrix)) into a list of counts per  
> each
> out<- vector("list") 	
> for(j in 1:length(L.matrix[i,])){
> out[[j]] <- rep(names(L.matrix[i,])[j], L.matrix[i,j])
> }
> ## puts previous loop products (counts) in a row
> out2 <- vector()	
> for(k in 1:length(out)){
> out2 <- append(out2, as.character(unlist(out[k])))
> }
> out3<- sample(out2, n.sample, replace=F)	
> mainout[[i]] <- out3
> mainout[[i]] <- factor(mainout[[i]], levels= colnames(L.matrix)) 	
> }
> finalout <- t(sapply(mainout, table))
> rownames(finalout)<-rownames(L.matrix)	
> return(finalout)	
> }
>
> ################### end function ##################
>
>
>> RAND_L(abund2, 100)
>      spA spB spC spD spa spF spG
> site1  11  12  18   8   0  24  27
> site2  24  24   0   0  27  25   0
> site3   0   0   6  38   0   0  56
> site4  27  20   0   0  16  37   0
>
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3265402.html

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list