Lab 4 Rank Abundance and Co-Occurance Analysis

Beginning Script

library(vegan)
## Loading required package: permute
## Loading required package: lattice
## This is vegan 2.5-4
library(BiodiversityR)
## Loading required package: tcltk
## BiodiversityR 2.11-1: Use command BiodiversityRGUI() to launch the Graphical User Interface; 
## to see changes use BiodiversityRGUI(changeLog=TRUE, backward.compatibility.messages=TRUE)
library(reshape)

beetleImport <- read.csv("C:\\Users\\Gabriela Krochmal\\Desktop\\ConBio_R\\groundBeetleAbundanceSP19.csv")
beetleImport$ID <- paste(beetleImport$habitatCode, beetleImport$replicate, sep= "_")

#reshape long form data into a matrix with cast()
beetle <- cast(beetleImport, ID ~ speciesCode, value= 'abundance')

rownames(beetle) <- beetle$ID #name rows with ID
beetle$ID <- NULL #drop ID column

beetle[is.na(beetle)] <- 0 #replace NA with 0

##Estimating alpha diversity with the vegan package
spBeetle <- specnumber(beetle) #species richness
HBeetle <- diversity(beetle, index="shannon") #Shannon(H')
DBeetle <- diversity(beetle, index="invsimpson") #simpson(1/D)

#making a data frame of the results
diversityResult <- data.frame(spBeetle ,HBeetle, DBeetle)

#importing and merging habitat data
habitat <- read.csv("C:\\Users\\Gabriela Krochmal\\Desktop\\ConBio_R\\groundBeetleHabitatSP19.csv")

#paste two columns together with an underscore
habitat$ID <- paste(habitat$habitatCode, habitat$replicate, sep= "_")

#create data frame
diversityResult <- data.frame(spBeetle, HBeetle, DBeetle)

#create ID column
diversityResult$ID <- rownames(diversityResult)

#merge the two data frames by ID column
beetleDiversity <- merge(diversityResult, habitat, by=c("ID"))

head(beetleDiversity)
##    ID spBeetle  HBeetle  DBeetle habitatCode replicate vegHgt habitat
## 1 E_1       17 1.267096 2.571619           E         1    5.5    Edge
## 2 E_2       14 1.424505 3.179289           E         2   15.0    Edge
## 3 E_3       15 1.412179 3.106648           E         3   15.0    Edge
## 4 E_4       25 1.737146 3.871034           E         4    3.0    Edge
## 5 E_5       21 1.636923 3.684945           E         5    2.5    Edge
## 6 E_6       17 1.557477 3.448558           E         6    2.0    Edge
beetle <- data.frame(beetle)

Question 1

#The top four ranked species in the data set are:
#1 Aba.par
#2 Pte.mad
#3 Cal.rot
#4 Pte.nige

RankAbun1 <- rankabundance(beetle)

#The statistics of the species can be found in:
head(RankAbun1)
##          rank abundance proportion plower pupper accumfreq logabun
## Aba.par     1      4868       40.6   37.9   43.3      40.6     3.7
## Pte.mad     2      3162       26.4   23.7   29.1      67.0     3.5
## Neb.bre     3      1758       14.7   12.4   17.0      81.7     3.2
## Cal.rot     4       765        6.4    4.6    8.2      88.1     2.9
## Pte.nige    5       246        2.1    1.3    2.8      90.2     2.4
## Pte.str     6       211        1.8    0.9    2.6      91.9     2.3
##          rankfreq
## Aba.par       2.1
## Pte.mad       4.2
## Neb.bre       6.2
## Cal.rot       8.3
## Pte.nige     10.4
## Pte.str      12.5
#Plots for abundance and proportion



rankabunplot(RankAbun1, scale="proportion", specnames= c(1:5))

rankabunplot(RankAbun1, scale="abundance", specnames= c(1:5))

#Conclusions I can draw from the plots produced regarding species richness is that this is a pretty diverse data set because there are 48 different species found in all of the ecosystems combined. Although there are alot of species, there are a few that dominate the ecosystem. When looking at the graph you can see that the abundance of all of the other speecies is extremely low (just above 0), while there is an abundance in the thousands of the top ranked species. The evenness can also reflect the abundance because there are so many of certain species so there is not a even distribution of species across the ecosystem.

Question 2

beetleSubE <- beetle[1:6,]
beetleSubG <- beetle[7:12,]
beetleSubW <- beetle[13:18,]

#rank abundance curves for edge habitat
RankAbunSubE1 <- rankabundance(beetleSubE)
rankabunplot(RankAbunSubE1, scale= "proportion", addit= FALSE, specnames=c(1:4))

RankAbunSubE1
##          rank abundance proportion plower pupper accumfreq logabun
## Aba.par     1      2146       44.4   39.4   49.3      44.4     3.3
## Pte.mad     2      1365       28.2   25.9   30.6      72.6     3.1
## Neb.bre     3       624       12.9    9.7   16.1      85.5     2.8
## Cal.rot     4       314        6.5    2.2   10.8      92.0     2.5
## Pte.str     5       101        2.1    1.5    2.6      94.1     2.0
## Pte.nige    6        45        0.9    0.7    1.2      95.1     1.7
## Pte.mel     7        40        0.8    0.4    1.2      95.9     1.6
## Poe.cup     8        38        0.8    0.2    1.4      96.7     1.6
## Pla.ass     9        27        0.6    0.3    0.8      97.2     1.4
## Pte.nigr   10        27        0.6    0.2    0.9      97.8     1.4
## Bem.man    11        18        0.4    0.1    0.6      98.2     1.3
## Sto.pum    12        17        0.4    0.1    0.6      98.5     1.2
## Lei.ful    13        13        0.3    0.0    0.5      98.8     1.1
## Lei.ruf    14        13        0.3   -0.1    0.6      99.0     1.1
## Cal.vio    15        10        0.2    0.1    0.3      99.3     1.0
## Bem.lam    16         5        0.1    0.0    0.2      99.4     0.7
## Lei.fer    17         5        0.1   -0.2    0.4      99.5     0.7
## Lei.spi    18         4        0.1    0.0    0.2      99.5     0.6
## Lor.pil    19         4        0.1   -0.1    0.2      99.6     0.6
## Ocy.har    20         4        0.1   -0.1    0.2      99.7     0.6
## Pte.obl    21         4        0.1    0.0    0.2      99.8     0.6
## Ago.mue    22         3        0.1    0.0    0.2      99.9     0.5
## Har.ruf    23         2        0.0   -0.1    0.1      99.9     0.3
## Pat.atr    24         2        0.0   -0.1    0.1      99.9     0.3
## Bem.big    25         1        0.0    0.0    0.1     100.0     0.0
## Bem.gut    26         1        0.0    0.0    0.1     100.0     0.0
## Cur.aul    27         1        0.0    0.0    0.1     100.0     0.0
## Acu.dub    28         0        0.0    0.0    0.0     100.0    -Inf
## Ago.afr    29         0        0.0    0.0    0.0     100.0    -Inf
## Ago.ful    30         0        0.0    0.0    0.0     100.0    -Inf
## Ago.vid    31         0        0.0    0.0    0.0     100.0    -Inf
## Ama.aen    32         0        0.0    0.0    0.0     100.0    -Inf
## Ama.com    33         0        0.0    0.0    0.0     100.0    -Inf
## Ama.fam    34         0        0.0    0.0    0.0     100.0    -Inf
## Ama.ple    35         0        0.0    0.0    0.0     100.0    -Inf
## Ama.sim    36         0        0.0    0.0    0.0     100.0    -Inf
## Bad.bul    37         0        0.0    0.0    0.0     100.0    -Inf
## Bem.obt    38         0        0.0    0.0    0.0     100.0    -Inf
## Bra.har    39         0        0.0    0.0    0.0     100.0    -Inf
## Bra.sha    40         0        0.0    0.0    0.0     100.0    -Inf
## Cal.fus    41         0        0.0    0.0    0.0     100.0    -Inf
## Cli.fos    42         0        0.0    0.0    0.0     100.0    -Inf
## Cyc.car    43         0        0.0    0.0    0.0     100.0    -Inf
## Not.big    44         0        0.0    0.0    0.0     100.0    -Inf
## Not.ruf    45         0        0.0    0.0    0.0     100.0    -Inf
## Pte.ver    46         0        0.0    0.0    0.0     100.0    -Inf
## Syn.niv    47         0        0.0    0.0    0.0     100.0    -Inf
## Tre.qua    48         0        0.0    0.0    0.0     100.0    -Inf
##          rankfreq
## Aba.par       2.1
## Pte.mad       4.2
## Neb.bre       6.2
## Cal.rot       8.3
## Pte.str      10.4
## Pte.nige     12.5
## Pte.mel      14.6
## Poe.cup      16.7
## Pla.ass      18.8
## Pte.nigr     20.8
## Bem.man      22.9
## Sto.pum      25.0
## Lei.ful      27.1
## Lei.ruf      29.2
## Cal.vio      31.2
## Bem.lam      33.3
## Lei.fer      35.4
## Lei.spi      37.5
## Lor.pil      39.6
## Ocy.har      41.7
## Pte.obl      43.8
## Ago.mue      45.8
## Har.ruf      47.9
## Pat.atr      50.0
## Bem.big      52.1
## Bem.gut      54.2
## Cur.aul      56.2
## Acu.dub      58.3
## Ago.afr      60.4
## Ago.ful      62.5
## Ago.vid      64.6
## Ama.aen      66.7
## Ama.com      68.8
## Ama.fam      70.8
## Ama.ple      72.9
## Ama.sim      75.0
## Bad.bul      77.1
## Bem.obt      79.2
## Bra.har      81.2
## Bra.sha      83.3
## Cal.fus      85.4
## Cli.fos      87.5
## Cyc.car      89.6
## Not.big      91.7
## Not.ruf      93.8
## Pte.ver      95.8
## Syn.niv      97.9
## Tre.qua     100.0
#rank abundance curves for grass habitat
RankAbunSubG1 <- rankabundance(beetleSubG)
rankabunplot(RankAbunSubG1, scale= "proportion", addit= FALSE, specnames=c(1:4))

RankAbunSubG1
##          rank abundance proportion plower pupper accumfreq logabun
## Aba.par     1       709       37.7   29.7   45.6      37.7     2.9
## Pte.mad     2       382       20.3   16.4   24.2      57.9     2.6
## Neb.bre     3       175        9.3    7.6   11.0      67.2     2.2
## Poe.cup     4       107        5.7    4.2    7.2      72.9     2.0
## Pte.str     5       104        5.5    4.2    6.8      78.4     2.0
## Bem.man     6        97        5.2    3.9    6.4      83.6     2.0
## Pte.nige    7        44        2.3    1.7    3.0      85.9     1.6
## Pte.nigr    8        30        1.6    1.1    2.1      87.5     1.5
## Bem.big     9        29        1.5    0.9    2.2      89.1     1.5
## Cli.fos    10        22        1.2    0.6    1.7      90.2     1.3
## Pla.ass    11        22        1.2    0.3    2.0      91.4     1.3
## Sto.pum    12        22        1.2    0.3    2.0      92.6     1.3
## Ago.afr    13        20        1.1    0.2    1.9      93.6     1.3
## Cal.fus    14        20        1.1    0.8    1.3      94.7     1.3
## Cal.rot    15        20        1.1    0.2    1.9      95.8     1.3
## Bem.lam    16        13        0.7    0.3    1.1      96.4     1.1
## Ama.ple    17         7        0.4   -0.1    0.8      96.8     0.8
## Pte.ver    18         7        0.4    0.1    0.7      97.2     0.8
## Not.ruf    19         6        0.3   -0.1    0.7      97.5     0.8
## Syn.niv    20         5        0.3    0.0    0.5      97.8     0.7
## Bad.bul    21         4        0.2    0.0    0.5      98.0     0.6
## Bra.sha    22         4        0.2    0.1    0.4      98.2     0.6
## Not.big    23         4        0.2   -0.1    0.5      98.4     0.6
## Tre.qua    24         4        0.2    0.1    0.3      98.6     0.6
## Acu.dub    25         3        0.2    0.0    0.3      98.8     0.5
## Ago.ful    26         3        0.2   -0.1    0.4      98.9     0.5
## Bem.obt    27         3        0.2    0.0    0.3      99.1     0.5
## Pte.mel    28         3        0.2    0.0    0.3      99.3     0.5
## Ago.vid    29         2        0.1   -0.1    0.3      99.4     0.3
## Ama.aen    30         2        0.1   -0.2    0.4      99.5     0.3
## Ama.fam    31         2        0.1   -0.2    0.4      99.6     0.3
## Bem.gut    32         2        0.1   -0.2    0.4      99.7     0.3
## Ocy.har    33         2        0.1   -0.2    0.4      99.8     0.3
## Ama.com    34         1        0.1   -0.1    0.2      99.8     0.0
## Ama.sim    35         1        0.1   -0.1    0.2      99.9     0.0
## Bra.har    36         1        0.1   -0.1    0.2      99.9     0.0
## Lei.fer    37         1        0.1   -0.1    0.2     100.0     0.0
## Ago.mue    38         0        0.0    0.0    0.0     100.0    -Inf
## Cal.vio    39         0        0.0    0.0    0.0     100.0    -Inf
## Cur.aul    40         0        0.0    0.0    0.0     100.0    -Inf
## Cyc.car    41         0        0.0    0.0    0.0     100.0    -Inf
## Har.ruf    42         0        0.0    0.0    0.0     100.0    -Inf
## Lei.ful    43         0        0.0    0.0    0.0     100.0    -Inf
## Lei.ruf    44         0        0.0    0.0    0.0     100.0    -Inf
## Lei.spi    45         0        0.0    0.0    0.0     100.0    -Inf
## Lor.pil    46         0        0.0    0.0    0.0     100.0    -Inf
## Pat.atr    47         0        0.0    0.0    0.0     100.0    -Inf
## Pte.obl    48         0        0.0    0.0    0.0     100.0    -Inf
##          rankfreq
## Aba.par       2.1
## Pte.mad       4.2
## Neb.bre       6.2
## Poe.cup       8.3
## Pte.str      10.4
## Bem.man      12.5
## Pte.nige     14.6
## Pte.nigr     16.7
## Bem.big      18.8
## Cli.fos      20.8
## Pla.ass      22.9
## Sto.pum      25.0
## Ago.afr      27.1
## Cal.fus      29.2
## Cal.rot      31.2
## Bem.lam      33.3
## Ama.ple      35.4
## Pte.ver      37.5
## Not.ruf      39.6
## Syn.niv      41.7
## Bad.bul      43.8
## Bra.sha      45.8
## Not.big      47.9
## Tre.qua      50.0
## Acu.dub      52.1
## Ago.ful      54.2
## Bem.obt      56.2
## Pte.mel      58.3
## Ago.vid      60.4
## Ama.aen      62.5
## Ama.fam      64.6
## Bem.gut      66.7
## Ocy.har      68.8
## Ama.com      70.8
## Ama.sim      72.9
## Bra.har      75.0
## Lei.fer      77.1
## Ago.mue      79.2
## Cal.vio      81.2
## Cur.aul      83.3
## Cyc.car      85.4
## Har.ruf      87.5
## Lei.ful      89.6
## Lei.ruf      91.7
## Lei.spi      93.8
## Lor.pil      95.8
## Pat.atr      97.9
## Pte.obl     100.0
#rank abundance curves for wood habitat
RankAbunSubW1 <- rankabundance(beetleSubW)
rankabunplot(RankAbunSubW1, scale="proportion", addit= FALSE, specnames =c(1:4))

RankAbunSubW1
##          rank abundance proportion plower pupper accumfreq logabun
## Aba.par     1      2013       38.3   34.6   41.9      38.3     3.3
## Pte.mad     2      1415       26.9   20.3   33.5      65.2     3.2
## Neb.bre     3       959       18.2   14.4   22.0      83.4     3.0
## Cal.rot     4       431        8.2    6.1   10.2      91.6     2.6
## Lei.ruf     5       176        3.3    1.4    5.3      94.9     2.2
## Pte.nige    6       157        3.0    1.3    4.7      97.9     2.2
## Pla.ass     7        49        0.9    0.2    1.6      98.8     1.7
## Cal.vio     8        23        0.4    0.1    0.8      99.3     1.4
## Not.big     9        19        0.4    0.1    0.6      99.6     1.3
## Cyc.car    10         9        0.2    0.1    0.3      99.8     1.0
## Pte.str    11         6        0.1    0.0    0.2      99.9     0.8
## Lei.spi    12         2        0.0    0.0    0.1     100.0     0.3
## Pte.mel    13         2        0.0    0.0    0.1     100.0     0.3
## Acu.dub    14         0        0.0    0.0    0.0     100.0    -Inf
## Ago.afr    15         0        0.0    0.0    0.0     100.0    -Inf
## Ago.ful    16         0        0.0    0.0    0.0     100.0    -Inf
## Ago.mue    17         0        0.0    0.0    0.0     100.0    -Inf
## Ago.vid    18         0        0.0    0.0    0.0     100.0    -Inf
## Ama.aen    19         0        0.0    0.0    0.0     100.0    -Inf
## Ama.com    20         0        0.0    0.0    0.0     100.0    -Inf
## Ama.fam    21         0        0.0    0.0    0.0     100.0    -Inf
## Ama.ple    22         0        0.0    0.0    0.0     100.0    -Inf
## Ama.sim    23         0        0.0    0.0    0.0     100.0    -Inf
## Bad.bul    24         0        0.0    0.0    0.0     100.0    -Inf
## Bem.big    25         0        0.0    0.0    0.0     100.0    -Inf
## Bem.gut    26         0        0.0    0.0    0.0     100.0    -Inf
## Bem.lam    27         0        0.0    0.0    0.0     100.0    -Inf
## Bem.man    28         0        0.0    0.0    0.0     100.0    -Inf
## Bem.obt    29         0        0.0    0.0    0.0     100.0    -Inf
## Bra.har    30         0        0.0    0.0    0.0     100.0    -Inf
## Bra.sha    31         0        0.0    0.0    0.0     100.0    -Inf
## Cal.fus    32         0        0.0    0.0    0.0     100.0    -Inf
## Cli.fos    33         0        0.0    0.0    0.0     100.0    -Inf
## Cur.aul    34         0        0.0    0.0    0.0     100.0    -Inf
## Har.ruf    35         0        0.0    0.0    0.0     100.0    -Inf
## Lei.fer    36         0        0.0    0.0    0.0     100.0    -Inf
## Lei.ful    37         0        0.0    0.0    0.0     100.0    -Inf
## Lor.pil    38         0        0.0    0.0    0.0     100.0    -Inf
## Not.ruf    39         0        0.0    0.0    0.0     100.0    -Inf
## Ocy.har    40         0        0.0    0.0    0.0     100.0    -Inf
## Pat.atr    41         0        0.0    0.0    0.0     100.0    -Inf
## Poe.cup    42         0        0.0    0.0    0.0     100.0    -Inf
## Pte.nigr   43         0        0.0    0.0    0.0     100.0    -Inf
## Pte.obl    44         0        0.0    0.0    0.0     100.0    -Inf
## Pte.ver    45         0        0.0    0.0    0.0     100.0    -Inf
## Sto.pum    46         0        0.0    0.0    0.0     100.0    -Inf
## Syn.niv    47         0        0.0    0.0    0.0     100.0    -Inf
## Tre.qua    48         0        0.0    0.0    0.0     100.0    -Inf
##          rankfreq
## Aba.par       2.1
## Pte.mad       4.2
## Neb.bre       6.2
## Cal.rot       8.3
## Lei.ruf      10.4
## Pte.nige     12.5
## Pla.ass      14.6
## Cal.vio      16.7
## Not.big      18.8
## Cyc.car      20.8
## Pte.str      22.9
## Lei.spi      25.0
## Pte.mel      27.1
## Acu.dub      29.2
## Ago.afr      31.2
## Ago.ful      33.3
## Ago.mue      35.4
## Ago.vid      37.5
## Ama.aen      39.6
## Ama.com      41.7
## Ama.fam      43.8
## Ama.ple      45.8
## Ama.sim      47.9
## Bad.bul      50.0
## Bem.big      52.1
## Bem.gut      54.2
## Bem.lam      56.2
## Bem.man      58.3
## Bem.obt      60.4
## Bra.har      62.5
## Bra.sha      64.6
## Cal.fus      66.7
## Cli.fos      68.8
## Cur.aul      70.8
## Har.ruf      72.9
## Lei.fer      75.0
## Lei.ful      77.1
## Lor.pil      79.2
## Not.ruf      81.2
## Ocy.har      83.3
## Pat.atr      85.4
## Poe.cup      87.5
## Pte.nigr     89.6
## Pte.obl      91.7
## Pte.ver      93.8
## Sto.pum      95.8
## Syn.niv      97.9
## Tre.qua     100.0
#Rank Abundance curves for all three habitats using proportion
rankabuncomp(beetle, y=habitat, factor="habitatCode", scale="proportion", legend=FALSE)

#rank abundance curves for all three habitats using raw abundance
rankabuncomp(beetle, y=habitat, factor="habitatCode", scale="abundance", legend=FALSE)

#The top ranked species in the Edge habitat are Aba.par, Pte.mad, Neb.bre, and Cal.rot. The abundance for Aba.park is 2,146.. 1,365 for Pte.mad, 624 for Neb.bre, and 314 for Cal.rot. 44% of this ecosystem is dominated by Aba.par, which provides insight that this ecosystem does not have an equal spread of species. In the Grassland habitat, the top 4 ranked species are Aba.par, Pte.mad, Neb.bre, and Poe.cup. The first ranked species Aba.par has a total abundance of 709, followed by 382 for Pte.mad, 175 for Neb.bre, and 107 for Poe.cup. This habitat has a large diversity but again only a few species dominate so it is not that even. In the Woodland habitat, the top ranked species are Aba.par, Pte.mad, Neb.bre, and Cal.rot. Their abundances are.. 2,013 for Aba.par, 1,415 for Pte.mad, 959 for Neb.bre, and 431 for Cal.rot. As in all of the other ecosystem, Aba.par dominates with a proportion of 38.3%. Comparing all of the top ranked species in the ecosystems, we can see that Aba.par by far is the most abundant species that is typically followed by Pte.mad and Neb.bre. 

Question 3

#There are many insect sampling challenges that I  can be faced with as a graduate student in a tropical rainforest. The first challenge is that insects are hard to find because they are tiny and it requires a multitude of insect collecting techniques. I could be very bad at collecting insects so that can make my data bias if I am unable to collect an accurate representation of the ecosystem. The second difficulty I can be faced with is the limited taxonomic work done on insects so it can be hard to define species and understand who lives in the ecosystem. Lastly, insects are cryptic organisms.  

Question 4

#After interpreting Figure 2, I was able to rank the treatment levels from the most representative sampling effort to the least representative sample effort. The most representative sample begins with 50m followed by 500m, 1070m, 1500m, and lastly 2000m. The general trend was that the smaller the area size correlates with a larger sample size. Having a larger sample size can be more representative of how many species are there. These numbers so make sense when re-evaluating accumulation curves I produced earlier because 

Question 5

#species accumulation curves for the full dataset
beetleAccum <- specaccum(beetle, method="random", permutation = 1000)

plot(beetleAccum, ci.type="poly", col="blue", lwd=2, ci.lty=0, ci.col="lightblue")

boxplot(beetleAccum, col="yellow", add=TRUE)

beetleAccum
## Species Accumulation Curve
## Accumulation method: random, with 1000 permutations
## Call: specaccum(comm = beetle, method = "random", permutations = 1000) 
## 
##                                                                     
## Sites     1.000000  2.000000  3.000000  4.000000  5.000000  6.000000
## Richness 18.149000 25.210000 29.516000 32.885000 35.507000 37.536000
## sd        6.054871  6.713641  6.491832  6.163584  5.612972  5.128255
##                                                                     
## Sites     7.000000  8.000000  9.000000 10.000000 11.000000 12.000000
## Richness 39.117000 40.490000 41.739000 42.806000 43.747000 44.534000
## sd        4.687353  4.311901  3.845213  3.326474  2.932847  2.561915
##                                                              
## Sites    13.000000 14.000000 15.000000 16.000000 17.000000 18
## Richness 45.217000 45.893000 46.488000 47.011000 47.499000 48
## sd        2.295033  1.970643  1.603255  1.298678  0.872215  0
#mean and sd richness should be similar to sampling one site
mean(diversityResult$spBeetle)
## [1] 17.944444
sd(diversityResult$spBeetle)
## [1] 6.2823021
#When looking at our species accumulation curve we can ensure that we had a good sampling effort because we hit our asymtote relatively quickly. My sampling conclusions for the individual habitats are not different than my conclusions for the whole data set because each site had 6 plots with richness numbers in the same range. 

Question 6

beetlePool <- specpool(beetle)

#species column: number of unique species
#chao column: total species estimator
#n column: number of sites in the sample

#estimated species richness by habitat
beetlePoolSub <- specpool(beetle, habitat$habitatCode)

specnumber(beetle) #species richness per site
## E_1 E_2 E_3 E_4 E_5 E_6 G_1 G_2 G_3 G_4 G_5 G_6 W_1 W_2 W_3 W_4 W_5 W_6 
##  17  14  15  25  21  17  28  22  18  28  26  24  12  11  11  12  12  10
specpool2vect(beetlePoolSub) #estimated total species per habitat
##  [1] 32.000000 32.000000 32.000000 32.000000 32.000000 32.000000 43.666667
##  [8] 43.666667 43.666667 43.666667 43.666667 43.666667 13.000000 13.000000
## [15] 13.000000 13.000000 13.000000 13.000000
#ratio of observed richness/estimated total species richness
unobsSpRatio <- specnumber(beetle) / specpool2vect(beetlePoolSub)

#boxplot
boxplot(unobsSpRatio ~ habitat$habitatCode)

#Conclusions that I can make regarding the sampling effort and the estimation of unobserved species in each beetle habitat is that we did a really good job for woodlands because our estimated amount of species was 13 and we actually found 13. For grasslands we were a bit off because we estimated that we would observe about 50 when we actually observed 37, so our sampling wasn't great here. For Edge we estimated that we would find 27 species and we found 32, so our sampling was decent here. These numbers make sense when reevaluating the curves I produced earlier because we had good enough sampling to see an asymtote earlier. 

Question 7

#If i was using this ground beetle dataset for a research project, I would not feel extremely confident in my species diversity estimates because for the most part our estimated numbers were not always near the actual number we collected and some of the ecosystems were not sampled the best they could have been.

Question 8

#Compare and contrast the beta-diversity results using the Jaccard Index vs the Bray-Curtis index

library(betapart) #new library for assessing jaccard index
beetleJac <- ifelse(beetle > 0,1,0) #presence/absence data

beetleBeta <- beta.pair(beetleJac, index.family="jaccard")
attributes(beetleBeta) #gives us information on the object
## $names
## [1] "beta.jtu" "beta.jne" "beta.jac"
beetleBeta$beta.jtu #turnover partition between sites
##             E_1         E_2         E_3         E_4         E_5
## E_2 0.000000000                                                
## E_3 0.000000000 0.000000000                                    
## E_4 0.111111111 0.000000000 0.000000000                        
## E_5 0.000000000 0.000000000 0.000000000 0.090909091            
## E_6 0.300000000 0.133333333 0.235294118 0.111111111 0.111111111
## G_1 0.380952381 0.250000000 0.333333333 0.648648649 0.551724138
## G_2 0.380952381 0.352941176 0.421052632 0.625000000 0.551724138
## G_3 0.454545455 0.352941176 0.421052632 0.500000000 0.500000000
## G_4 0.454545455 0.352941176 0.421052632 0.611111111 0.600000000
## G_5 0.380952381 0.250000000 0.333333333 0.648648649 0.551724138
## G_6 0.454545455 0.352941176 0.421052632 0.666666667 0.600000000
## W_1 0.500000000 0.500000000 0.500000000 0.285714286 0.285714286
## W_2 0.428571429 0.428571429 0.428571429 0.307692308 0.307692308
## W_3 0.533333333 0.533333333 0.533333333 0.307692308 0.307692308
## W_4 0.400000000 0.400000000 0.400000000 0.285714286 0.285714286
## W_5 0.400000000 0.400000000 0.400000000 0.285714286 0.285714286
## W_6 0.461538462 0.461538462 0.461538462 0.333333333 0.333333333
##             E_6         G_1         G_2         G_3         G_4
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1 0.300000000                                                
## G_2 0.380952381 0.240000000                                    
## G_3 0.380952381 0.105263158 0.285714286                        
## G_4 0.380952381 0.352941176 0.240000000 0.105263158            
## G_5 0.300000000 0.266666667 0.307692308 0.105263158 0.322580645
## G_6 0.380952381 0.222222222 0.240000000 0.105263158 0.153846154
## W_1 0.285714286 0.500000000 0.500000000 0.588235294 0.500000000
## W_2 0.307692308 0.428571429 0.428571429 0.533333333 0.428571429
## W_3 0.307692308 0.533333333 0.533333333 0.625000000 0.533333333
## W_4 0.285714286 0.400000000 0.500000000 0.500000000 0.500000000
## W_5 0.285714286 0.400000000 0.500000000 0.500000000 0.500000000
## W_6 0.333333333 0.461538462 0.461538462 0.571428571 0.461538462
##             G_5         G_6         W_1         W_2         W_3
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1                                                            
## G_2                                                            
## G_3                                                            
## G_4                                                            
## G_5                                                            
## G_6 0.153846154                                                
## W_1 0.588235294 0.588235294                                    
## W_2 0.533333333 0.533333333 0.000000000                        
## W_3 0.625000000 0.625000000 0.000000000 0.166666667            
## W_4 0.500000000 0.588235294 0.153846154 0.000000000 0.166666667
## W_5 0.500000000 0.588235294 0.153846154 0.000000000 0.166666667
## W_6 0.571428571 0.571428571 0.000000000 0.000000000 0.181818182
##             W_4         W_5
## E_2                        
## E_3                        
## E_4                        
## E_5                        
## E_6                        
## G_1                        
## G_2                        
## G_3                        
## G_4                        
## G_5                        
## G_6                        
## W_1                        
## W_2                        
## W_3                        
## W_4                        
## W_5 0.000000000            
## W_6 0.000000000 0.000000000
beetleBeta$beta.jne #nestedness partition between sites
##              E_1          E_2          E_3          E_4          E_5
## E_2 0.1764705882                                                    
## E_3 0.1176470588 0.0666666667                                       
## E_4 0.2735042735 0.4400000000 0.4000000000                          
## E_5 0.1904761905 0.3333333333 0.2857142857 0.1398601399             
## E_6 0.0000000000 0.1444444444 0.0804953560 0.2735042735 0.1616161616
## G_1 0.2127976190 0.3500000000 0.2795698925 0.0263513514 0.0871647510
## G_2 0.1190476190 0.2070588235 0.1558704453 0.0321428571 0.0149425287
## G_3 0.0237154150 0.1232492997 0.0789473684 0.1129032258 0.0555555556
## G_4 0.1818181818 0.2922201139 0.2351973684 0.0299145299 0.0756756757
## G_5 0.1857142857 0.3214285714 0.2528735632 0.0092460882 0.0659229209
## G_6 0.1316614420 0.2396514161 0.1860902256 0.0090090090 0.0363636364
## W_1 0.1190476190 0.0555555556 0.0789473684 0.3439153439 0.2795031056
## W_2 0.1714285714 0.1008403361 0.1269841270 0.3589743590 0.3010033445
## W_3 0.1333333333 0.0777777778 0.0982456140 0.3589743590 0.3010033445
## W_4 0.1500000000 0.0705882353 0.1000000000 0.3439153439 0.2795031056
## W_5 0.1500000000 0.0705882353 0.1000000000 0.3439153439 0.2795031056
## W_6 0.1884615385 0.1266968326 0.1495726496 0.3703703704 0.3188405797
##              E_6          G_1          G_2          G_3          G_4
## E_2                                                                 
## E_3                                                                 
## E_4                                                                 
## E_5                                                                 
## E_6                                                                 
## G_1 0.2483870968                                                    
## G_2 0.1190476190 0.1470967742                                       
## G_3 0.0281385281 0.3085299456 0.1142857143                          
## G_4 0.2127976190 0.0000000000 0.1470967742 0.3085299456             
## G_5 0.2172413793 0.0458333333 0.0923076923 0.2651072125 0.0410557185
## G_6 0.1547619048 0.1003584229 0.0562962963 0.2147368421 0.1128205128
## W_1 0.1879699248 0.2500000000 0.1923076923 0.1074168798 0.2500000000
## W_2 0.2186234818 0.3133640553 0.2514285714 0.1484848485 0.3133640553
## W_3 0.2186234818 0.2479166667 0.1974358974 0.1141304348 0.2479166667
## W_4 0.1879699248 0.3096774194 0.1923076923 0.1363636364 0.2500000000
## W_5 0.1879699248 0.3096774194 0.1923076923 0.1363636364 0.2500000000
## W_6 0.2456140351 0.3126550868 0.2584615385 0.1558441558 0.3126550868
##              G_5          G_6          W_1          W_2          W_3
## E_2                                                                 
## E_3                                                                 
## E_4                                                                 
## E_5                                                                 
## E_6                                                                 
## G_1                                                                 
## G_2                                                                 
## G_3                                                                 
## G_4                                                                 
## G_5                                                                 
## G_6 0.0604395604                                                    
## W_1 0.1859582543 0.1703853955                                       
## W_2 0.2333333333 0.2166666667 0.0833333333                          
## W_3 0.1814516129 0.1681034483 0.0833333333 0.0000000000             
## W_4 0.2333333333 0.1703853955 0.0000000000 0.0833333333 0.0641025641
## W_5 0.2333333333 0.1703853955 0.0000000000 0.0833333333 0.0641025641
## W_6 0.2285714286 0.2142857143 0.1666666667 0.0909090909 0.0681818182
##              W_4          W_5
## E_2                          
## E_3                          
## E_4                          
## E_5                          
## E_6                          
## G_1                          
## G_2                          
## G_3                          
## G_4                          
## G_5                          
## G_6                          
## W_1                          
## W_2                          
## W_3                          
## W_4                          
## W_5 0.0000000000             
## W_6 0.1666666667 0.1666666667
beetleBeta$beta.jac #beta diversity between sites
##             E_1         E_2         E_3         E_4         E_5
## E_2 0.176470588                                                
## E_3 0.117647059 0.066666667                                    
## E_4 0.384615385 0.440000000 0.400000000                        
## E_5 0.190476190 0.333333333 0.285714286 0.230769231            
## E_6 0.300000000 0.277777778 0.315789474 0.384615385 0.272727273
## G_1 0.593750000 0.600000000 0.612903226 0.675000000 0.638888889
## G_2 0.500000000 0.560000000 0.576923077 0.657142857 0.566666667
## G_3 0.478260870 0.476190476 0.500000000 0.612903226 0.555555556
## G_4 0.636363636 0.645161290 0.656250000 0.641025641 0.675675676
## G_5 0.566666667 0.571428571 0.586206897 0.657894737 0.617647059
## G_6 0.586206897 0.592592593 0.607142857 0.675675676 0.636363636
## W_1 0.619047619 0.555555556 0.578947368 0.629629630 0.565217391
## W_2 0.600000000 0.529411765 0.555555556 0.666666667 0.608695652
## W_3 0.666666667 0.611111111 0.631578947 0.666666667 0.608695652
## W_4 0.550000000 0.470588235 0.500000000 0.629629630 0.565217391
## W_5 0.550000000 0.470588235 0.500000000 0.629629630 0.565217391
## W_6 0.650000000 0.588235294 0.611111111 0.703703704 0.652173913
##             E_6         G_1         G_2         G_3         G_4
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1 0.548387097                                                
## G_2 0.500000000 0.387096774                                    
## G_3 0.409090909 0.413793103 0.400000000                        
## G_4 0.593750000 0.352941176 0.387096774 0.413793103            
## G_5 0.517241379 0.312500000 0.400000000 0.370370370 0.363636364
## G_6 0.535714286 0.322580645 0.296296296 0.320000000 0.266666667
## W_1 0.473684211 0.750000000 0.692307692 0.695652174 0.750000000
## W_2 0.526315789 0.741935484 0.680000000 0.681818182 0.741935484
## W_3 0.526315789 0.781250000 0.730769231 0.739130435 0.781250000
## W_4 0.473684211 0.709677419 0.692307692 0.636363636 0.750000000
## W_5 0.473684211 0.709677419 0.692307692 0.636363636 0.750000000
## W_6 0.578947368 0.774193548 0.720000000 0.727272727 0.774193548
##             G_5         G_6         W_1         W_2         W_3
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1                                                            
## G_2                                                            
## G_3                                                            
## G_4                                                            
## G_5                                                            
## G_6 0.214285714                                                
## W_1 0.774193548 0.758620690                                    
## W_2 0.766666667 0.750000000 0.083333333                        
## W_3 0.806451613 0.793103448 0.083333333 0.166666667            
## W_4 0.733333333 0.758620690 0.153846154 0.083333333 0.230769231
## W_5 0.733333333 0.758620690 0.153846154 0.083333333 0.230769231
## W_6 0.800000000 0.785714286 0.166666667 0.090909091 0.250000000
##             W_4         W_5
## E_2                        
## E_3                        
## E_4                        
## E_5                        
## E_6                        
## G_1                        
## G_2                        
## G_3                        
## G_4                        
## G_5                        
## G_6                        
## W_1                        
## W_2                        
## W_3                        
## W_4                        
## W_5 0.000000000            
## W_6 0.166666667 0.166666667
plotBeta <- betadisper(beetleBeta$beta.jac, habitat$habitatCode)
plot(plotBeta)

anova(plotBeta)
## Analysis of Variance Table
## 
## Response: Distances
##           Df    Sum Sq    Mean Sq F value   Pr(>F)  
## Groups     2 0.0482585 0.02412923 5.31927 0.017947 *
## Residuals 15 0.0680429 0.00453619                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
TukeyHSD(plotBeta)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##             diff          lwr          upr      p adj
## G-E  0.039835908 -0.061167441  0.140839256 0.57341463
## W-E -0.084362641 -0.185365990  0.016640707 0.10934484
## W-G -0.124198549 -0.225201897 -0.023195200 0.01567444
beetleBray <- bray.part(beetle)
attributes(beetleBray)
## $names
## [1] "bray.bal" "bray.gra" "bray"
beetleBray$bray #beta diversity with abundance data
##             E_1         E_2         E_3         E_4         E_5
## E_2 0.118012422                                                
## E_3 0.143277002 0.085507246                                    
## E_4 0.151706700 0.109306683 0.153998678                        
## E_5 0.157769870 0.147214076 0.207173779 0.085963003            
## E_6 0.133663366 0.146177370 0.190691661 0.075791855 0.081196581
## G_1 0.470370370 0.472247498 0.430267062 0.509740260 0.544910180
## G_2 0.526946108 0.523996082 0.489817792 0.558058925 0.588235294
## G_3 0.632608696 0.633652822 0.588719154 0.662313433 0.688775510
## G_4 0.541389153 0.543925234 0.509164969 0.552784705 0.596021423
## G_5 0.480446927 0.487648673 0.446766169 0.512234910 0.550375940
## G_6 0.529636711 0.524882629 0.488229273 0.540901503 0.583717358
## W_1 0.248478141 0.234392114 0.291139241 0.189382338 0.115850703
## W_2 0.189920098 0.157958688 0.209242619 0.156829680 0.144981413
## W_3 0.256427159 0.184895833 0.214088398 0.213900539 0.218274112
## W_4 0.257142857 0.155137676 0.177730193 0.166461159 0.173812283
## W_5 0.265459088 0.170370370 0.194516971 0.155733029 0.134087237
## W_6 0.216481360 0.136950904 0.160273973 0.158834027 0.163025210
##             E_6         G_1         G_2         G_3         G_4
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1 0.532385466                                                
## G_2 0.579124579 0.217791411                                    
## G_3 0.683544304 0.291228070 0.207317073                        
## G_4 0.578011318 0.243937233 0.146067416 0.256931608            
## G_5 0.534920635 0.165745856 0.148606811 0.287234043 0.125179856
## G_6 0.563311688 0.235632184 0.132686084 0.253731343 0.103448276
## W_1 0.146011039 0.633493480 0.676577230 0.759444873 0.684873950
## W_2 0.169332598 0.581832420 0.628023353 0.720680394 0.639423077
## W_3 0.247210804 0.544130249 0.594123049 0.692154916 0.606326889
## W_4 0.196859903 0.519642857 0.570057582 0.670833333 0.589367553
## W_5 0.162842753 0.571542766 0.619778346 0.712190651 0.633387889
## W_6 0.194169096 0.552162850 0.596730245 0.695780177 0.619130435
##             G_5         G_6         W_1         W_2         W_3
## E_2                                                            
## E_3                                                            
## E_4                                                            
## E_5                                                            
## E_6                                                            
## G_1                                                            
## G_2                                                            
## G_3                                                            
## G_4                                                            
## G_5                                                            
## G_6 0.124637681                                                
## W_1 0.647139904 0.669711876                                    
## W_2 0.597167585 0.621882542 0.169660679                        
## W_3 0.560723514 0.586937335 0.240760296 0.093348891            
## W_4 0.536804309 0.572744015 0.223605847 0.139772046 0.201027617
## W_5 0.587148594 0.618734593 0.166835187 0.134593993 0.190758294
## W_6 0.568627451 0.603493450 0.203567681 0.069524913 0.110148515
##             W_4         W_5
## E_2                        
## E_3                        
## E_4                        
## E_5                        
## E_6                        
## G_1                        
## G_2                        
## G_3                        
## G_4                        
## G_5                        
## G_6                        
## W_1                        
## W_2                        
## W_3                        
## W_4                        
## W_5 0.083485679            
## W_6 0.107711918 0.104705882
plotBray <- betadisper(beetleBray$bray, habitat$habitatCode)
plot(plotBray)

anova(plotBray)
## Analysis of Variance Table
## 
## Response: Distances
##           Df    Sum Sq    Mean Sq F value  Pr(>F)
## Groups     2 0.0046519 0.00232597 1.05675 0.37209
## Residuals 15 0.0330159 0.00220106
TukeyHSD(plotBray)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = distances ~ group, data = df)
## 
## $group
##              diff          lwr         upr      p adj
## G-E  0.0371786930 -0.033178127 0.107535513 0.37936206
## W-E  0.0073514026 -0.063005417 0.077708222 0.96031491
## W-G -0.0298272904 -0.100184110 0.040529529 0.52792832
#The Jaccard Index is looking at the list of species richness, and they will get a 1 or 0 if they are present or not. If our different habitat types are similar they will be close to eachother or on top of eachother;as they get further away from eachother then the more different they are. The ANOVA actually tells us that its different and the Tukey HSD test can tell us the differences between ecosystems. Grasslands and Edge are very similar because the pvalue is 0.57. Woods and Edge are a little similar because the pvalue is 0.10, while Wood and Grasslands are very different because the pvalue is 0.01. Using the Bray-Curtis Index we get different results. The Grasslands and Edge are similar because the p-value is 0.37, Woods and Edge are also very similar because the pvalue is 0.96, and lastly woods and grasslands are also similar with a pvalue of 0.52. 

Question 9

library(cooccur)
beetleCOImport <- t(beetle)
beetleCO <- ifelse(beetleCOImport > 1, 1, beetleCOImport)

cooccur.beetles <- cooccur(mat = beetleCO, type= "spp_site", thresh= TRUE, spp_names=TRUE)
## 
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |                                                                 |   1%
  |                                                                       
  |=                                                                |   1%
  |                                                                       
  |=                                                                |   2%
  |                                                                       
  |==                                                               |   2%
  |                                                                       
  |==                                                               |   3%
  |                                                                       
  |==                                                               |   4%
  |                                                                       
  |===                                                              |   4%
  |                                                                       
  |                                                                 |   0%
  |                                                                       
  |=====                                                            |   7%
  |                                                                       
  |=====                                                            |   8%
  |                                                                       
  |======                                                           |   9%
  |                                                                       
  |======                                                           |  10%
  |                                                                       
  |=======                                                          |  10%
  |                                                                       
  |=======                                                          |  11%
  |                                                                       
  |========                                                         |  12%
  |                                                                       
  |========                                                         |  13%
  |                                                                       
  |=========                                                        |  13%
  |                                                                       
  |=========                                                        |  14%
  |                                                                       
  |=========                                                        |  15%
  |                                                                       
  |==========                                                       |  15%
  |                                                                       
  |==========                                                       |  16%
  |                                                                       
  |===========                                                      |  16%
  |                                                                       
  |===========                                                      |  17%
  |                                                                       
  |===========                                                      |  18%
  |                                                                       
  |============                                                     |  18%
  |                                                                       
  |============                                                     |  19%
  |                                                                       
  |=============                                                    |  19%
  |                                                                       
  |=============                                                    |  20%
  |                                                                       
  |=============                                                    |  21%
  |                                                                       
  |==============                                                   |  21%
  |                                                                       
  |==============                                                   |  22%
  |                                                                       
  |===============                                                  |  22%
  |                                                                       
  |===============                                                  |  23%
  |                                                                       
  |===============                                                  |  24%
  |                                                                       
  |================                                                 |  24%
  |                                                                       
  |================                                                 |  25%
  |                                                                       
  |=================                                                |  26%
  |                                                                       
  |=================                                                |  27%
  |                                                                       
  |==================                                               |  27%
  |                                                                       
  |==================                                               |  28%
  |                                                                       
  |===================                                              |  29%
  |                                                                       
  |===================                                              |  30%
  |                                                                       
  |====================                                             |  30%
  |                                                                       
  |====================                                             |  31%
  |                                                                       
  |====================                                             |  32%
  |                                                                       
  |=====================                                            |  32%
  |                                                                       
  |=====================                                            |  33%
  |                                                                       
  |======================                                           |  33%
  |                                                                       
  |======================                                           |  34%
  |                                                                       
  |======================                                           |  35%
  |                                                                       
  |=======================                                          |  35%
  |                                                                       
  |=======================                                          |  36%
  |                                                                       
  |========================                                         |  36%
  |                                                                       
  |========================                                         |  37%
  |                                                                       
  |========================                                         |  38%
  |                                                                       
  |=========================                                        |  38%
  |                                                                       
  |=========================                                        |  39%
  |                                                                       
  |==========================                                       |  39%
  |                                                                       
  |==========================                                       |  40%
  |                                                                       
  |==========================                                       |  41%
  |                                                                       
  |===========================                                      |  41%
  |                                                                       
  |===========================                                      |  42%
  |                                                                       
  |============================                                     |  42%
  |                                                                       
  |============================                                     |  43%
  |                                                                       
  |============================                                     |  44%
  |                                                                       
  |=============================                                    |  44%
  |                                                                       
  |=============================                                    |  45%
  |                                                                       
  |==============================                                   |  45%
  |                                                                       
  |==============================                                   |  46%
  |                                                                       
  |==============================                                   |  47%
  |                                                                       
  |===============================                                  |  47%
  |                                                                       
  |===============================                                  |  48%
  |                                                                       
  |================================                                 |  49%
  |                                                                       
  |================================                                 |  50%
  |                                                                       
  |=================================                                |  50%
  |                                                                       
  |=================================                                |  51%
  |                                                                       
  |==================================                               |  52%
  |                                                                       
  |==================================                               |  53%
  |                                                                       
  |===================================                              |  53%
  |                                                                       
  |===================================                              |  54%
  |                                                                       
  |===================================                              |  55%
  |                                                                       
  |====================================                             |  55%
  |                                                                       
  |====================================                             |  56%
  |                                                                       
  |=====================================                            |  56%
  |                                                                       
  |=====================================                            |  57%
  |                                                                       
  |=====================================                            |  58%
  |                                                                       
  |======================================                           |  58%
  |                                                                       
  |======================================                           |  59%
  |                                                                       
  |=======================================                          |  59%
  |                                                                       
  |=======================================                          |  60%
  |                                                                       
  |=======================================                          |  61%
  |                                                                       
  |========================================                         |  61%
  |                                                                       
  |========================================                         |  62%
  |                                                                       
  |=========================================                        |  62%
  |                                                                       
  |=========================================                        |  63%
  |                                                                       
  |=========================================                        |  64%
  |                                                                       
  |==========================================                       |  64%
  |                                                                       
  |==========================================                       |  65%
  |                                                                       
  |===========================================                      |  65%
  |                                                                       
  |===========================================                      |  66%
  |                                                                       
  |===========================================                      |  67%
  |                                                                       
  |============================================                     |  67%
  |                                                                       
  |============================================                     |  68%
  |                                                                       
  |=============================================                    |  68%
  |                                                                       
  |=============================================                    |  69%
  |                                                                       
  |=============================================                    |  70%
  |                                                                       
  |==============================================                   |  70%
  |                                                                       
  |==============================================                   |  71%
  |                                                                       
  |===============================================                  |  72%
  |                                                                       
  |===============================================                  |  73%
  |                                                                       
  |================================================                 |  73%
  |                                                                       
  |================================================                 |  74%
  |                                                                       
  |=================================================                |  75%
  |                                                                       
  |=================================================                |  76%
  |                                                                       
  |==================================================               |  76%
  |                                                                       
  |==================================================               |  77%
  |                                                                       
  |==================================================               |  78%
  |                                                                       
  |===================================================              |  78%
  |                                                                       
  |===================================================              |  79%
  |                                                                       
  |====================================================             |  79%
  |                                                                       
  |====================================================             |  80%
  |                                                                       
  |====================================================             |  81%
  |                                                                       
  |=====================================================            |  81%
  |                                                                       
  |=====================================================            |  82%
  |                                                                       
  |======================================================           |  82%
  |                                                                       
  |======================================================           |  83%
  |                                                                       
  |======================================================           |  84%
  |                                                                       
  |=======================================================          |  84%
  |                                                                       
  |=======================================================          |  85%
  |                                                                       
  |========================================================         |  85%
  |                                                                       
  |========================================================         |  86%
  |                                                                       
  |========================================================         |  87%
  |                                                                       
  |=========================================================        |  87%
  |                                                                       
  |=========================================================        |  88%
  |                                                                       
  |==========================================================       |  89%
  |                                                                       
  |==========================================================       |  90%
  |                                                                       
  |===========================================================      |  90%
  |                                                                       
  |===========================================================      |  91%
  |                                                                       
  |============================================================     |  92%
  |                                                                       
  |============================================================     |  93%
  |                                                                       
  |=============================================================    |  93%
  |                                                                       
  |=============================================================    |  94%
  |                                                                       
  |=============================================================    |  95%
  |                                                                       
  |==============================================================   |  95%
  |                                                                       
  |==============================================================   |  96%
  |                                                                       
  |===============================================================  |  96%
  |                                                                       
  |===============================================================  |  97%
  |                                                                       
  |===============================================================  |  98%
  |                                                                       
  |================================================================ |  98%
  |                                                                       
  |================================================================ |  99%
  |                                                                       
  |=================================================================|  99%
  |                                                                       
  |=================================================================| 100%
head(cooccur.beetles$results)
##   sp1 sp2 sp1_inc sp2_inc obs_cooccur prob_cooccur exp_cooccur p_lt p_gt
## 1   1   2      18       3           3        0.167           3    1    1
## 2   1   3      18       6           6        0.333           6    1    1
## 3   1   4      18       2           2        0.111           2    1    1
## 4   1   5      18       2           2        0.111           2    1    1
## 5   1   6      18       2           2        0.111           2    1    1
## 6   1   7      18       1           1        0.056           1    1    1
##   sp1_name sp2_name
## 1  Aba.par  Acu.dub
## 2  Aba.par  Ago.afr
## 3  Aba.par  Ago.ful
## 4  Aba.par  Ago.mue
## 5  Aba.par  Ago.vid
## 6  Aba.par  Ama.aen
plot(cooccur.beetles) #heat map plot

#pair--wise investigation using species codes
pair(mod= cooccur.beetles, "Cli.fos")
## Species:
## [1] "Cli.fos"
## with 19 associations
## 
##          sp2 sp2_inc obs_cooccur prob_cooccur exp_cooccur    p_lt    p_gt
## 411  Cyc.car       6           0        0.111         2.0 0.04977 1.00000
## 413  Lei.ruf       9           0        0.167         3.0 0.00452 1.00000
## 417  Not.ruf       4           4        0.074         1.3 1.00000 0.00490
## 420  Poe.cup      12           6        0.222         4.0 1.00000 0.04977
## 424 Pte.nigr      12           6        0.222         4.0 1.00000 0.04977
## 427  Pte.ver       4           4        0.074         1.3 1.00000 0.00490
## 429  Syn.niv       4           4        0.074         1.3 1.00000 0.00490
## 430  Tre.qua       4           4        0.074         1.3 1.00000 0.00490
## 55   Acu.dub       3           3        0.056         1.0 1.00000 0.02451
## 78   Ago.afr       6           6        0.111         2.0 1.00000 0.00005
## 162  Ama.ple       4           4        0.074         1.3 1.00000 0.00490
## 187  Bad.bul       3           3        0.056         1.0 1.00000 0.02451
## 207  Bem.big       7           6        0.130         2.3 1.00000 0.00038
## 249  Bem.lam      10           6        0.185         3.3 1.00000 0.01131
## 277  Bem.man      12           6        0.222         4.0 1.00000 0.04977
## 303  Bem.obt       3           3        0.056         1.0 1.00000 0.02451
## 323  Bra.sha       4           4        0.074         1.3 1.00000 0.00490
## 340  Cal.fus       6           6        0.111         2.0 1.00000 0.00005
## 388  Cal.vio      12           0        0.222         4.0 0.00005 1.00000
#p_lt = p-value < 0.5 detects negative associations
#p_gt = p-value < 0.5 detecs of positive associations

#After looking at cooccurrence patterns among species pairs, the conclusions I can make are that whenever there is a positive relationship you can find those species together, but when there is a negative relationship you will not find those species together at all (probably because they like different habitats). For example we would find species Cli.fos and Cal.fus in the same ecosystem because they have a positive relationship, but you would not find Cli.fos and Cal.vio in the same ecosystem because they have a negative relationship. 

Question 10

pair(mod= cooccur.beetles, "Aba.par")
## Species:
## [1] "Aba.par"
## with 0 associations
## 
## [1] sp2          sp2_inc      obs_cooccur  prob_cooccur exp_cooccur 
## [6] p_lt         p_gt        
## <0 rows> (or 0-length row.names)
pair(mod= cooccur.beetles, "Pte.mad")
## Species:
## [1] "Pte.mad"
## with 0 associations
## 
## [1] sp2          sp2_inc      obs_cooccur  prob_cooccur exp_cooccur 
## [6] p_lt         p_gt        
## <0 rows> (or 0-length row.names)
pair(mod= cooccur.beetles, "Cal.rot")
## Species:
## [1] "Cal.rot"
## with 0 associations
## 
## [1] sp2          sp2_inc      obs_cooccur  prob_cooccur exp_cooccur 
## [6] p_lt         p_gt        
## <0 rows> (or 0-length row.names)
pair(mod= cooccur.beetles, "Pte.nige")
## Species:
## [1] "Pte.nige"
## with 0 associations
## 
## [1] sp2          sp2_inc      obs_cooccur  prob_cooccur exp_cooccur 
## [6] p_lt         p_gt        
## <0 rows> (or 0-length row.names)
#The highest ranked species in the data set all have no associations because they are found everywhere.