Title: | Bayesian Model to Estimate Population Trends from Counts Series |
---|---|
Description: | Infers the trends of one or several animal populations over time from series of counts. It does so by accounting for count precision (provided or inferred based on expert knowledge, e.g. guesstimates), smoothing the population rate of increase over time, and accounting for the maximum demographic potential of species. Inference is carried out in a Bayesian framework. This work is part of the FRB-CESAB working group AfroBioDrivers <https://www.fondationbiodiversite.fr/en/the-frb-in-action/programs-and-projects/le-cesab/afrobiodrivers/>. |
Authors: | Nicolas Casajus [aut, cre, cph] , Roger Pradel [aut] |
Maintainer: | Nicolas Casajus <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.0.9000 |
Built: | 2024-11-11 03:59:24 UTC |
Source: | https://github.com/FRBCesab/popbayes |
From the output of the function fit_trend()
(or read_bugs()
), this
function extracts estimated parameters into a data.frame
.
The resulting data.frame
has no particular use in popbayes
but it can be
useful for users.
bugs_to_df(data)
bugs_to_df(data)
data |
a named |
A data.frame
.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Import BUGS outputs for one count series ---- bugs <- popbayes::read_bugs(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Extract estimated parameters ---- popbayes::bugs_to_df(bugs)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Import BUGS outputs for one count series ---- bugs <- popbayes::read_bugs(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Extract estimated parameters ---- popbayes::bugs_to_df(bugs)
From the output of the function fit_trend()
(or read_bugs()
), this
function checks if the estimation of all parameters of one (or several)
BUGS model has converged. This diagnostic is performed by comparing the
Rhat
value of each parameter to a threshold
(default is 1.1
). If some
Rhat
values are greater than this threshold (no convergence), a message
listing problematic models is displayed.
diagnostic(data, threshold = 1.1)
diagnostic(data, threshold = 1.1)
data |
a named |
threshold |
a |
No return value.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Check for convergence ---- popbayes::diagnostic(a_buselaphus_mod)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Check for convergence ---- popbayes::diagnostic(a_buselaphus_mod)
This function identifies the count series relative to a species and/or
a location in a named list like the output of function format_data()
. If
both species and location are provided, the series of counts of the species
at the specified location is extracted. Otherwise, all series corresponding
to the specified criterion (species or location) are extracted.
filter_series(data, species = NULL, location = NULL)
filter_series(data, species = NULL, location = NULL)
data |
a named |
species |
a |
location |
a |
A subset of data
, i.e. a named list
.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Number of count series ---- length(garamba_formatted) ## Retrieve count series names ---- popbayes::list_series(path = temp_path) ## Get data for Alcelaphus buselaphus (at all sites) ---- x <- popbayes::filter_series(garamba_formatted, species = "Alcelaphus buselaphus") ## Get data at Garamba (for all species) ---- x <- popbayes::filter_series(garamba_formatted, location = "Garamba") ## Get data for Alcelaphus buselaphus at Garamba only ---- x <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus")
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Number of count series ---- length(garamba_formatted) ## Retrieve count series names ---- popbayes::list_series(path = temp_path) ## Get data for Alcelaphus buselaphus (at all sites) ---- x <- popbayes::filter_series(garamba_formatted, species = "Alcelaphus buselaphus") ## Get data at Garamba (for all species) ---- x <- popbayes::filter_series(garamba_formatted, location = "Garamba") ## Get data for Alcelaphus buselaphus at Garamba only ---- x <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus")
This function applies a Bayesian model to count series in order to infer
the population trend over time. This function only works on the output of
format_data()
or filter_series()
.
Important: This function uses R2jags::jags()
and the
freeware JAGS (https://mcmc-jags.sourceforge.io/) must be
installed.
There are two types of options: model options (argument model_opts
) and
MCMC options (argument mcmc_opts
).
A. Model options
a smoothing factor: the precision (the inverse of variance) of a normal
distribution centered on the current relative rate of increase r from which
the next candidate relative rate of increase (see below) is drawn.
The highest this number, the tighter the link between successive relative
rates of increase. The default 100
corresponds to a moderate link.
a logical indicating whether the population growth must remain limited by
the species demographic potential (provided by the argument rmax
in
format_data()
).
The relative rate of increase is the change in log population size between two dates. The quantity actually being modeled is the relative rate of increase per unit of time (usually one date). This quantity reflects more directly the prevailing conditions than the population size itself, which is the reason why it has been chosen.
When the second model option is set to TRUE
, the candidate rate of
increase is compared to the maximum relative rate of increase
(obtained when using format_data()
) and replaced by rmax
if greater.
B. MCMC options
Classical Markov chain Monte Carlo (MCMC) settings (see argument mcmc_opts
below).
fit_trend( data, model_opts = list(100, TRUE), mcmc_opts = list(ni = 50000, nt = 3, nb = 10000, nc = 2), path = "." )
fit_trend( data, model_opts = list(100, TRUE), mcmc_opts = list(ni = 50000, nt = 3, nb = 10000, nc = 2), path = "." )
data |
a named |
model_opts |
a |
mcmc_opts |
a |
path |
a |
An n-element list
(where n
is the number of count series). Each
element of the list is a BUGS output as provided by JAGS (also written
in the folder path
).
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Get data for Alcelaphus buselaphus at Garamba only ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trend (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Check for convergence ---- popbayes::diagnostic(a_buselaphus_mod, threshold = 1.1) ## Plot estimated population trend ---- popbayes::plot_trend(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Plot MCMC traceplot ---- R2jags::traceplot(a_buselaphus_mod[[1]], ask = TRUE)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Get data for Alcelaphus buselaphus at Garamba only ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trend (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Check for convergence ---- popbayes::diagnostic(a_buselaphus_mod, threshold = 1.1) ## Plot estimated population trend ---- popbayes::plot_trend(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Plot MCMC traceplot ---- R2jags::traceplot(a_buselaphus_mod[[1]], ask = TRUE)
This function provides an easy way to get count series ready to be analyzed
by the package popbayes
. It must be used prior to all other functions.
This function formats the count series (passed through the argument
data
) by selecting and renaming columns, checking columns format and
content, and removing missing data (if na_rm = TRUE
). It converts the
original data frame into a list of count series that will be analyzed later
by the function fit_trend()
to estimate population trends.
To be usable for the estimation of population trends, counts must be
accompanied by information on precision. The population trend model requires
a 95% confident interval (CI).
If estimates are total counts or guesstimates, this function will construct
boundaries of the 95% CI by applying the rules set out in
https://frbcesab.github.io/popbayes/articles/popbayes.html.
If counts were estimated by a sampling method the user needs to specify a
measure of precision. Precision is preferably provided in the form of a 95%
CI by means of two fields: lower_ci
and upper_ci
. It may also be given
in the form of a standard deviation (sd
), a variance (var
), or a
coefficient of variation (cv
). If the fields lower_ci
and upper_ci
are
both absent (or NA
), fields sd
, var
, and cv
are examined in this
order. When one is found valid (no missing value), a 95% CI is derived
assuming a normal distribution.
The field stat_method
must be present in data
to indicate
if counts are total counts ('T'
), sampling ('S'
), or
guesstimate ('X'
).
If a series mixes aerial and ground counts, a field field_method
must
also be present and must contain either 'A'
(aerial counts), or 'G'
(ground counts). As all counts must eventually refer to the same field
method for a correct estimation of trend, a conversion will be performed to
homogenize counts. This conversion is based on a preferred field method
and a conversion factor both specific to a species/category.
The preferred field method specifies the conversion direction. The
conversion factor is the multiplicative factor that must be applied to an
aerial count to get an equivalent ground count (note that if the preferred
field method is 'A'
, ground counts will be divided by the conversion
factor to get the equivalent aerial count).
The argument rmax
represents the maximum change in log population size
between two dates (i.e. the relative rate of increase). It will be used
by fit_trend()
but must be provided in this function.
These three parameters, named pref_field_method
, conversion_A2G
, and
rmax
can be present in data
or in a second data.frame
(passed through the argument info
).
Alternatively, the package popbayes
provides their values for some
African large mammals.
Note: If the field field_method
is absent in data
, counts are
assumed to be obtained with one field method.
format_data( data, info = NULL, date = "date", count = "count", location = "location", species = "species", stat_method = "stat_method", lower_ci = "lower_ci", upper_ci = "upper_ci", sd = NULL, var = NULL, cv = NULL, field_method = NULL, pref_field_method = NULL, conversion_A2G = NULL, rmax = NULL, path = ".", na_rm = FALSE )
format_data( data, info = NULL, date = "date", count = "count", location = "location", species = "species", stat_method = "stat_method", lower_ci = "lower_ci", upper_ci = "upper_ci", sd = NULL, var = NULL, cv = NULL, field_method = NULL, pref_field_method = NULL, conversion_A2G = NULL, rmax = NULL, path = ".", na_rm = FALSE )
data |
a The If individual counts were estimated by sampling, additional column(s)
providing a measure of precision is also required (e.g. If the individuals were counted by different methods, an additional field
Others fields can be present either in |
info |
(optional) a |
date |
a |
count |
a |
location |
a |
species |
a |
stat_method |
a |
lower_ci |
(optional) a |
upper_ci |
(optional) a |
sd |
(optional) a |
var |
(optional) a |
cv |
(optional) a |
field_method |
(optional) a |
pref_field_method |
(optional) a |
conversion_A2G |
(optional) a |
rmax |
(optional) a |
path |
a |
na_rm |
a |
An n-elements list
(where n
is the number of count series). The
name of each element of this list is a combination of location and
species. Each element of the list is a list
with the following content:
location
a character
string. The name of the series site.
species
a character
string. The name of the series species.
date
a numerical
vector. The sequence of dates of the
series.
n_dates
an integer.
The number of unique dates.
stat_methods
a character
vector. The different stat methods
of the series.
field_methods
(optional) a character
vector. The different
field methods of the series.
pref_field_method
(optional) a character
string. The
preferred field method of the species ('A'
or 'G'
).
conversion_A2G
(optional) a numeric
. The conversion factor
of the species used to convert counts to its preferred field method.
rmax
a numeric
. The maximum population growth rate of the
species.
data_original
a data.frame
. Original data of the series
with renamed columns. Some rows may have been deleted
(if na_rm = TRUE
).
data_converted
a data.frame
. Data containing computed
boundaries of the 95% CI (lower_ci_conv
and upper_ci_conv
). If
counts have been obtained by different field methods, contains also
converted counts (count_conv
) based on the preferred field method and
conversion factor of the species. This data.frame
will be used by the
function fit_trend()
to fit population models.
Note: Some original series can be discarded if one of these two conditions is met: 1) the series contains only zero counts, and 2) the series contains only a few dates (< 4 dates).
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Number of count series ---- length(garamba_formatted) ## Retrieve count series names ---- popbayes::list_series(path = temp_path) ## Print content of the first count series ---- names(garamba_formatted[[1]]) ## Print original data ---- garamba_formatted[[1]]$"data_original" ## Print converted data ---- garamba_formatted[[1]]$"data_converted"
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Number of count series ---- length(garamba_formatted) ## Retrieve count series names ---- popbayes::list_series(path = temp_path) ## Print content of the first count series ---- names(garamba_formatted[[1]]) ## Print original data ---- garamba_formatted[[1]]$"data_original" ## Print converted data ---- garamba_formatted[[1]]$"data_converted"
This dataset contains individual counts of 10 African mammal species in the Garamba National Park (Democratic Republic of the Congo) from 1976 to 2017.
garamba
garamba
A data.frame
with 141 rows (counts) and the following 8 variables:
the location of the survey (Garamba)
the binomial name of the species
the date of the survey
the method used to estimate individuals counts. One of
T
(total counts), G
(guesstimate), and S
(sampling counts)
the field method used to collect data. One of
A
(aerial counts), and G
(ground counts)
number of individuals
lower boundary of the 95% confidence interval of the counts (only for sampling counts)
upper boundary of the 95% confidence interval of the counts (only for sampling counts)
the preferred field method of the species. One of
A
for Aerial counts, and G
for Ground counts
the conversion multiplicative factor (corresponding to the detectability category) used to convert aerial to ground counts
the maximum population growth rate
Hillman Smith K & Kalpers J (2015) Garamba Conservation in Peace & War.
Hillman Smith publisher, 448pp. ISBN: 9789966185105.
Monico M (2014)
Aerial Survey Report March 2014 - Garamba National Park, DRC.
African Parks Network/ICCN/Pan-African Elephant Aerial Survey, 42pp.
Spies K et al. (2017)
Aerial Survey Report April 2017 - Garamba National Park, DRC.
African Parks Network/EU/ICCN. 38pp.
data("garamba") head(garamba, 30)
data("garamba") head(garamba, 30)
This function retrieves the count series names generated by
the function format_data()
.
list_series(path = ".")
list_series(path = ".")
path |
a |
A vector of count series names (character
strings).
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Retrieve count series names ---- popbayes::list_series(path = temp_path)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Retrieve count series names ---- popbayes::list_series(path = temp_path)
This function plots a panel of two graphics for one count series
(previously generated by format_data()
):
on the left side, scatter plot overlapping original (black points) and converted counts (grey points);
on the right side, scatter plot of converted counts with boundaries of the 95% confident interval.
plot_series(series, title = TRUE, path = ".", path_fig = ".", save = FALSE)
plot_series(series, title = TRUE, path = ".", path_fig = ".", save = FALSE)
series |
a |
title |
a |
path |
a |
path_fig |
a |
save |
a |
No return value.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Get series names ---- popbayes::list_series(path = temp_path) ## Plot for Alcelaphus buselaphus at Garamba ---- popbayes::plot_series("garamba__alcelaphus_buselaphus", path = temp_path)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Get series names ---- popbayes::list_series(path = temp_path) ## Plot for Alcelaphus buselaphus at Garamba ---- popbayes::plot_series("garamba__alcelaphus_buselaphus", path = temp_path)
This function plots a panel of two graphics for one BUGS model
(previously generated by fit_trend()
):
on the left side, the population trend estimated by the Bayesian model (blue line) with the 95% CI (gray envelop). Dots (with intervals) represent converted counts passed to the model (with the 95% CI);
on the right side, a bar plot of estimated relative growth rates (r) by date. Dark bars are real estimated r.
plot_trend(series, title = TRUE, path = ".", path_fig = ".", save = FALSE)
plot_trend(series, title = TRUE, path = ".", path_fig = ".", save = FALSE)
series |
a |
title |
a |
path |
a |
path_fig |
a |
save |
a |
No return value.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Plot estimated population trend ---- popbayes::plot_trend(series = "garamba__alcelaphus_buselaphus", path = temp_path)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Plot estimated population trend ---- popbayes::plot_trend(series = "garamba__alcelaphus_buselaphus", path = temp_path)
This function imports a list of BUGS outputs previously exported by
fit_trend()
. Users can import one, several, or all models.
read_bugs(series = NULL, path = ".")
read_bugs(series = NULL, path = ".")
series |
a vector of |
path |
a |
An n-element list
(where n
is the number of count series). See
fit_trend()
for further information.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Import BUGS outputs for one count series ---- popbayes::read_bugs(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Import BUGS outputs for all count series ---- popbayes::read_bugs(path = temp_path)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Select one serie ---- a_buselaphus <- popbayes::filter_series(garamba_formatted, location = "Garamba", species = "Alcelaphus buselaphus") ## Fit population trends (requires JAGS) ---- a_buselaphus_mod <- popbayes::fit_trend(a_buselaphus, path = temp_path) ## Import BUGS outputs for one count series ---- popbayes::read_bugs(series = "garamba__alcelaphus_buselaphus", path = temp_path) ## Import BUGS outputs for all count series ---- popbayes::read_bugs(path = temp_path)
This function imports a list of count series data previously exported by
format_data()
. Users can import one, several, or all count series data.
read_series(series = NULL, path = ".")
read_series(series = NULL, path = ".")
series |
a vector of |
path |
a |
An n-element list
(where n
is the number of count series). See
format_data()
for further information.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Import all count series ---- count_series <- popbayes::read_series(path = temp_path) ## Import one count series ---- a_bus <- popbayes::read_series(series = "garamba__alcelaphus_buselaphus", path = temp_path)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Import all count series ---- count_series <- popbayes::read_series(path = temp_path) ## Import one count series ---- a_bus <- popbayes::read_series(series = "garamba__alcelaphus_buselaphus", path = temp_path)
From the output of the function format_data()
(or filter_series()
), this
function extracts data.frame
containing converted counts
(converted = TRUE
) or original counts (converted = FALSE
) for one,
several, or all count series.
The resulting data.frame
has no particular use in popbayes
but it can be
useful for users.
series_to_df(data, converted = TRUE)
series_to_df(data, converted = TRUE)
data |
a named |
converted |
a |
A data.frame
.
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Extract converted count data ---- converted_data <- popbayes::series_to_df(garamba_formatted, converted = TRUE) ## Extract original count data ---- original_data <- popbayes::series_to_df(garamba_formatted, converted = FALSE) dim(converted_data) dim(original_data) dim(garamba)
## Load Garamba raw dataset ---- file_path <- system.file("extdata", "garamba_survey.csv", package = "popbayes") garamba <- read.csv(file = file_path) ## Create temporary folder ---- temp_path <- tempdir() ## Format dataset ---- garamba_formatted <- popbayes::format_data( data = garamba, path = temp_path, field_method = "field_method", pref_field_method = "pref_field_method", conversion_A2G = "conversion_A2G", rmax = "rmax") ## Extract converted count data ---- converted_data <- popbayes::series_to_df(garamba_formatted, converted = TRUE) ## Extract original count data ---- original_data <- popbayes::series_to_df(garamba_formatted, converted = FALSE) dim(converted_data) dim(original_data) dim(garamba)
This dataset contains information about 15 African mammal species.
It can be used in the function format_data()
to convert individual counts
estimated from a field method to a preferred field method. The field method
can be A
(aerial counts) or G
(ground counts). See format_data()
for
further information. It also contains the maximum population growth rate
(i.e. the maximum change in log population size).
User can take this dataset as a template to add information for missing
species. Note that only species
, pref_field_method
, conversion_A2G
,
and rmax
are required.
species_info
species_info
A data.frame
with 15 rows (African mammals species) and the
following variables:
the order of the species
the family of the species
the species binomial name
the species English name
the species French name
the detectability category of the species. One of
MLB
for Medium-sized Light and Brown species (20-150kg),
LLB
for Large Light and Brown species (>150kg),
LD
for Large Dark (>150kg), Elephant
, and Giraffe
the preferred field method of the species. One of
A
for Aerial counts, and G
for Ground counts
the conversion multiplicative factor (corresponding to the detectability category) used to convert aerial to ground counts
the maximum population growth rate
data("species_info") species_info
data("species_info") species_info
The demographic potential of a species is limited. The intrinsic rate of
increase rmax
is the maximum increase in log population size that a
species can attain in a year. According to Sinclair (2003), it is related
to the body mass of adult females by:
w_to_rmax(w)
w_to_rmax(w)
w |
a numerical vector. Adult female body mass (in kg). |
A numerical vector of rmax
values.
Sinclair (2013) Mammal population regulation, keystone processes and ecosystem dynamics. Philosophical Transactions: Biological Sciences, 358, 1729-1740.
## Set adult female body mass ---- body_masses <- c(55, 127) ## Add species names ---- names(body_masses) <- c("Impala", "Tiang") ## Compute species rmax ---- w_to_rmax(body_masses)
## Set adult female body mass ---- body_masses <- c(55, 127) ## Add species names ---- names(body_masses) <- c("Impala", "Tiang") ## Compute species rmax ---- w_to_rmax(body_masses)