Milton Cezar
2006-Aug-29 01:13 UTC
[R] Bootstraping for groups and subgroups and joing with other table
Dear R-experts, I have a table with following collumns: State, SamplePlot, Species and BodySize. I sampled bird species at 34 SamplePlots and 5 States (regions) monthly during two years. On each bird record I measured bodysize and identified the species. So I have many records of each species (about 150 species) at each SamplePlot and each Region (State). Now I would like bootstrap these data, selecting 50 records for each State/SamplePlot combinations and count how many species (richness) were sampled at bootstrap. I need to do this 1.000 times. After that and need join the number of species [obtained at each bootstrap and for each State/SamplePlot combination] with a dataframe that have other attributes for SamplePlot (like Area, Perimeter etc). Bellow follow a sample of these two tables (dataframes). Could someone help me on this task. Kind regards, Miltinho ======== Table 1 - Bird records State SamplePlot Species Bodysize SaoPaulo Site1 Spp01 4.35 SaoPaulo Site1 Spp04 0.80 SaoPaulo Site1 Spp01 4.45 SaoPaulo Site1 Spp02 6.46 SaoPaulo Site1 Spp02 3.98 SaoPaulo Site1 Spp02 9.82 SaoPaulo Site2 Spp02 9.71 SaoPaulo Site2 Spp01 7.38 SaoPaulo Site2 Spp03 9.30 SaoPaulo Site2 Spp01 4.32 SaoPaulo Site2 Spp01 6.80 SaoPaulo Site2 Spp02 5.80 SaoPaulo Site2 Spp01 1.53 RioJaneiro Site1 Spp02 1.37 RioJaneiro Site1 Spp02 4.43 RioJaneiro Site1 Spp01 3.31 RioJaneiro Site1 Spp03 6.25 RioJaneiro Site1 Spp01 3.40 RioJaneiro Site2 Spp01 9.12 RioJaneiro Site2 Spp01 0.80 RioJaneiro Site2 Spp01 6.37 RioJaneiro Site2 Spp02 1.66 RioJaneiro Site2 Spp01 3.49 RioJaneiro Site3 Spp02 8.98 RioJaneiro Site3 Spp02 5.96 RioJaneiro Site3 Spp01 8.28 RioJaneiro Site3 Spp03 1.51 Bahia Site1 Spp01 6.76 Bahia Site1 Spp01 9.99 Bahia Site2 Spp01 0.72 Bahia Site2 Spp02 6.63 Bahia Site2 Spp02 3.41 Bahia Site2 Spp01 8.85 Bahia Site2 Spp01 8.13 Bahia Site3 Spp02 4.41 Bahia Site3 Spp01 9.49 Bahia Site3 Spp02 6.77 Bahia Site3 Spp02 0.64 Bahia Site4 Spp01 6.97 Bahia Site4 Spp03 8.34 Bahia Site4 Spp01 5.46 Bahia Site4 Spp01 5.52 Bahia Site5 Spp01 5.37 Bahia Site5 Spp02 8.66 ===== Table 2 - Attributes of SamplePlot State SamplePlot Area Bahia Site1 10 Bahia Site2 25 Bahia Site3 70 Bahia Site4 15 Bahia Site5 5 RioJaneiro Site1 32 RioJaneiro Site2 45 RioJaneiro Site3 10 SaoPaulo Site1 23 SaoPaulo Site2 45 --------------------------------- Música para ver e ouvir: You're Beautiful, do James Blunt [[alternative HTML version deleted]]
Chris Stubben
2006-Aug-30 17:17 UTC
[R] Bootstraping for groups and subgroups and joing with other table
> I have a table with following collumns: State, SamplePlot, Species andBodySize. I sampled bird species at> 34 SamplePlots and 5 States (regions) monthly during two years. On each birdrecord I measured bodysize> and identified the species. So I have many records of each species (about 150species) at each SamplePlot> and each Region (State). > > Now I would like bootstrap these data, selecting 50 records for eachState/SamplePlot combinations and> count how many species (richness) were sampled at bootstrap. I need to do this1.000 times.> > After that and need join the number of species [obtained at each bootstrapand for each State/SamplePlot> combination] with a dataframe that have other attributes for SamplePlot (likeArea, Perimeter etc). I asked a similar question earlier... IF you have data frame birds and bird.plots, maybe something like this. #initialize empty variable boot<-NULL for(i in 1:100) { ## split on state and site and create list a a <-split(birds, paste(birds$State,birds$SampleSite), drop=T) # sample 50 rows each OR by number of observations (better?) # b<-lapply( a, function(x) x[sample(nrow(x), 50, replace=T),]) b<-lapply( a, function(x) x[sample(nrow(x), replace=T),]) ## count number of unique species or other statistic? ### and add row to boot matrix boot<-rbind(boot, unlist( lapply(b, function (x) length(unique(x$Species)) ) )) } ## mean y<-apply(boot, 2, mean) ## convert to data frame for merge y<-data.frame(y) names(y)<-"boot.count" ## add row names to bird.plots for easy join rownames(bird.plots)<-paste(bird.plots$State,bird.plots$SampleSite) merge(bird.plots,y, by=0) Row.names State SampleSite Area boot.count 1 Bahia Site1 Bahia Site1 10 1.00 2 Bahia Site2 Bahia Site2 25 1.96 3 Bahia Site3 Bahia Site3 70 1.72 4 Bahia Site4 Bahia Site4 15 1.73 5 Bahia Site5 Bahia Site5 5 1.42 6 RioJaneiro Site1 RioJaneiro Site1 32 2.49 7 RioJaneiro Site2 RioJaneiro Site2 45 1.63 8 RioJaneiro Site3 RioJaneiro Site3 10 2.37 9 SaoPaulo Site1 SaoPaulo Site1 23 2.41 10 SaoPaulo Site2 SaoPaulo Site2 45 2.57 Chris Stubben
Possibly Parallel Threads
- En: Bootstraping for groups (right data tables)
- remove dead server (samba 4.4.4)
- [Bridge] challenge of year: connect to LAN using wireless-ap over bridge + unmanaged l2tpv3 tunnel + bridge? it's possible?
- Excluding columns from dataframe and selecting row records
- Paquete calculo de tamaño muestral