Learn R Programming

invacost (version 1.1-6)

computeAvgTotCost: Calculate the cumulative and average annual cost over a single period of time

Description

This simple function calculates the cumulative cost average annual cost of invasive alien species over a single period of time. It is used internally by summarizeCosts.

Usage

computeAvgTotCost(
  costdb,
  cost.column = "Cost_estimate_per_year_2017_USD_exchange_rate",
  year.column = "Impact_year",
  min.year = NULL,
  max.year = NULL
)

Value

a named list with 5 elements

  • initial_year: first year in the data

  • final_year: last year in the data

  • time_span: the difference between initial and final years.

  • total_cost: total cost.

  • annual.cost: cost per year

  • number_estimates: the number of cost estimates before expansion via expandYearlyCosts

  • number_year_values: the number of costs per year included

Arguments

costdb

The expanded 'InvaCost' database output from expandYearlyCosts, where annual costs occurring over several years are repeated for each year.

cost.column

Name of the cost column to use in costdb (usually, choose between the exchange rate (default) or Purchase Power Parity cost per year)

year.column

Name of the year column to use in costdb.

min.year

The minimum year of the period (specify only if different from the range of data)

max.year

The minimum year of the period (specify only if different from the range of data)

Author

Boris Leroy leroy.boris@gmail.com, Andrew Kramer, Anne-Charlotte Vaissière, Christophe Diagne

References

https://github.com/Farewe/invacost

Leroy Boris, Kramer Andrew M, Vaissière Anne-Charlotte, Kourantidou Melina, Courchamp Franck & Diagne Christophe (2022). Analysing economic costs of invasive alien species with the invacost R package. Methods in Ecology and Evolution. tools:::Rd_expr_doi("10.1111/2041-210X.13929")

See Also

expandYearlyCosts to get the database in appropriate format.

Examples

Run this code
data(invacost)

### Cleaning steps
# Eliminating data with no information on starting and ending years
invacost <- invacost[-which(is.na(invacost$Probable_starting_year_adjusted)), ]
invacost <- invacost[-which(is.na(invacost$Probable_ending_year_adjusted)), ]
# Keeping only observed and reliable costs
invacost <- invacost[invacost$Implementation == "Observed", ]
invacost <- invacost[which(invacost$Method_reliability == "High"), ]
# Eliminating data with no usable cost value
invacost <- invacost[-which(is.na(invacost$Cost_estimate_per_year_2017_USD_exchange_rate)), ]

### Expansion
# \donttest{
db.over.time <- expandYearlyCosts(invacost,
                                  startcolumn = "Probable_starting_year_adjusted",
                                  endcolumn = "Probable_ending_year_adjusted")
                                  
### Analysis
res <- computeAvgTotCost(db.over.time,
                         min.year = 1960,
                         max.year = 2020) # Excluding data after 2020 (e.g. planned budgets)
res# }

Run the code above in your browser using DataLab