`summarise()` has grouped output by 'cover_cat_cd'. You can override using the
`.groups` argument.
count_species
# A tibble: 70 × 4
# Groups: cover_cat_cd [70]
cover_cat_cd cover_cat_name n count
<chr> <chr> <int> <int>
1 TUR SEDI Turf Algae with Sediment 789 789
2 SPO OTHE Porifera spp 755 755
3 BAR SUB. Bare Substrate 729 729
4 DIC SPE. Dictyota spp 704 704
5 GOR GORG Gorgonians 698 698
6 MAC FLES MacroOtherFleshy 526 526
7 RHO CRUS Rhodophyta cru. spp 520 520
8 GOR ENCR Encrusting gorgonian 470 470
9 SID SIDE Siderastrea siderea 459 459
10 MIL SPE. Millepora spp 414 414
# ℹ 60 more rows
# Filter out all species more than 20 observationscoral <- coral |>group_by(cover_cat_cd,cover_cat_name)|>filter(n()>20) |>filter(!is.na(cover_cat_name))# Filter down to only hard corals with > 20 data points (9 hard coral species)coral <- coral |>filter(cover_cat_name %in%c( "Agaricia agaricites", "Colpophyllia natans", "Dichocoenia stokesii", "Montastraea cavernosa", "Orbicella faveolata", "Porites porites", "Siderastrea siderea", "Stephanocoenia intersepta", "Porites astreoides")) head(coral)
Warning: package 'sf' was built under R version 4.3.3
Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library(dplyr)# Convert to sf objectscoral_sf <-st_as_sf(coral, coords =c("longitude", "latitude"), crs =4326) #n= 1798carb_sf <-st_as_sf(carb, coords =c("longitude", "latitude"), crs =4326) #n = 1352## NEAREST NEIGHBOR# Extract unique years from the coral datasetyears <-unique(coral$year)# Make an empty df to store the joined resultsjoined_df <-data.frame()# Loop through each year and perform nearest neighbor analysis within that yearfor (year in years) {# Filter datasets for the current year coral_year <- coral_sf[coral_sf$year == year, ] carb_year <- carb_sf[carb_sf$year == year, ]# the nearest neighbor analysis nearest_neighbors <-st_nearest_feature(coral_year, carb_year)# Extract the carbonate chemistry measurements for nearest neighbors nearest_carb <- carb_year[nearest_neighbors, ]# Add the nearest chemistry measurements to the coral cover data coral_with_chemistry_year <-cbind(coral_year, nearest_carb)# Add the result to the final df joined_df <-rbind(joined_df, coral_with_chemistry_year)}# Reset row numbersrownames(joined_df) <-NULL# Update the dataframejoined_df <- joined_df#Df check unique(joined_df$year)
# Now, we can analyze the combined data to understand the relationship between carbonate chemistry and coral cover
Data Visualizations
Map of ΩAr across Florida Keys - in other doc need to combine (with un merged data)
Map of ΩAr, pH, and Temp across Florida Keys - in other doc need to combine (with un merged data)
Statistical Assessments
joined_df
Simple feature collection with 1798 features and 13 fields
Active geometry column: geometry
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -83.10352 ymin: 24.43146 xmax: -80.08719 ymax: 25.74996
Geodetic CRS: WGS 84
First 10 features:
region mpa_name year cover_cat_cd cover_cat_name hardbottom_p
1 FLK Unprotected 2016 ORB FAVE Orbicella faveolata 4
2 FLK Unprotected 2016 SID SIDE Siderastrea siderea 4
3 FLK Unprotected 2016 STE INTE Stephanocoenia intersepta 1
4 FLK Unprotected 2016 DIC STOK Dichocoenia stokesii 1
5 FLK Unprotected 2016 MON CAVE Montastraea cavernosa 1
6 FLK Unprotected 2016 STE INTE Stephanocoenia intersepta 1
7 FLK West_Sambo 2016 MON CAVE Montastraea cavernosa 1
8 FLK West_Sambo 2016 SID SIDE Siderastrea siderea 1
9 FLK West_Sambo 2016 STE INTE Stephanocoenia intersepta 1
10 FLK West_Sambo 2016 COL NATA Colpophyllia natans 1
region.1 year.1 dic p_h_measured aragonite_sat temperature_c p_co2
1 FLK 2016 2018.0 8.003 3.88 30.492 448.5
2 FLK 2016 2018.0 8.003 3.88 30.492 448.5
3 FLK 2016 2018.0 8.003 3.88 30.492 448.5
4 FLK 2016 2018.0 8.003 3.88 30.492 448.5
5 FLK 2016 2039.6 8.006 3.85 29.634 447.6
6 FLK 2016 2039.6 8.006 3.85 29.634 447.6
7 FLK 2016 2053.9 8.035 3.65 26.287 416.3
8 FLK 2016 2053.9 8.035 3.65 26.287 416.3
9 FLK 2016 2053.9 8.035 3.65 26.287 416.3
10 FLK 2016 2053.3 8.059 3.74 25.728 392.1
geometry geometry.1
1 POINT (-81.9823 24.46499) POINT (-81.82954 24.45697)
2 POINT (-81.9823 24.46499) POINT (-81.82954 24.45697)
3 POINT (-81.9823 24.46499) POINT (-81.82954 24.45697)
4 POINT (-81.9823 24.46499) POINT (-81.82954 24.45697)
5 POINT (-81.7548 24.46302) POINT (-81.71873 24.47505)
6 POINT (-81.7548 24.46302) POINT (-81.71873 24.47505)
7 POINT (-81.72699 24.47505) POINT (-81.71912 24.47733)
8 POINT (-81.72699 24.47505) POINT (-81.71912 24.47733)
9 POINT (-81.72699 24.47505) POINT (-81.71912 24.47733)
10 POINT (-81.70926 24.50635) POINT (-81.71482 24.47673)
# additive multiple regression# How does the percentage of hard coral cover (hardbottom_p) vary over time (year) in each region (region)?coral_lm1 <-lm(hardbottom_p ~ year + region, data = joined_df)summary(coral_lm1)
Call:
lm(formula = hardbottom_p ~ year + region, data = joined_df)
Residuals:
Min 1Q Median 3Q Max
-3.097 -1.442 -1.135 0.558 37.558
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.25599 0.15612 14.450 < 2e-16 ***
year2018 0.08407 0.19747 0.426 0.670
year2021 0.18556 0.24626 0.753 0.451
year2022 -0.12133 0.19342 -0.627 0.531
regionFLK 0.84059 0.15930 5.277 1.47e-07 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.087 on 1793 degrees of freedom
Multiple R-squared: 0.01557, Adjusted R-squared: 0.01338
F-statistic: 7.091 on 4 and 1793 DF, p-value: 1.158e-05
# Pr(>|t|) # (Intercept) < 2e-16 ***# year2018 0.670 # year2021 0.451 # year2022 0.531 # regionFLK 1.47e-07 ***# F-statistic: 7.091 on 4 and 1793 DF, p-value: 1.158e-05# How does the percentage of hard coral cover (hardbottom_p) vary over time (year) in each region (region) - for each species?coral_lm2 <-lm(hardbottom_p ~ year + region + cover_cat_name, data = joined_df)summary(coral_lm2)
# F-statistic: 15.8 on 12 and 1785 DF, p-value: < 2.2e-16# add in chemistry stats# use augment() for additive models in ggplot# additive multiple regression# 1 categorical# How does carbonate chemistry effect hard coral cover over time in each region? # exploring models:coral_lm3 <-lm(hardbottom_p ~ year + region + p_h_measured, data = joined_df)summary(coral_lm3)
Call:
lm(formula = hardbottom_p ~ year + region + p_h_measured, data = joined_df)
Residuals:
Min 1Q Median 3Q Max
-3.240 -1.453 -1.091 0.547 37.547
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -42.59455 24.17125 -1.762 0.07821 .
year2018 0.08330 0.19734 0.422 0.67298
year2021 0.01751 0.26223 0.067 0.94678
year2022 -0.10558 0.19347 -0.546 0.58534
regionFLK 0.67643 0.18212 3.714 0.00021 ***
p_h_measured 5.59928 3.01755 1.856 0.06368 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.085 on 1792 degrees of freedom
Multiple R-squared: 0.01746, Adjusted R-squared: 0.01472
F-statistic: 6.369 on 5 and 1792 DF, p-value: 7.15e-06
# F-statistic: 6.369 on 5 and 1792 DF, p-value: 7.15e-06coral_lm4 <-lm(hardbottom_p ~ year + region + p_h_measured + dic, data = joined_df)summary(coral_lm4)
Call:
lm(formula = hardbottom_p ~ year + region + p_h_measured + dic,
data = joined_df)
Residuals:
Min 1Q Median 3Q Max
-3.239 -1.453 -1.096 0.547 37.547
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -4.193e+01 2.549e+01 -1.645 0.100161
year2018 8.125e-02 1.990e-01 0.408 0.683026
year2021 1.719e-02 2.623e-01 0.066 0.947766
year2022 -1.004e-01 2.036e-01 -0.493 0.622184
regionFLK 6.718e-01 1.908e-01 3.520 0.000442 ***
p_h_measured 5.573e+00 3.035e+00 1.837 0.066432 .
dic -2.218e-04 2.695e-03 -0.082 0.934403
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.085 on 1791 degrees of freedom
Multiple R-squared: 0.01747, Adjusted R-squared: 0.01417
F-statistic: 5.306 on 6 and 1791 DF, p-value: 1.954e-05
# F-statistic: 5.306 on 6 and 1791 DF, p-value: 1.954e-05coral_lm5 <-lm(hardbottom_p ~ year + region + p_h_measured + dic + aragonite_sat, data = joined_df)summary(coral_lm5)
Call:
lm(formula = hardbottom_p ~ year + region + p_h_measured + dic +
aragonite_sat, data = joined_df)
Residuals:
Min 1Q Median 3Q Max
-3.889 -1.462 -1.042 0.492 37.538
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -38.925191 25.437766 -1.530 0.12614
year2018 0.455018 0.228794 1.989 0.04688 *
year2021 -0.166689 0.267553 -0.623 0.53335
year2022 -0.011399 0.204885 -0.056 0.95564
regionFLK 0.541843 0.194371 2.788 0.00536 **
p_h_measured 7.096764 3.061805 2.318 0.02057 *
dic -0.004763 0.003023 -1.576 0.11530
aragonite_sat -1.601079 0.488008 -3.281 0.00105 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.077 on 1790 degrees of freedom
Multiple R-squared: 0.02334, Adjusted R-squared: 0.01952
F-statistic: 6.111 on 7 and 1790 DF, p-value: 4.493e-07
# F-statistic: 6.111 on 7 and 1790 DF, p-value: 4.493e-07coral_lm6 <-lm(hardbottom_p ~ year + region + p_h_measured + dic + aragonite_sat + temperature_c, data = joined_df)summary(coral_lm6)
Call:
lm(formula = hardbottom_p ~ year + region + p_h_measured + dic +
aragonite_sat + temperature_c, data = joined_df)
Residuals:
Min 1Q Median 3Q Max
-3.779 -1.459 -0.937 0.489 37.541
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 107.604752 46.787741 2.300 0.021571 *
year2018 0.576103 0.230280 2.502 0.012447 *
year2021 -0.703242 0.303003 -2.321 0.020404 *
year2022 0.625715 0.266303 2.350 0.018900 *
regionFLK 0.580323 0.193950 2.992 0.002808 **
p_h_measured -10.043812 5.520064 -1.820 0.069001 .
dic -0.008143 0.003146 -2.589 0.009714 **
aragonite_sat 0.188357 0.683453 0.276 0.782890
temperature_c -0.317490 0.085211 -3.726 0.000201 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.066 on 1789 degrees of freedom
Multiple R-squared: 0.03086, Adjusted R-squared: 0.02652
F-statistic: 7.12 on 8 and 1789 DF, p-value: 2.614e-09
# F-statistic: 7.12 on 8 and 1789 DF, p-value: 2.614e-09coral_lm7 <-lm(hardbottom_p ~ year + region + p_h_measured + dic + aragonite_sat + temperature_c + p_co2, data = joined_df)summary(coral_lm7)
# F-statistic: 6.606 on 9 and 1788 DF, p-value: 2.491e-09# ANOVAS - still working on anova1 <-aov(aragonite_sat~region + year, data = joined_df)summary(anova1)
Df Sum Sq Mean Sq F value Pr(>F)
region 1 0.00 0.000 0 0.989
year 3 28.99 9.662 333 <2e-16 ***
Residuals 1793 52.02 0.029
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1