computeAvgTotCost {invacost} | R Documentation |
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
)
Arguments
costdb |
The expanded 'InvaCost' database output from
|
cost.column |
Name of the cost column to use in |
year.column |
Name of the year column to use in |
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) |
Value
a named list
with 5 elements
initial_year
: first year in the datafinal_year
: last year in the datatime_span
: the difference between initial and final years.total_cost
: total cost.annual.cost
: cost per yearnumber_estimates
: the number of cost estimates before expansion viaexpandYearlyCosts
number_year_values
: the number of costs per year included
Note
Arguments min.year
and max.year
do not filter the data. Only
specify them if you wish to change the interval over which averages are
calculated. For example, if your data have values from 1960 to 1964 but you
want to calculated the average value from 1960 to 1969, set
min.year = 1960
and max.year = 1969
.
However, if you want to calculate values for an interval narrower than your data, filter the data BEFORE running this function.
Author(s)
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. doi:10.1111/2041-210X.13929
See Also
expandYearlyCosts
to get the database in appropriate format.
Examples
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
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