diff --git a/DESCRIPTION b/DESCRIPTION index 40ea7979..30ac1d21 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fbi Title: Finnish Biodiversity Indicators -Version: 0.11.17.9000 +Version: 0.11.18 Authors@R: c( person(given = "Finnish Museum of Natural History - Luomus", role = "cph"), diff --git a/docs/404.html b/docs/404.html index 89bae530..2ab90677 100644 --- a/docs/404.html +++ b/docs/404.html @@ -22,7 +22,7 @@ fbi - 0.11.17 + 0.11.18 + + @@ -66,119 +90,133 @@

Community temperature index

This documents outlines how a multi-taxon indicator (Community temperature index for Finnish Birds in Winter) can be calculated in R.

-
-

Load packages

-

The following packages are required. All packages are available on CRAN apart from -{fbi} which can be installed from GitHub.

-
library(dplyr)
-library(fbi)
-library(finbif)
-library(ggplot2)
-library(lubridate)
-library(lme4)
-library(arm)
+
+

Load packages +

+

The following packages are required. All packages are available on CRAN apart from +fbi which can be installed from GitHub.

+
-
-

Survey data

+
+

Survey data +

These five fields are required for the survey data.

-
select <- c("document_id", "location_id", "year", "month", "day")
+
+select <- c("document_id", "location_id", "year", "month", "day")

These filters restrict the survey data to the Dec-Jan “Winter Bird Census” monitoring dataset from December 1958 onwards where the selected data fields have no missing data.

-
filter <- list(
-  collection = "Winter Bird Census",
-  date_range_ymd = c("1958-12-01", ""),
-  date_range_md= c("12-01", "01-31"),
-  has_value = select
-)
+
+filter <- list(
+  collection = "Winter Bird Census",
+  date_range_ymd = c("1958-12-01", ""),
+  date_range_md= c("12-01", "01-31"),
+  has_value = select
+)

The survey data can now downloaded from FinBIF.

-
surveys <- finbif_occurrence(
-  filter = filter,
-  select = select,
-  aggregate = "events",
-  aggregate_counts = FALSE,
-  n = "all",
-  quiet = TRUE
-)
+
+surveys <- finbif_occurrence(
+  filter = filter,
+  select = select,
+  aggregate = "events",
+  aggregate_counts = FALSE,
+  n = "all",
+  quiet = TRUE
+)

A single processing function is applied to the survey data to limit each site to the first survey of the year (where year is the period Dec-Jan).

-
surveys <- pick_first_survey_in_winter(surveys)
+
+surveys <- pick_first_survey_in_winter(surveys)
-
-

Count data

+
+

Count data +

Count data requires two fields to be selected: the survey identifier (document_id) and the measure of abundance (abundance_interpreted).

-
select <- c("document_id", abundance = "abundance_interpreted")
+
+select <- c("document_id", abundance = "abundance_interpreted")

The count data requires the same filters as the survey data (though the filter has_value needs to be redefined).

-
filter[["has_value"]] <- select
+
+filter[["has_value"]] <- select

A set of taxa and their species temperature index values is defined.

-
sti <- c(
-  "Poecile montanus" = -7.51,
-  "Regulus regulus" = -4.23,
-  "Lophophanes cristatus" = -5.90,
-  "Certhia familiaris" = -6.89
-)
+
+sti <- c(
+  "Poecile montanus" = -7.51,
+  "Regulus regulus" = -4.23,
+  "Lophophanes cristatus" = -5.90,
+  "Certhia familiaris" = -6.89
+)

The count data for these taxa can now be downloaded from FinBIF.

-
counts <- lapply(
-  names(sti),
-  finbif_occurrence,
-  filter = filter,
-  select = select,
-  n = "all",
-  quiet = TRUE
-)
+
+counts <- lapply(
+  names(sti),
+  finbif_occurrence,
+  filter = filter,
+  select = select,
+  n = "all",
+  quiet = TRUE
+)

The count data is then combined with the survey data and the species temperature indices.

-
counts <- lapply(counts, combine_with_surveys, surveys)
-
-counts <- mapply(mutate, counts, sp = names(sti), SIMPLIFY = FALSE)
-
-counts <- do.call(rbind, counts)
-
-counts[["sti"]] <- sti[counts[["sp"]]]
+
+counts <- lapply(counts, combine_with_surveys, surveys)
+
+counts <- mapply(mutate, counts, sp = names(sti), SIMPLIFY = FALSE)
+
+counts <- do.call(rbind, counts)
+
+counts[["sti"]] <- sti[counts[["sp"]]]
-
-

Create Index

+
+

Create Index +

A community temperature index for each year is created by fitting a linear mixed effects regression model to the combined data.

-
cti_data <- summarise(
-  group_by(counts, location_id, year),
-  cti = sum(abundance * sti) / sum(abundance), .groups = "drop"
-)
-
-cti <- lmer(cti ~ (1 | location_id) + (1 | year), cti_data)
-
-cti <- data.frame(index = coef(cti)[["year"]], se = se.coef(cti)[["year"]])
-
-cti[["time"]] <- as.integer(row.names(cti))
-
-names(cti) <- c("index", "se", "time")
-
ggplot(cti) +
-aes(
-  x = parse_date_time(time, "Y"),
-  y = index,
-  ymin = index - se,
-  ymax = index + se
-) +
-geom_ribbon(alpha = .2) +
-geom_line() +
-ylab(NULL) +
-xlab(NULL) +
-theme_minimal()
+
+cti_data <- summarise(
+  group_by(counts, location_id, year),
+  cti = sum(abundance * sti) / sum(abundance), .groups = "drop"
+)
+
+cti <- lmer(cti ~ (1 | location_id) + (1 | year), cti_data)
+
+cti <- data.frame(index = coef(cti)[["year"]], se = se.coef(cti)[["year"]])
+
+cti[["time"]] <- as.integer(row.names(cti))
+
+names(cti) <- c("index", "se", "time")
+
+ggplot(cti) +
+aes(
+  x = parse_date_time(time, "Y"),
+  y = index,
+  ymin = index - se,
+  ymax = index + se
+) +
+geom_ribbon(alpha = .2) +
+geom_line() +
+ylab(NULL) +
+xlab(NULL) +
+theme_minimal()
- -
Community Temperature Index for Winter Birds in +Community Temperature Index for Winter Birds in Finland
Community Temperature Index for Winter Birds in Finland
+ +
@@ -190,10 +228,12 @@

Create Index

Site built with pkgdown 2.1.0.

-
+ +
- + + diff --git a/docs/articles/community-temperature-indices.html b/docs/articles/community-temperature-indices.html index 07933d87..c65ab763 100644 --- a/docs/articles/community-temperature-indices.html +++ b/docs/articles/community-temperature-indices.html @@ -22,7 +22,7 @@ fbi - 0.11.17 + 0.11.18