View source: R/summarizeCosts.R
computeAvgTotCost | R Documentation |
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
.
computeAvgTotCost(
costdb,
cost.column = "Cost_estimate_per_year_2017_USD_exchange_rate",
year.column = "Impact_year",
min.year = NULL,
max.year = NULL
)
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) |
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 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.
Boris Leroy leroy.boris@gmail.com, Andrew Kramer, Anne-Charlotte Vaissière, Christophe Diagne
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/2041-210X.13929")}
expandYearlyCosts
to get the database in appropriate format.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.