A simple wrapper for msi_tool
to make it easier to use in R.
Multi-Species Indicators (MSI) are biodiversity indicators that combine the population
development of species into a single indicator. The MSI-tool calculates an MSI, confidence intervals
for the MSIs and linear and flexible (smoothed) trends. The trends are classified in terms like
"moderate increase", "strong decrease" or "stable". A number of additional analyses can be performed
like testing for changepoints, comparison of trends before and after a changepoint and the calculation
and testing of the total change in a time series.
Arguments
- data
a data.frame with 4 columns in this order: 'species', 'year', 'index', 'se' (standard error). The index value in the base year (which need not be the first year), should be set to 100, with se of 0.
- jobname
Generic name for output files
- ...
other parameters to pass to
msi_tool
Value
Returns a dataframe with 4 columns: Year, Index, lower2.5, upper97.5. The last two columns are the credible intervals
Examples
# Create some example data in the format required
nyr = 20
species = rep(letters, each = nyr)
year = rev(rep(1:nyr, length(letters)))
# Create an index value that increases with time
index = rep(seq(50, 100, length.out = nyr), length(letters))
# Add randomness to species
index = index * runif(n = length(index), 0.7, 1.3)
# Add correlated randomness acrosss species, to years
index = index * rep(runif(0.8, 1.2, n = nyr), length(letters))
se = runif(n = nyr * length(letters), min = 10, max = 20)
data <- data.frame(species, year, index, se)
# Our species are decreasing
plot(data$year, data$index)
# Species index values need to be 100 in the base year. Here I use
# the first year as my base year and rescale to 100. The standard error
# in the base year should be 0.
min_year <- min(data$year)
for(sp in unique(data$species)){
subset_data <- data[data$species == sp, ]
multi_factor <- 100 / subset_data$index[subset_data$year == min_year]
data$index[data$species == sp] <- data$index[data$species == sp] * multi_factor
data$se[data$species == sp] <- data$se[data$species == sp] * multi_factor
data$se[data$species == sp][1] <- 0
}
# Run the MSI function
msi_out <- msi(data, plot = FALSE)
# Plot the resulting indicator
plot(msi_out)