Title: | Complementary Package to 'nicheROVER' and 'SIBER' |
---|---|
Description: | Provides functions complementary to packages 'nicheROVER' and 'SIBER' allowing the user to extract Bayesian estimates from data objects created by the packages 'nicheROVER' and 'SIBER'. Please see the following publications for detailed methods on 'nicheROVER' and 'SIBER' Hansen et al. (2015) <doi:10.1890/14-0235.1>, Jackson et al. (2011) <doi:10.1111/j.1365-2656.2011.01806.x>, and Layman et al. (2007) <doi:10.1890/0012-9658(2007)88[42:CSIRPF]2.0.CO;2>, respectfully. |
Authors: | Benjamin L. Hlina [aut, cre] |
Maintainer: | Benjamin L. Hlina <[email protected]> |
License: | CC0 |
Version: | 0.3.2 |
Built: | 2024-11-15 06:11:15 UTC |
Source: | https://github.com/benjaminhlina/nichetools |
Creates a list with all of the comparisons needed to create Bayesian and maximum-likelihood estimates for proportion of niche similarities.
create_comparisons(data, comparison = c("within", "among"))
create_comparisons(data, comparison = c("within", "among"))
data |
a |
comparison |
a |
# ---- load siber ---- library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_names <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_names) |> as.character() cg_names <- demo.siber.data.2 |> dplyr::distinct(community, group, community_names, group_name) # ---- create comparsions ---- create_comparisons(cg_names, comparison = "within")
# ---- load siber ---- library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_names <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_names) |> as.character() cg_names <- demo.siber.data.2 |> dplyr::distinct(community, group, community_names, group_name) # ---- create comparsions ---- create_comparisons(cg_names, comparison = "within")
Extract group metrics within each community from a matrix object
that is produced by groupMetricsML()
function from
SIBER. These metrics
are the following the convex hull total area (TA), Standard Ellipse Area (SEA), and the
corresponding small sample size corrected version SEAc based on the maximum likelihood
estimates of the means and covariance matrices of each group.
extract_group_metrics(data = NULL, community_df = NULL, data_format = NULL)
extract_group_metrics(data = NULL, community_df = NULL, data_format = NULL)
data |
a |
community_df |
a four column data frame. One of the columns has to be named
|
data_format |
a |
A tibble
containing four rows when data_format
is set to its
default which is long
. These four rows are the following, community
,
the_name_of_the_communities
, metric
and post_est
.
library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) # ---- create comparsions ---- demo.siber.data.2 <- demo.siber.data.2[,1:4] siber_example <- createSiberObject(demo.siber.data.2) # extract group metrics group_ml <- groupMetricsML(siber_example) group_convert <- extract_group_metrics(data = group_ml, community_df = cg_name)
library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) # ---- create comparsions ---- demo.siber.data.2 <- demo.siber.data.2[,1:4] siber_example <- createSiberObject(demo.siber.data.2) # extract group metrics group_ml <- groupMetricsML(siber_example) group_convert <- extract_group_metrics(data = group_ml, community_df = cg_name)
Extract Bayesian estimates for the following six layman metrics,
C range,
N range, total area (TA),
distance to centroid (CD), distance to the nearest neighbour (NND), and
the standard deviation of the distance to the nearest neighbour (SDNND)
from data objects created by
SIBER. To learn
more about the following metrics please review
Layman et al. (2008).
extract_layman( data, type = NULL, community_df = NULL, data_format = NULL, isotope_x = NULL, isotope_y = NULL, element_x = NULL, element_y = NULL )
extract_layman( data, type = NULL, community_df = NULL, data_format = NULL, isotope_x = NULL, isotope_y = NULL, element_x = NULL, element_y = NULL )
data |
a |
type |
a |
community_df |
a two column data frame. One of the columns has to be named
|
data_format |
a |
isotope_x |
a |
isotope_y |
a |
element_x |
a |
element_y |
a |
A tibble
containing four rows when data_format
is set to its
default which is long
. These four rows are the following, community
,
the_name_of_the_communities
, metric
and post_est
.
SIBER::bayesianLayman()
and SIBER::createSiberObject()
library(SIBER) # ---- bring in SIBER demo data ---- # uncomenet to use # str(demo.siber.data) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_names <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_names) |> as.character() c_names <- demo.siber.data.2 |> dplyr::distinct(community, community_names) demo.siber.data_2 <- demo.siber.data.2[,1:4] # ---- create the siber object ---- siber.example <- createSiberObject(demo.siber.data_2) # ---- view Bayesian estimates of mu and sigma produced by SIBER --- # uncomment to use # str(post_sam_siber) # ---- extract posterior estimates of mu ----- mu_post <- extractPosteriorMeans(siber.example, post_sam_siber) # ---- Bayesian estimates of layman metrics using SIBER ---- layman_b <- bayesianLayman(mu.post = mu_post) # ---- use nichetools to extract Bayesian estimates of Layman metrics ---- layman_be <- extract_layman(layman_b, community_df = c_names) layman_be
library(SIBER) # ---- bring in SIBER demo data ---- # uncomenet to use # str(demo.siber.data) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_names <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_names) |> as.character() c_names <- demo.siber.data.2 |> dplyr::distinct(community, community_names) demo.siber.data_2 <- demo.siber.data.2[,1:4] # ---- create the siber object ---- siber.example <- createSiberObject(demo.siber.data_2) # ---- view Bayesian estimates of mu and sigma produced by SIBER --- # uncomment to use # str(post_sam_siber) # ---- extract posterior estimates of mu ----- mu_post <- extractPosteriorMeans(siber.example, post_sam_siber) # ---- Bayesian estimates of layman metrics using SIBER ---- layman_b <- bayesianLayman(mu.post = mu_post) # ---- use nichetools to extract Bayesian estimates of Layman metrics ---- layman_be <- extract_layman(layman_b, community_df = c_names) layman_be
Extract Bayesian estimates of from data objects created by
nicheROVER or
SIBER.
extract_mu( data, pkg = NULL, isotope_names = NULL, data_format = NULL, community_df = NULL )
extract_mu( data, pkg = NULL, isotope_names = NULL, data_format = NULL, community_df = NULL )
data |
a |
pkg |
a |
isotope_names |
is a vector of |
data_format |
a |
community_df |
a four column data frame. One of the columns has to be named
|
Returns a tibble
of extracted estimates of created by the
function
niw.post()
or siberMVN()
in the packages
nicheROVER.
and SIBER.
The tibble
will contain five columns in the following order, metric
,
sample_name
, sample_number
, and the names of the isotope
columns supplied to niw.post()
or siberMVN()
(e.g., d13c
and d15n
).
nicheROVER::niw.post()
and SIBER::siberMVN()
extract_mu( data = niw_fish_post ) library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) extract_mu( data = post_sam_siber, pkg = "SIBER", community_df = cg_name )
extract_mu( data = niw_fish_post ) library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) extract_mu( data = post_sam_siber, pkg = "SIBER", community_df = cg_name )
Extract niche size based on elliptical niche region of Bayesian estimates of
sigma created by function niw.post()
or siberEllipses()
in the package
nicheROVER or
SIBER, respectfully.
For nicheROVER
this function is a wrapper around nicheROVER::niche.size
.
extract_niche_size( data, pkg = NULL, name = NULL, prob = NULL, community_df = NULL )
extract_niche_size( data, pkg = NULL, name = NULL, prob = NULL, community_df = NULL )
data |
a |
pkg |
a |
name |
a |
prob |
a |
community_df |
a four column data frame. One of the columns has to be named
|
if pkg
is set to "nicheROVER"
then a tibble
containing three rows, sample_name
, id
, and niche_size
is returned.
nicheROVER::niche.size()
, nicheROVER::niw.post()
,
SIBER::siberEllipses()
, and SIBER::createSiberObject()
extract_niche_size(data = niw_fish_post)
extract_niche_size(data = niw_fish_post)
Extract Bayesian estimates of similarities among groups produced by the
following function overlap()
in the package
nicheROVER.
extract_overlap(data, name_a = NULL, name_b = NULL)
extract_overlap(data, name_a = NULL, name_b = NULL)
data |
a |
name_a |
character string to supply for the first
|
name_b |
character string to supply for the second
|
A tibble
containing five rows, sample_name_a
, id
,
sample_name_b
, sample_number
, and niche_overlap
.
extract_overlap(data = over_stat)
extract_overlap(data = over_stat)
Extract Bayesian estimates of from data objects created by
nicheROVER
or SIBER.
extract_sigma( data, pkg = NULL, isotope_n = NULL, isotope_names = NULL, data_format = NULL )
extract_sigma( data, pkg = NULL, isotope_n = NULL, isotope_names = NULL, data_format = NULL )
data |
a |
pkg |
a |
isotope_n |
a |
isotope_names |
is a vector of |
data_format |
a |
Returns a tibble
of extracted estimates of created by
the function
niw.post()
or siberMVN()
in the packages
nicheROVER.
and SIBER.
The returned object will contain five columns in the
following order when data_format
is set to "wide"
,
metric
, id
, sample_name
, isotope
, sample_number
,
and the posterior sample for (e.g.,
d13c
and d15n
).
nicheROVER::niw.post()
and SIBER::siberMVN()
extract_sigma( data = niw_fish_post ) extract_sigma( data = post_sam_siber, pkg = "SIBER" )
extract_sigma( data = niw_fish_post ) extract_sigma( data = post_sam_siber, pkg = "SIBER" )
Extract niche similarities from objects created by {SIBER}
.
extract_similarities(data, type = c("bay", "ml"), community_df = NULL)
extract_similarities(data, type = c("bay", "ml"), community_df = NULL)
data |
a |
type |
a |
community_df |
a four column data frame. One of the columns has to be named
|
library(purrr) library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) # ---- create comparsions ---- cg_names_within_c <- create_comparisons(cg_name, comparison = "within") demo.siber.data.2 <- demo.siber.data.2[,1:4] siber_example <- createSiberObject(demo.siber.data.2) ml_within_overlap <- cg_names_within_c |> map(~ maxLikOverlap(.x$cg_1, .x$cg_2, siber_example, p.interval = NULL, n = 100), .progress = TRUE) ml_95_within_com <- extract_similarities(ml_within_overlap, type = "ml", community_df = cg_name)
library(purrr) library(SIBER) # ---- create community names data frame ---- # uncomment to use # str(demo.siber.data.2) demo.siber.data.2$group_name <- as.factor(demo.siber.data.2$group) demo.siber.data.2$group <- as.numeric(demo.siber.data.2$group_name) |> as.character() demo.siber.data.2$community_name <- as.factor(demo.siber.data.2$community) demo.siber.data.2$community <- as.numeric(demo.siber.data.2$community_name) |> as.character() cg_name <- demo.siber.data.2 |> dplyr::distinct(community, group, community_name, group_name) # ---- create comparsions ---- cg_names_within_c <- create_comparisons(cg_name, comparison = "within") demo.siber.data.2 <- demo.siber.data.2[,1:4] siber_example <- createSiberObject(demo.siber.data.2) ml_within_overlap <- cg_names_within_c |> map(~ maxLikOverlap(.x$cg_1, .x$cg_2, siber_example, p.interval = NULL, n = 100), .progress = TRUE) ml_95_within_com <- extract_similarities(ml_within_overlap, type = "ml", community_df = cg_name)
data.frame
containing posterior estimates of
Posterior estimates of using
fish
data set from
nicheROVER,
using Normal-Inverse-Wishart (NIW) priors.
mu_est_long
mu_est_long
data.frame
containing 8,000 rows and 7 variables
name of the metric extracted from niw.post()
species abbreviation
sample number from 1-1000
column with isotope name
estimate of mu produced from niw.post()
isotopic element used in labelling
neutron number used in labelling
and
This function allows the user to supply Bayesian estimates of and
to create estimated Bayesian ellipse for niche region.
niche_ellipse( dat_mu, dat_sigma, isotope_a = NULL, isotope_b = NULL, p_ell = NULL, random = NULL, set_seed = NULL, n = NULL, message = TRUE )
niche_ellipse( dat_mu, dat_sigma, isotope_a = NULL, isotope_b = NULL, p_ell = NULL, random = NULL, set_seed = NULL, n = NULL, message = TRUE )
dat_mu |
a |
dat_sigma |
a |
isotope_a |
character string that is the column name of the first
isotope used in |
isotope_b |
character string that is the column name of the second
isotope used in |
p_ell |
is the confidence interval of each ellipse estimate.
Default is 0.95 (i.e., 95% confidence interval).
This value is bound by 0 and 1 and has to be a |
random |
logical value indicating whether or not to randomly sample
posterior distributions for |
set_seed |
numerical value to set seed for random sampling. Default is
a random value. To consistently sample the same subsample, please supply
a numerical value (e.g., |
n |
numerical value that controls the number of random samples.
Default is |
message |
control whether the time processing is displayed after the
end of the function. Default is |
A tibble
containing, sample_name
, sample_number
, and the
isotopes that were used in the estimation of ellipse
(i.e., and d13c
and d15n
).
nicheROVER::niw.post()
, SIBER::siberMVN()
, extract_mu()
,
and extract_sigma()
niche_ellipse(dat_mu = mu_est_long, dat_sigma = sigma_est_wide)
niche_ellipse(dat_mu = mu_est_long, dat_sigma = sigma_est_wide)
list
of the posterior estimates of
and
from {nicheROVER}
Posterior estimates of and
using the
fish
data set from
nicheROVER,
using Normal-Inverse-Wishart (NIW) priors.
This list
is produced using the function niw.post()
from
nicheROVER.
niw_fish_post
niw_fish_post
A list
with elements and
of sizes c(nsamples, length(lambda))
and c(dim(Psi)).
data.frame
containing the estimates of percentage of overlap among groupsEstimates of the percentage of overlap among example species used in nicheROVER.
over_stat
over_stat
A array
containing matrices
of the percent overlap for each group
used in Bayesian estimates of and
using
Normal-Inverse-Wishart (NIW) priors calculated in
niw.post()
.
list
of the posterior estimates of
and
from {SIBER}
Posterior estimates of and
using the
demo.siber.data.2
data set from SIBER.
This list
is produced using the function siberMVN()
from
SIBER.
post_sam_siber
post_sam_siber
A list
with estimates of and
for each species
and group.
data.frame
containing posterior estimates of
Posterior estimates of using
fish
data set from
nicheROVER,
using Normal-Inverse-Wishart (NIW) priors
sigma_est_wide
sigma_est_wide
data.frame
containing 8,000 rows and 6 variables
name of the metric extracted from niw.post()
species abbreviation
column with isotope name
sample number from 1-1000
estimate of for d15n produced from
niw.post()
estimate of for d13c produced from
niw.post()