Skip to content

Latest commit

 

History

History
272 lines (201 loc) · 9.01 KB

P4.md

File metadata and controls

272 lines (201 loc) · 9.01 KB

Introduction

This code calculates indicator P4 of NorInAliS.

Preparations

Define auxiliary functions:

# Combines text strings
"%+%" <- function(string1, string2) paste0(string1, string2)


# I just find this more intuitive...
"%contains%" <- function (textstring, searchtext) grepl(searchtext, textstring)

Load data from the Alien Species List 2018 (Sandvik et al. 2020):

fab  <- read.csv2(url("https://datadryad.org/stash/downloads/file_stream/359484"),
                  as.is=T)

The AOOs (areas of occupancy, in km2) provided in the above dataset are only the best estimates of the total AOO for each species (i.e. the median expert judgement of the real AOO, including “dark figures” or unreported occurrences). However, in order to quantify uncertainty, P2 needs more than that, viz. the low and high estimates of the total AOO (i.e. lower and upper quartiles) as well as the known AOO (i.e. excluding dark figures). These values are here read from a separate file. Their source is https://artsdatabanken.no/fremmedartslista2018.

aoo <- read.csv2("../cache/aoo.csv", as.is=T)

Restrict data to alien species that are reproducing unaidedly in mainland Norway:

fab <- fab[which(fab$Status == "reproducing" & fab$Mainl),]

Restrict the data to marine species:

w <- which(fab$LifeSt %in%
           c("mar", "mar,par"))
fab <- fab[w,]
aoo <- aoo[w,]

Restrict data to coastal and bottom-dwelling species (This is based on ecosystem codes defined by “Nature in Norway”, according to the EcoSyst framework, see Halvorsen et al. 2020):

w <- delete <- which(fab$Ecosys %contains% "H01" & !(fab$Ecosys %contains% "M"))
if (length(w)) {
  for (i in w) {
    if (fab$Ecosys[i] %contains% "H01-05") {
      if (!(paste(unlist(strsplit(fab$Ecosys[i], ",")) %-% "H01-05",
                  collapse=",") %contains% "H01")) {
        delete <- w %-% i
      }
    }
  }
  if (length(delete)) {
    cat(length(delete) %+% " marine species " %+% ifelse(length(delete) == 1,
        "is omitted because it is", "are omitted because they are") %+%
        " not coastal or bottom-dwelling:\n")
    for (i in delete) {
      cat("* " %+% fab$Name[i] %+% "\n")
    }
    fab <- fab[-delete,]
    aoo <- aoo[-delete,]
  }
}

## 2 marine species are omitted because they are not coastal or bottom-dwelling:
## * Mnemiopsis leidyi
## * Penilia avirostris

Make sure that the two data frames are compatible:

if (all(fab$Name == aoo$Name)) {
  cat("Everything is fine.\n")
} else {
  cat("ERROR: For some reason, the two dataframes are not compatible!\n")
}

## Everything is fine.

Load the relevant data from the reporting system for the Water Framework Directive (WFD) in Norway (for details, see indicator P3):

WFD <- read.csv("../cache/WFD.csv", sep=";", dec=".", as.is=TRUE, encoding="latin1")

Restrict the data to coastal waterbodies:

WFD <- WFD[which(WFD$Category == "Coastal"), ]
head(WFD)

##                 ID                          Name Category   Area Length           Species Impact Regional
## 905   0101000031-C               Svenner - Rauer  Coastal 124.51     NA Crassostrea gigas     SE    FALSE
## 906 0101000032-3-C                         Tjøme  Coastal 116.48     NA Crassostrea gigas     SE    FALSE
## 907 0101020101-1-C         Ytre Oslofjord - Vest  Coastal  80.02     NA Crassostrea gigas     SE    FALSE
## 908 0101020200-2-C       Midtre Oslofjord - Vest  Coastal  59.73     NA Crassostrea gigas     SE    FALSE
## 909 0101020300-1-C Hårfagrebåen - Hortenskrakken  Coastal  15.24     NA Crassostrea gigas     SE    FALSE
## 910   0101020601-C                   Oslofjorden  Coastal 121.00     NA Crassostrea gigas     SE    FALSE

How many alien species are reported in the two datasets?

{
  cat("Alien Species List 2018:   " %+% length(unique(fab$Name))    %+% " spp.\n")
  cat("Water Framework Directive: " %+% length(unique(WFD$Species)) %+% " spp.\n")
}

## Alien Species List 2018:   32 spp.
## Water Framework Directive: 3 spp.

Specify the total number and size of waterbodies (from Vann-nett):

Ncoast <-  2283  # number of coastal waterbodies
Acoast <- 93649  # total area of coastal waterbodies in square kilometres

Functions

The estimation of indicator definition P4(a) uses the same functions as indicator P2 (see there). They are here loaded invisibly.

Error checking and correction

Check for obvious errors in the original data:

(1) Is any low estimate greater than the corresponding best estimate?

w <- which(aoo$low > aoo$best)
if (length(w)) {
  print(aoo[w,])
} else {
  cat("Everything is fine.\n")
}

## Everything is fine.

(2) Is any high estimate less than the corresponding best estimate?

w <- which(aoo$high < aoo$best)
if (length(w)) {
  print(aoo[w,])
} else {
  cat("Everything is fine.\n")
}

## Everything is fine.

(3) By definition, AOOs are multiples of 4 square kilometres. Some figures are incompatible with this definition. We solve this by rounding upwards:

aoo[, 2:5] <- ceiling(aoo[, 2:5] / 4) * 4

(4) Is any AOO greater than the area of mainland Norway?

w <- which(aoo$high > 323800)
if (length(w)) {
  print(aoo[w,])
} else {
  cat("Everything is fine.\n")
}

## Everything is fine.

Simulations

If you want P2 for high- and severe-impact species only, do this first (not run):

aoo <- aoo[which(fab$Impact %in% c("HI", "SE")),]
WFD <- WFD[which(WFD$Impact %in% c("HI", "SE")),]

If you want P2 for the remaining species only, do this first (not run):

aoo <- aoo[which(fab$Impact %in% c("NK", "LO", "PH")),]
WFD <- WFD[which(WFD$Impact %in% c("NK", "LO", "PH")),]

If you want P2 for all alien species (default), do none of the above.

Then start the simulation:

AOO <- P2(aoo)
avg   <-     mean(apply(AOO, 1, sum))
stdev <-       sd(apply(AOO, 1, sum))
conf  <- quantile(apply(AOO, 1, sum), c(0.025, 0.25, 0.5, 0.75, 0.975))

Output of the results:

{ 
  cat("P4(a) is " %+% round(avg,   -2) %+% " km² ± " %+%
                      round(stdev, -2) %+% " km² (mean ± SD)\n\n")
  cat("Confidence levels (in km²):\n")
  print(round(conf, -2))
}

## P4(a) is 202200 km² ± 64300 km² (mean ± SD)
## 
## Confidence levels (in km²):
##   2.5%    25%    50%    75%  97.5% 
## 113200 156500 189700 233800 369600

Calculation of WFD-based indicator definitions

Create a variable for the results:

P4 <- matrix(round(avg), 1, 5, 
      dimnames=list("Coastal", c("P4(a)", "P4(b)", "P4(c)", "Area", "P4(d)")))

Estimate P4(b):

P4[1, 2] <- length(unique(WFD$ID))

Estimate P4(c):

P4[1, 3] <- P4[1, 2] / Ncoast

Estimate P4(d):

P4[1, 4] <- 0
for (i in unique(WFD$ID)) {
  A <- WFD$Area[which(WFD$ID == i)[1]]
  # to ensure that every waterbody is only counted once
  if (!is.na(A)) {
    P4[1, 4] <- P4[1, 4] + A
  }
}
P4[1, 5] <- P4[1, 4] / Acoast
P4[1, 4] <- round(P4[1, 4])

Output of the results, where

  • P4(a) is the sum of areas of occupancies (in square kilometres) of all coastal or bottom-dwelling marine alien species that are recorded as reproducing unaidedly in Norway, including estimated dark figures of the areas of occupancy,
  • P4(b) is the number of coastal waterbodies in which at least one alien species is recorded as an ongoing impact according to the Water Framework Directive,
  • P4(c) is the proportion of coastal waterbodies in which at least one alien species is recorded as an ongoing impact according to the Water Framework Directive,
  • Area is the cumulative area of coastal waterbodies (in square kilometres) in which at least one alien species is recorded as an ongoing impact according to the Water Framework Directive,
  • P4(d) is the proportion of the area of coastal waterbodies in which at least one alien species is recorded as an ongoing impact according to the Water Framework Directive:
print(P4)

##          P4(a) P4(b)     P4(c)  Area     P4(d)
## Coastal 202232   290 0.1270258 18870 0.2015009