Solution
Radhika answered on
Oct 22 2022
####################################################################
####################################################################
## community abundance data
## open the "BCI1.csv" file in excel and have a look
## the data is tree counts in 1-hectare plots in the Ba
o Colorado Island.
## there are 50 plots (rows) of 1 hectare with counts of trees on each plot with total of 225 species (columns).
## Full Latin names are used for tree species.
## Data give the numbers of trees at least 10 cm in diameter at
east height (1.3 m above the ground) in each one hectare square of forest.
## Within each one hectare square, all individuals of all species were tallied and are recorded in this table.
## The quadrats are located in a regular grid.
## Data source: http:
www.sciencemag.org/cgi/content/full/295/5555/666/DC1 (also available in the 'vegan' R package
## Reference: Condit, R, Pitman, N, Leigh, E.G., Chave, J., Te
orgh, J., Foster, R.B., Nuñez, P., Aguilar, S., Valencia, R., Villa, G., Muller-Landau, H.C., Losos, E. & Hu
ell, S.P. (2002). Beta-diversity in tropical forest trees. Science 295, 666–669.
## first we read in the data set and have a quick look
BCI <- read.csv("BCI1.csv")
head(BCI)
# A ti
le: 6 x 225
Abarema.macrade~ Acacia.melanoce~ Acalypha.divers~
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
# ... with 222 more variables: Acalypha.macrostachya ,
# Adelia.triloba , Aegiphila.panamensis ,
# Alchornea.costaricensis , Alchornea.latifolia ,
# Alibertia.edulis , Allophylus.psilospermus ,
# Alseis.blackiana , Amaioua.corymbosa ,
# Anacardium.excelsum , Andira.inermis ,
# Annona.spraguei , Apeiba.aspera ,
# Apeiba.tibou
ou , Aspidosperma.cruenta ,
# Astrocaryum.standleyanum ,
# Astronium.graveolens , Attalea.butyracea ,
# Banara.guianensis , Beilschmiedia.pendula ,
# Brosimum.alicastrum , Brosimum.guianense ,
# Calophyllum.longifolium , Casearia.aculeata ,
# Casearia.a
orea , Casearia.commersoniana ,
# Casearia.guianensis , Casearia.sylvestris ,
# Cassipourea.elliptica ,
# Cavanillesia.platanifolia , Cecropia.insignis ,
# Cecropia.obtusifolia , Cedrela.odorata ,
# Ceiba.pentandra , Celtis.schippii ,
# Cespedezia.macrophylla , Chamguava.schippii ,
# Chima
his.parviflora , Chlorophora.tinctoria ,
# Chrysochlamys.eclipes ,
# Chrysophyllum.argenteum ,
# Chrysophyllum.cainito , Coccoloba.coronata ,
# Coccoloba.manzanillensis ,
# Colu
ina.glandulosa , Cordia.alliodora ,
# Cordia.bicolor , Cordia.lasiocalyx ,
# Coussarea.curvigemmia , Croton.billbergianus ,
# Cupania.cinerea , Cupania.latifolia ,
# Cupania.rufescens , Cupania.sylvatica ,
# Dendropanax.a
oreus , Desmopsis.panamensis ,
# Diospyros.artanthifolia , Dipteryx.panamensis ,
# Drypetes.standleyi , Elaeis.oleifera ,
# Enterolobium.schomburgkii ,
# Erythrina.costaricensis ,
# Erythroxylum.macrophyllum ,
# Eugenia.coloradensis , Eugenia.galalonensis ,
# Eugenia.nesiotica , Eugenia.oerstedeana ,
# Faramea.occidentalis , Ficus.colu
inae ,
# Ficus.costaricana , Ficus.insipida ,
# Ficus.maxima , Ficus.obtusifolia ,
# Ficus.popenoei , Ficus.tonduzii ,
# Ficus.trigonata , Ficus.yoponensis ,
# Garcinia.intermedia , Garcinia.madruno ,
# Genipa.americana , Guapira.standleyana ,
# Guarea.fuzzy , Guarea.grandifolia ,
# Guarea.guidonia , Guatteria.dumetorum ,
# Guazuma.ulmifolia , Guettarda.foliacea ,
# Gustavia.supe
a , Hampea.appendiculata ,
# Hasseltia.floribunda , Heisteria.acuminata ,
# Heisteria.concinna , Hirtella.americana ,
# Hirtella.triandra , Hura.crepitans ,
# Hyeronima.alchorneoides , Inga.acuminata ,
# Inga.cocleensis , Inga.goldmanii ,
# Inga.laurina , ...
names(BCI)
names(BCI)
[1] "Abarema.macradenium"
[2] "Acacia.melanoceras"
[3] "Acalypha.diversifolia"
[4] "Acalypha.macrostachya"
[5] "Adelia.triloba"
[6] "Aegiphila.panamensis"
[7] "Alchornea.costaricensis"
[8] "Alchornea.latifolia"
[9] "Alibertia.edulis"
[10] "Allophylus.psilospermus"
[11] "Alseis.blackiana"
[12] "Amaioua.corymbosa"
[13] "Anacardium.excelsum"
[14] "Andira.inermis"
[15] "Annona.spraguei"
[16] "Apeiba.aspera"
[17] "Apeiba.tibou
ou"
[18] "Aspidosperma.cruenta"
[19] "Astrocaryum.standleyanum"
[20] "Astronium.graveolens"
[21] "Attalea.butyracea"
[22] "Banara.guianensis"
[23] "Beilschmiedia.pendula"
[24] "Brosimum.alicastrum"
[25] "Brosimum.guianense"
[26] "Calophyllum.longifolium"
[27] "Casearia.aculeata"
[28] "Casearia.a
orea"
[29] "Casearia.commersoniana"
[30] "Casearia.guianensis"
[31] "Casearia.sylvestris"
[32] "Cassipourea.elliptica"
[33] "Cavanillesia.platanifolia"
[34] "Cecropia.insignis"
[35] "Cecropia.obtusifolia"
[36] "Cedrela.odorata"
[37] "Ceiba.pentandra"
[38] "Celtis.schippii"
[39] "Cespedezia.macrophylla"
[40] "Chamguava.schippii"
[41] "Chima
his.parviflora"
[42] "Chlorophora.tinctoria"
[43] "Chrysochlamys.eclipes"
[44] "Chrysophyllum.argenteum"
[45] "Chrysophyllum.cainito"
[46] "Coccoloba.coronata"
[47] "Coccoloba.manzanillensis"
[48] "Colu
ina.glandulosa"
[49] "Cordia.alliodora"
[50] "Cordia.bicolor"
[51] "Cordia.lasiocalyx"
[52] "Coussarea.curvigemmia"
[53] "Croton.billbergianus"
[54] "Cupania.cinerea"
[55] "Cupania.latifolia"
[56] "Cupania.rufescens"
[57] "Cupania.sylvatica"
[58] "Dendropanax.a
oreus"
[59] "Desmopsis.panamensis"
[60] "Diospyros.artanthifolia"
[61] "Dipteryx.panamensis"
[62] "Drypetes.standleyi"
[63] "Elaeis.oleifera"
[64] "Enterolobium.schomburgkii"
[65] "Erythrina.costaricensis"
[66] "Erythroxylum.macrophyllum"
[67] "Eugenia.coloradensis"
[68] "Eugenia.galalonensis"
[69] "Eugenia.nesiotica"
[70] "Eugenia.oerstedeana"
[71] "Faramea.occidentalis"
[72] "Ficus.colu
inae"
[73] "Ficus.costaricana"
[74] "Ficus.insipida"
[75] "Ficus.maxima"
[76] "Ficus.obtusifolia"
[77] "Ficus.popenoei"
[78] "Ficus.tonduzii"
[79] "Ficus.trigonata"
[80] "Ficus.yoponensis"
[81] "Garcinia.intermedia"
[82] "Garcinia.madruno"
[83] "Genipa.americana"
[84] "Guapira.standleyana"
[85] "Guarea.fuzzy"
[86] "Guarea.grandifolia"
[87] "Guarea.guidonia"
[88] "Guatteria.dumetorum"
[89] "Guazuma.ulmifolia"
[90] "Guettarda.foliacea"
[91] "Gustavia.supe
a"
[92] "Hampea.appendiculata"
[93] "Hasseltia.floribunda"
[94] "Heisteria.acuminata"
[95] "Heisteria.concinna"
[96] "Hirtella.americana"
[97] "Hirtella.triandra"
[98] "Hura.crepitans"
[99] "Hyeronima.alchorneoides"
[100] "Inga.acuminata"
[101] "Inga.cocleensis"
[102] "Inga.goldmanii"
[103] "Inga.laurina"
[104] "Inga.marginata"
[105] "Inga.nobilis"
[106] "Inga.oerstediana"
[107] "Inga.pezizifera"
[108] "Inga.punctata"
[109] "Inga.ruiziana"
[110] "Inga.sapindoides"
[111] "Inga.spectabilis"
[112] "Inga.umbellifera"
[113] "Jacaranda.copaia"
[114] "Lacistema.aggregatum"
[115] "Lacmellea.panamensis"
[116] "Laetia.procera"
[117] "Laetia.thamnia"
[118] "Lafoensia.punicifolia"
[119] "Licania.hypoleuca"
[120] "Licania.platypus"
[121] "Lindackeria.laurina"
[122] "Lonchocarpus.latifolius"
[123] "Luehea.seemannii"
[124] "Macrocnemum.roseum"
[125] "Maquira.costaricana"
[126] "Margaritaria.nobilis"
[127] "Marila.laxiflora"
[128] "Maytenus.schippii"
[129] "Miconia.affinis"
[130] "Miconia.argentea"
[131] "Miconia.elata"
[132] "Miconia.hondurensis"
[133] "Mosannona.garwoodii"
[134] "Myrcia.gatunensis"
[135] "Myrospermum.frutescens"
[136] "Nectandra.cissiflora"
[137] "Nectandra.lineata"
[138] "Nectandra.purpurea"
[139] "Ochroma.pyramidale"
[140] "Ocotea.cernua"
[141] "Ocotea.oblonga"
[142] "Ocotea.puberula"
[143] "Ocotea.whitei"
[144] "Oenocarpus.mapora"
[145] "Ormosia.amazonica"
[146] "Ormosia.coccinea"
[147] "Ormosia.macrocalyx"
[148] "Pachira.quinata"
[149] "Pachira.sessilis"
[150] "Perebea.xanthochyma"
[151] "Phoebe.cinnamomifolia"
[152] "Picramnia.latifolia"
[153] "Piper.reticulatum"
[154] "Platymiscium.pinnatum"
[155] "Platypodium.elegans"
[156] "Posoqueria.latifolia"
[157] "Poulsenia.armata"
[158] "Pourouma.bicolor"
[159] "Pouteria.fossicola"
[160] "Pouteria.reticulata"
[161] "Pouteria.stipitata"
[162] "Prioria.copaifera"
[163] "Protium.costaricense"
[164] "Protium.panamense"
[165] "Protium.tenuifolium"
[166] "Pseudobombax.septenatum"
[167] "Psidium.friedrichsthalianum"
[168] "Psychotria.grandis"
[169] "Pterocarpus.rohrii"
[170] "Quararibea.asterolepis"
[171] "Quassia.amara"
[172] "Randia.armata"
[173] "Sapium.
oadleaf"
[174] "Sapium.glandulosum"
[175] "Schizolobium.parahyba"
[176] "Senna.dariensis"
[177] "Simarouba.amara"
[178] "Siparuna.guianensis"
[179] "Siparuna.pauciflora"
[180] "Sloanea.terniflora"
[181] "Socratea.exo
hiza"
[182] "Solanum.hayesii"
[183] "Sorocea.affinis"
[184] "Spachea.mem
anacea"
[185] "Spondias.mombin"
[186] "Spondias.radlkoferi"
[187] "Sterculia.apetala"
[188] "Swartzia.simplex.var.grandiflora"
[189] "Swartzia.simplex.var.ochnacea"
[190] "Symphonia.globulifera"
[191] "Tabebuia.guayacan"
[192] "Tabebuia.rosea"
[193] "Tabernaemontana.a
orea"
[194] "Tachigali.versicolor"
[195] "Talisia.nervosa"
[196] "Talisia.princeps"
[197] "Terminalia.amazonia"
[198] "Terminalia.oblonga"
[199] "Tetragastris.panamensis"
[200] "Tetrathylacium.johansenii"
[201] "Theo
oma.cacao"
[202] "Thevetia.ahouai"
[203] "Tocoyena.pittieri"
[204] "Trattinnickia.aspera"
[205] "Trema.micrantha"
[206] "Trichanthera.gigantea"
[207] "Trichilia.pallida"
[208] "Trichilia.tuberculata"
[209] "Trichospermum.galeottii"
[210] "Triplaris.cumingiana"
[211] "Trophis.caucana"
[212] "Trophis.racemosa"
[213] "Turpinia.occidentalis"
[214] "Unonopsis.pittieri"
[215] "Virola.multiflora"
[216] "Virola.sebifera"
[217] "Virola.surinamensis"
[218] "Vismia.baccifera"
[219] "Vochysia.fe
uginea"
[220] "Xylopia.macrantha"
[221] "Zanthoxylum.ekmanii"
[222] "Zanthoxylum.juniperinum"
[223] "Zanthoxylum.panamense"
[224] "Zanthoxylum.setulosum"
[225] "Zuelania.guidonia"
## use 'apply' to calculate the total number of individuals in each plot
n <- rowSums(BCI)
n
[1] 448 435 463 508 505 412 416 431 409 483 401 366 409 438
[15] 462 437 381 347 433 429 408 418 340 392 442 407 417 387
[29] 364 475 421 459 436 447 601 430 435 447 424 489 402 414
[43] 407 409 444 430 425 415 427 432
apply(BCI, 1, sum)
[1] 448 435 463 508 505 412 416 431 409 483 401 366 409 438
[15] 462 437 381 347 433 429 408 418 340 392 442 407 417 387
[29] 364 475 421 459 436 447 601 430 435 447 424 489 402 414
[43] 407 409 444 430 425 415 427 432
## these are the co-ordinates of each plot
UTM.EW <- rep(seq(625754, 626654, by=100), each=5)
UTM.NS <- rep(seq(1011569, 1011969, by=100), len=50)
## we can plot to look for spatial trends in total abundance
## this is definitely easier using qplot from the ggplot li
ary than the base plot function - if you have it installed...
li
ary(ggplot2)
qplot(UTM.EW, UTM.NS, size = nsp)
## qplot is able to adjust the size of the points automatically...
## to do something similar in the base plot function we would need to do the size adjustment ourselves...
ptsz <- (n-min(n))/(max(n)-min(n))*5+0.5
plot(UTM.EW,UTM.NS,cex=ptsz)
## of course you would follow up with formal statistical tests if you saw something interesting here
## use 'apply' to calculate the mean number of individuals in each plot
apply(BCI,1,function(x) mean(x[x>0]) )
[1] 4.817204 5.178571 5.144444 5.404255 5.000000 4.847059
[7] 5.073171 4.897727 4.544444 5.138298 4.609195 4.357143
[13] 4.397849 4.469388 4.967742 4.698925 4.096774 3.898876
[19] 3.972477 4.290000 4.121212 4.593407 3.434343 4.126316
[25] 4.209524 4.472527 4.212121 4.552941 4.232558 4.896907
[31] 5.467532 5.215909 5.069767 4.858696 7.240964 4.673913
[37] 4.943182 5.451220 5.047619 6.112500 3.941176 4.758621
[43] 4.732558 5.049383 5.481481 5.000000 4.166667 4.560440
[49] 4.692308 4.645161
## now use 'rowSums' and 'rowMeans' to do the same things
owMeans(BCI)
[1] 1.991111 1.933333 2.057778 2.257778 2.244444 1.831111
[7] 1.848889 1.915556 1.817778 2.146667 1.782222 1.626667
[13] 1.817778 1.946667 2.053333 1.942222 1.693333 1.542222
[19] 1.924444 1.906667 1.813333 1.857778 1.511111 1.742222
[25] 1.964444 1.808889 1.853333 1.720000 1.617778 2.111111
[31] 1.871111 2.040000 1.937778 1.986667 2.671111 1.911111
[37] 1.933333 1.986667 1.884444 2.173333 1.786667 1.840000
[43] 1.808889 1.817778 1.973333 1.911111 1.888889 1.844444
[49] 1.897778 1.920000
owSums(BCI)
owSums(BCI>0)
[1] 4.817204 5.178571 5.144444 5.404255 5.000000 4.847059
[7] 5.073171 4.897727 4.544444 5.138298 4.609195 4.357143
[13] 4.397849 4.469388 4.967742 4.698925 4.096774 3.898876
[19] 3.972477 4.290000 4.121212 4.593407 3.434343 4.126316
[25] 4.209524 4.472527 4.212121 4.552941 4.232558 4.896907
[31] 5.467532 5.215909 5.069767 4.858696 7.240964 4.673913
[37] 4.943182 5.451220 5.047619 6.112500 3.941176 4.758621
[43] 4.732558 5.049383 5.481481 5.000000 4.166667 4.560440
[49] 4.692308 4.645161
mean(rowSums(BCI))
[1] 429.14
## now we want to calculate species richness for each plot
## first convert to presence/absence data
BCIPA <- (BCI>0)
## then sum to get richness
nsp <- apply(BCIPA,1,sum)
[1] 93 84 90 94 101 85 82 88 90 94 87 84 93 98
[15] 93 93 93 89 109 100 99 91 99 95 105 91 99 85
[29] 86 97 77 88 86 92 83 92 88 82 84 80 102 87
[43] 86 81 81 86 102 91 91 93
## now use qplot and/or plot to look for spatial patterns in species richness
qplot(UTM.EW, UTM.NS, size = nsp)
## now we want to calculate the Shannon's diversity index for each site (see http:
en.wikipedia.org/wiki/Diversity_index#Shannon_index)
## the function to calculate Shannon's diversity is available in the vegan package (and others), but we will show how to write it here
shannon <- function(x) {
x <- subset(x,x>0)
ps <- x/sum(x)
-sum(ps*log(ps))
}
## use 'apply' to calculate the shannon index for each plot
xx=apply(BCI,1,shannon)
xx
[1] 4.018412 3.848471 3.814060 3.976563 3.969940 3.776575
[7] 3.836811 3.908381 3.761331 3.889803 3.859814 3.698414
[13] 3.982373 4.017494 3.956635 3.916821 3.736897 3.944985
[19] 4.013094 4.077327 3.969925 3.755413 4.062575 3.979427
[25] 4.074718 3.947749 3.980281 3.693896 3.688721 3.851598
[31] 3.724967 3.784873 3.740392 3.821669 2.641859 3.846109
[37] 3.791703 3.516082 3.530494 3.234849 4.052495 3.966614
[43] 3.736254 3.705016 3.609518 3.810489 3.920918 3.913725
[49] 3.778851 3.906616
## plot to look for spatial trends in shannon diversity
## as a challenge you could try to calculate the simpson diversity index for each plot
## use apply and/or colSums to calculate the total number of plots at which each species is found
## use apply and/or colSums to calculate the frequency for each species (ie the proportion of plots at which it is found)
## of course from here you would likely go on to produce some ordinations or dendograms and do some multi-variate analysis
### now what if you wanted to analyse by genus instead of species??
## look carefully at what each of the following lines of code does and see if you can follow - ask if in doubt
names(BCI)[1]
strsplit(names(BCI)[1],".",fixed=TRUE)
strsplit(names(BCI),".",fixed=TRUE)
splitlist <- strsplit(names(BCI),".",fixed=TRUE)
splitlist[[1]][1]
splitlist[[1]][2]
unlist(splitlist)
seq(1,length(unlist(splitlist)),by=2)
unlist(splitlist)[seq(1,length(unlist(splitlist)),by=2)]
[1] "Abarema" "Acacia" "Acalypha"
[4] "Acalypha" "Adelia" "Aegiphila"
[7] "Alchornea" "Alchornea" "Alibertia"
[10] "Allophylus" "Alseis" "Amaioua"
[13] "Anacardium" "Andira" "Annona"
[16] "Apeiba" "Apeiba" "Aspidosperma"
[19] "Astrocaryum" "Astronium" "Attalea"
[22] "Banara" "Beilschmiedia" "Brosimum"
[25] "Brosimum" "Calophyllum" "Casearia"
[28] "Casearia" "Casearia" "Casearia"
[31] "Casearia" "Cassipourea" "Cavanillesia"
[34] "Cecropia" "Cecropia" "Cedrela"
[37] "Ceiba" "Celtis" "Cespedezia"
[40] "Chamguava" "Chima
his" "Chlorophora"
[43] "Chrysochlamys" "Chrysophyllum" "Chrysophyllum"
[46] "Coccoloba" "Coccoloba" "Colu
ina"
[49] "Cordia" "Cordia" "Cordia"
[52] "Coussarea" "Croton" "Cupania"
[55] "Cupania" "Cupania" "Cupania"
[58] "Dendropanax" "Desmopsis" "Diospyros"
[61] "Dipteryx" "Drypetes" "Elaeis"
[64] "Enterolobium" "Erythrina" "Erythroxylum"
[67] "Eugenia" "Eugenia" "Eugenia"
[70] "Eugenia" "Faramea" "Ficus"
[73] "Ficus" "Ficus" "Ficus"
[76] "Ficus" "Ficus" "Ficus"
[79] "Ficus" "Ficus" "Garcinia"
[82] "Garcinia" "Genipa" "Guapira"
[85] "Guarea" "Guarea" "Guarea"
[88] "Guatteria" "Guazuma" "Guettarda"
[91] "Gustavia" "Hampea" "Hasseltia"
[94] "Heisteria" "Heisteria" "Hirtella"
[97] "Hirtella" "Hura" "Hyeronima"
[100] "Inga" "Inga" "Inga"
[103] "Inga" "Inga" "Inga"
[106] "Inga" "Inga" "Inga"
[109] "Inga" "Inga" "Inga"
[112] "Inga" "Jacaranda" "Lacistema"
[115] "Lacmellea" "Laetia" "Laetia"
[118] "Lafoensia" "Licania" "Licania"
[121] "Lindackeria" "Lonchocarpus" "Luehea"
[124] "Macrocnemum" "Maquira" "Margaritaria" ...