# Lab 8 - Exercises

-   Set-up your environment

-   Load, describe, and clean the microbe/nectar datasets from lab. Be sure to explain the cleaning steps you are taking and why.

-   Explore geographical, abiotic, and biotic filtering further. (*Hint: first step will often be to pivot and wrangle the shape of your cleaned dataframe to match the structure of the inputs from these past labs. You may also need to combine datasets.*)

-   Section 1:

    -   Like we did in lab 5, map the data using x, y coordinates. Visualize (i.e. using color, size, fill, etc.) the differences in *average* bacterial and yeast concentrations by site.

        -   Assume flowers with the same prefix (SR1, SR2, etc.) come from the same site (e.g. site SR)

        -   What could these results imply in the context of filtering?

    -   Reference the section "Real-World Data: Island Biogeography of Coral Reefs" from the newer version of lab 6: [https://charleslehnen.github.io/](https://charleslehnen.github.io/BISC_404_Ecology_and_Biodiversity/Labs/Lab_5/Lab_5.html)[BISC_404_Ecology_and_Biodiversity](https://charleslehnen.github.io/BISC_404_Ecology_and_Biodiversity/Labs/Lab_5/Lab_5.html)[/Labs/Lab_6/Lab_6.html](https://charleslehnen.github.io/BISC_404_Ecology_and_Biodiversity/Labs/Lab_5/Lab_5.html)

        -   Hints:

            -   Combine sites into 2 regions:

                -   `observed_data_clean <- observed_data_clean %>% mutate(region = case_when( site_name %in% c("LH", "SG", "OH", "MW", "SV", "JP") ~ "norcal", site_name %in% c("BS", "SB", "SA", "CH", "BB", "SR") ~ "central" ))`

            -   Be sure when calculating `p` to only count species that are present (\>0) for each site. It may help to create a community data matrix with each site as a different row to use `specnumber()` for that step.

                -   `comm_data_matrix <- observed_data_clean %>% select(Fcfu1, Fcfu2, Fcfu3, Fcfu4, Fcfu5, Fcfu6, Bcfu1, Bcfu2, Bcfu3, Bcfu4, Bcfu5, Bcfu6) %>%summarize(across(everything(), sum, na.rm = TRUE))`

                    `p <- specnumber(comm_data_matrix)`

            -   The values from "Date_collected" column should become the date range column titles needed for `regular_sampling_scheme()` function input.

                -   Here is guidance on pivoting your dataframe:

                    -   `observed_data_wide <- observed_data_clean %>%`

                        `select(region, Date_collected, Fcfu1, Fcfu2, Fcfu3, Fcfu4, Fcfu5, Fcfu6, Bcfu1, Bcfu2, Bcfu3, Bcfu4, Bcfu5, Bcfu6) %>%`

                        `# Pivot to long format and filter out zero counts pivot_longer( cols = c(Fcfu1, Fcfu2, Fcfu3, Fcfu4, Fcfu5, Fcfu6, Bcfu1, Bcfu2, Bcfu3, Bcfu4, Bcfu5, Bcfu6), names_to = "Species", values_to = "Count" ) %>% filter(Count != 0) %>%`

                        `group_by(region, Species, Date_collected) %>% summarize(Count = sum(Count, na.rm = TRUE), .groups = 'drop') %>%`

                        `# Convert to date format so we can sort later mutate(Date_collected = mdy(Date_collected)) %>%`

                        `pivot_wider( names_from = Date_collected, values_from = Count, values_fill = 0 ) %>%`

                        `# Convert counts to presence/absence (1 or 0) mutate(across(where(is.numeric), ~ case_when( . > 0 ~ 1, . == 0 ~ 0, TRUE ~ NA_real_ ))) %>%`

                        `# Arrange columns so date columns are in chronological order select(region, Species, sort(tidyselect::peek_vars()))`\

        -   What could these results imply in the context of filtering? (Hint: do sites have similar or different S\* values and what does this imply about filtering?)\

    Section 2:

    -   Reference zero-growth isoclines from the newer version of lab 5: <https://charleslehnen.github.io/BISC_404_Ecology_and_Biodiversity/Labs/Lab_5/Lab_5.html>

        -   Repeat a zero-growth isocline analysis for our microbe/nectar dataset for bacteria vs. yeast.

        -   What could these results imply in the context of filtering?\

-   Write a brief overall conclusion what your results imply. Note the strengths and weaknesses of using these analyses over using species abundance or richness.

------------------------------------------------------------------------

# References
