Title: | Analysis of Ecological Drivers on Ecosystem Multifunctionality |
---|---|
Description: | Methods for the analysis of how ecological drivers affect the multifunctionality of an ecosystem based on methods of Byrnes et al. 2016 <doi:10.1111/2041-210X.12143> and Byrnes et al. 2022 <doi:10.1101/2022.03.17.484802>. Most standard methods in the literature are implemented (see vignettes) in a tidy format. |
Authors: | Jarrett Byrnes [aut, cre, cph] |
Maintainer: | Jarrett Byrnes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.9.3 |
Built: | 2024-11-02 03:42:26 UTC |
Source: | https://github.com/jebyrnes/multifunc |
Data from the pan-European Biodepth grassland diversity manipulation
Jarrett Byrnes
Spehn, E. M., A. Hector, J. Joshi, M. Scherer-Lorenzen, B. Schmid, E. Bazeley-White, C. Beierkuhnlein, M. C. Caldeira, M. Diemer, P. G. Dimitrakopoulos, J. A. Finn, H. Freitas, P. S. Giller, J. Good, R. Harris, P. Hogberg, K. Huss-Danell, A. Jumpponen, J. Koricheva, P. W. Leadley, M. Loreau, A. Minns, C. P. H. Mulder, G. O'Donovan, S. J. Otway, C. Palmborg, J. S. Pereira, A. B. Pfisterer, A. Prinz, D. J. Read, E. D. Schulze, A. S. Siamantziouras, A. C. Terry, A. Y. Troumbis, F. I. Woodward, S. Yachi, and J. H. Lawton. 2005. Ecosystem effects of biodiversity manipulations in European grasslands. Ecological Monographs 75:37-63.
Takes a data frame of functions and calculates the correlation-based distance between functions.
cor_dist(adf)
cor_dist(adf)
adf |
A |
A matrix
divNeeded
Determines, for every combination of functions, how many species
influence those functions.
divNeeded(overData, type = "positive")
divNeeded(overData, type = "positive")
overData |
Matrix of functions and which species affect them from |
type |
Are the kinds of effects we're looking at "positive", "negative" or "all". |
Iterates over all possible combinations of functions. Checks the matrix of which species have positive, negative, or both influences on those functions. Tally's total number of species that have an effect on those functions
Returns a data frame of all combinations and how many species are needed to influence all of them.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the # same sign-scale (e.g. the maximum level of a # function is the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) posCurve <- divNeeded(redund, type = "positive")
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the # same sign-scale (e.g. the maximum level of a # function is the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) posCurve <- divNeeded(redund, type = "positive")
Calculates the average distance between functions for one or an entire assemblage of replicates
dmean(adf_raw, D)
dmean(adf_raw, D)
adf_raw |
A data frame frame with functions in columns and rows as replicates |
D |
A distance matrix describing dissimilarity between functions. |
Single numeric of weighted average of distance matrix
Byrnes, J. E. K., Roger, F. and Bagchi, R. 2022. Understandable Multifunctionality Measures Using Hill Numbers. bioRxiv. 2022.03.17.484802. https://doi.org/10.1101/2022.03.17.484802
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
Calculates the minimum non-zero value of a distance matrix
dmin(D)
dmin(D)
D |
A distance matrix describing dissimilarity between functions. |
A numeric
Data from the a seagrass grazer diversity manipulation at the Virginia Institute of Marine Sciences. From Duffy et al. 2003 Ecology Letters.
Jarrett Byrnes
Duffy, J. E., J. P. Richardson, and E. A. Canuel. 2003. Grazer diversity effects on ecosystem functioning in seagrass beds. Ecology letters 6:637-645.
Calculate the effective number of functions for rows in a dataset
eff_num_func(dat, vars, q = 1, standardized = FALSE, D = NULL, tau = NULL)
eff_num_func(dat, vars, q = 1, standardized = FALSE, D = NULL, tau = NULL)
dat |
A data frame with functions in columns and rows as replicates as well as other information. |
vars |
Column names of function variables |
q |
Order of the diversity measure. Defaults to the Shannon case where q = 1. For Simpson, q=2. |
standardized |
Use standardized number of functions (scaled by total
number of functions, so between 0-1), or just raw effective number of
functions for calculation. Defaults to |
D |
A distance matrix describing dissimilarity between functions. Defaults
to NULL, and the index is calculated assuming all functions are different. If
it is not null, it must be a symmetric matrix with dimensions matching the
number of functions listed in |
tau |
A cutoff for degree of dissimilarity under which functions are considered to be different. If tau is the minimum non-zero value of D, all functions are different. if tau is the maximum value of D are greater, all functions are considered the same. |
Takes a data frame, variable names, whether we want an index standardized by number of functions or not, an order of Hill number for our effective number of functions as well as a dissimilarity matrix (if desired) and value for a dissimilarity cutoff (defaults to the average dissimilarity). It then calculates and returns the effective number of functions using the appropriate method. See Chao et al. 2019 for more.
Returns a vector of effective or standardized effective number of functions
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
Jost, L. 2006. Entropy and diversity. Oikos 113(2): 363-375.
Hill, M. 1973. Diversity and evenness: A unifying notation and its consequences. Ecology 54: 427-432.
eff_num_func_d
eff_num_func_d(adf_freq, q = 1, D, tau = NULL)
eff_num_func_d(adf_freq, q = 1, D, tau = NULL)
adf_freq |
A data frame of functional "frequencies" - i.e. f_i/sum(f_i) |
q |
Order of hill number used for index. Defaults to q=1, as in Shannon Diversity |
D |
A distance matrix describing dissimilarity between functions. |
tau |
A cutoff for degree of dissimilarity under which functions are considered to be different. If tau is the minimum non-zero value of D, all functions are different. if tau is the maximum value of D are greater, all functions are considered the same. |
A vector of effective number of functions
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
eff_num_func_d_onerow
eff_num_func_d_onerow(arow_freq, D, tau, q)
eff_num_func_d_onerow(arow_freq, D, tau, q)
arow_freq |
One replicate sample of different functions (a single numeric vector) |
D |
A distance matrix describing dissimilarity between functions. |
tau |
A cutoff for degree of dissimilarity under which functions are considered to be different. If tau is the minimum non-zero value of D, all functions are different. if tau is the maximum value of D are greater, all functions are considered the same. |
q |
Order of hill number used for index. Defaults to q=1, as in Shannon Diversity |
A single value of effective number of functions
Byrnes, J. E. K., Roger, F. and Bagchi, R. 2022. Understandable Multifunctionality Measures Using Hill Numbers. bioRxiv. 2022.03.17.484802. https://doi.org/10.1101/2022.03.17.484802
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
eff_num_func_no_d
eff_num_func_no_d(adf_freq, q = 1)
eff_num_func_no_d(adf_freq, q = 1)
adf_freq |
A data frame of functional "frequencies" - i.e. f_i/sum(f_i) |
q |
Order of hill number used for index. Defaults to q=1, as in Shannon Diversity |
Takes a data frame, with functions standardized against total level of function in their replicate as columns and replicates as rows. Returns the effective number of functions using the appropriate method. See Chao et al. 2019 or Jost 2006 for details. Does not adjust for correlation between functions.
Returns a verctor of effective or standardized effective number of functions
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
Jost, L. 2006. Entropy and diversity. Oikos 113(2): 363-375.
Hill, M. 1973. Diversity and evenness: A unifying notation and its consequences. Ecology 54: 427-432.
filterCoefData
filters contributions of species
to function by sign.
filterCoefData(coefData, type = "positive")
filterCoefData(coefData, type = "positive")
coefData |
Matrix of functions and coefficients for which species affect them from |
type |
Are the kinds of effects we're looking at "positive", "negative" or "all". |
Takes a matrix of functions and coefficients for species and filters out only the sign of contributions desired. Typically used by other functions in the package.
Returns a filtered matrix.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars coefs <- getRedundancy(vars, species, germany, output = "coef") stdCoefs <- stdEffects(coefs, germany, vars, species) filterCoefData(stdCoefs) ######### # filterCoefData takes a matrix of coefficients # and filters it so that only the positive, negative, or both contributions # are present #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars coefs <- getRedundancy(vars, species, germany, output = "coef") stdCoefs <- stdEffects(coefs, germany, vars, species) filterCoefData(stdCoefs) ######### # filterCoefData takes a matrix of coefficients # and filters it so that only the positive, negative, or both contributions # are present #########
filterOverData
filters qualitative effects of species
to function by sign.
filterOverData(overData, type = "positive")
filterOverData(overData, type = "positive")
overData |
Matrix of functions and which species affect them from |
type |
Are the kinds of effects we're looking at "positive", "negative" or "all". |
Takes a matrix of functions and effects of species - 1's and -1's, s - and filters out only the sign of contributions desired. Typically used by other functions in the package.
Returns a filtered matrix.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is the # "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) filterOverData(redund, type = "positive") ######### # filterOverData takes a matrix of 1s, 0s, and -1s # and filters it so that only the positive, negative, or both contributions # are 1 for later overlap function usage #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is the # "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) filterOverData(redund, type = "positive") ######### # filterOverData takes a matrix of 1s, 0s, and -1s # and filters it so that only the positive, negative, or both contributions # are 1 for later overlap function usage #########
getCoefTab
extract the effect of diversity on number of functions greater than
a threshold
getCoefTab( eqn, fun = stats::glm, data, groupVar = "thresholds", coefVar = NULL, ... )
getCoefTab( eqn, fun = stats::glm, data, groupVar = "thresholds", coefVar = NULL, ... )
eqn |
The model to be fit at each threshold. |
fun |
The fitting function. Defaults to |
data |
A data frame containing the variables in the model to be fit. |
groupVar |
Grouping variable. Defaults to "thresholds" to fit the model at different thresholds, but, other types of grouping are possible. |
coefVar |
The name of the variable from the model whose coefficient we'll be extracting. |
... |
Other arguments to be supplied to the fitting function |
getCoefTab Takes a statistical model and plot level data with the number of functions greater than a threshold at multiple different thresholds and returns the coefficient for the effect of diversity at each threshold
Returns a data frame of thresholds, coefficients, and their statistical properties.
Jarrett Byrnes.
## Not run: data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.05, threshmax = 0.99, prepend = c("plot", "Diversity"), maxN = 7 ) germanyLinearSlopes <- getCoefTab(funcMaxed ~ Diversity, data = germanyThresh, coefVar = "Diversity", family = quasipoisson(link = "identity") ) ## End(Not run)
## Not run: data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.05, threshmax = 0.99, prepend = c("plot", "Diversity"), maxN = 7 ) germanyLinearSlopes <- getCoefTab(funcMaxed ~ Diversity, data = germanyThresh, coefVar = "Diversity", family = quasipoisson(link = "identity") ) ## End(Not run)
getFuncMaxed
the number of functions greater than or equal to a single threshold in one experimental unit
getFuncMaxed( adf, vars = NA, thresh = 0.7, proportion = FALSE, prepend = "Diversity", maxN = 1 )
getFuncMaxed( adf, vars = NA, thresh = 0.7, proportion = FALSE, prepend = "Diversity", maxN = 1 )
adf |
A data frame with functions. |
vars |
The column names of the functions to be assessed. |
thresh |
The threshold value to assess. |
proportion |
Whether the output will be returned as a proportion of all functions. Defaults to |
prepend |
Additional columns that will be imported from the data for the returned data frame. |
maxN |
As a 'maximum' value can be subject to outliers, etc., what number of the highest data points for a function will be used to calculate the value against which thresholds will be judged. E.g., if maxN=1 then all thresholds are proportions of the largest value measured for a function. If maxN=8, then it's the proportion of the mean of the highest 8 measurements. |
Create a data frame that has the value of number or proportion of functions greater than a single threshold.
Returns a data frame of number or fraction of functions greater than or equal to the selected thresholds in each plot.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncMaxed(germany, vars, thresh = 0.5, prepend = c("plot", "Diversity"), maxN = 7) # A function that will return a data frame with the first several columns # being information the user wants for identification purposes (prepend) # which defaults to Diversity and the final column the number of columns # which pass a predefined threshold, defined as some proportion of the maximim # observed for each column. vars=the names of the vars being specified # thresh is the threshold, between 0 and 1, of proportion of the max that needs # to be passed to be counted. # changelog # 2014-03-24 Fixed -1 error in getMaxValue # 2015-06-24 Fixed column name from prepend error https://github.com/jebyrnes/multifunc/issues/1 # 2022-04-14 Updated to use dplyr
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncMaxed(germany, vars, thresh = 0.5, prepend = c("plot", "Diversity"), maxN = 7) # A function that will return a data frame with the first several columns # being information the user wants for identification purposes (prepend) # which defaults to Diversity and the final column the number of columns # which pass a predefined threshold, defined as some proportion of the maximim # observed for each column. vars=the names of the vars being specified # thresh is the threshold, between 0 and 1, of proportion of the max that needs # to be passed to be counted. # changelog # 2014-03-24 Fixed -1 error in getMaxValue # 2015-06-24 Fixed column name from prepend error https://github.com/jebyrnes/multifunc/issues/1 # 2022-04-14 Updated to use dplyr
getFuncsMaxed
the number of functions greater than or equal to a wide variety of thresholds in each experimental unit
getFuncsMaxed( adf, vars = NA, threshmin = 0.05, threshmax = 0.99, threshstep = 0.01, proportion = FALSE, prepend = "Diversity", maxN = 1 )
getFuncsMaxed( adf, vars = NA, threshmin = 0.05, threshmax = 0.99, threshstep = 0.01, proportion = FALSE, prepend = "Diversity", maxN = 1 )
adf |
A data frame with functions. |
vars |
The column names of the functions to be assessed. |
threshmin |
The lowest threshold value to assess. |
threshmax |
The highest threshold value to assess |
threshstep |
The incremental steps between lowest and highest thresholds to be assessed. See |
proportion |
Whether the output will be returned as a porportion of all functions. Defaults to |
prepend |
Additional columns that will be imported from the data for the returned data frame. |
maxN |
As a 'maximum' value can be subject to outliers, etc., what number of the highest data points for a function will be used to calculate the value against which thresholds will be judged. E.g., if maxN=1 then all thresholds are porportions of the largest value measured for a function. If maxN=8, then it's the porportion of the mean of the highest 8 measurements. |
Create a data frame that has the value of number or proportion of functions greater than a threshold for several different thresholds at the plot.
Returns a data frame of number or fraction of functions greater than or equal to the selected thresholds in each plot over all thresholds within the relevant range.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.50, threshmax = 0.60, prepend = c("plot", "Diversity"), maxN = 7 )
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.50, threshmax = 0.60, prepend = c("plot", "Diversity"), maxN = 7 )
getIndices
Generates a variety of indices describing multifunctionality based on
the number of functions greater than a threshold for many different threshold and coefficients describing
the relationship between diversity and number of functoins greater than a threshold.
getIndices( slopedata, threshdata, eqn, fun = stats::glm, divvar = "Diversity", groupVar = "thresholds", showNfunc = T )
getIndices( slopedata, threshdata, eqn, fun = stats::glm, divvar = "Diversity", groupVar = "thresholds", showNfunc = T )
slopedata |
A data frame with slopes of the relationship between diversity and number of functions greather than or equal to a threshold
from |
threshdata |
A data frame with the number of functions greater than a threshold for each plot at each threshold from |
eqn |
The formula used for fitting the models in slopedata. |
fun |
The function used to refit the threshold data at key points to get intercepts, etc., that are needed for the table. |
divvar |
The name of the variable that has the measure of diversity or other driver in the threshdata data frame. |
groupVar |
The name of a variable by which data is grouped in the threshdata data frame. Typically "thresholds" from |
showNfunc |
Show the functions at Tmin, Tmax, and Tmde. Defaults to TRUE. |
See Byrnes et al. In Review.
A data frame of indices
Jarrett Byrnes.
## Not run: data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.05, threshmax = 0.99, prepend = c("plot", "Diversity"), maxN = 7 ) germanyLinearSlopes <- getCoefTab(funcMaxed ~ Diversity, data = germanyThresh, coefVar = "Diversity", family = quasipoisson(link = "identity") ) getIndices(germanyLinearSlopes, germanyThresh, funcMaxed ~ Diversity) ## End(Not run)
## Not run: data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) germanyThresh <- getFuncsMaxed(germany, vars, threshmin = 0.05, threshmax = 0.99, prepend = c("plot", "Diversity"), maxN = 7 ) germanyLinearSlopes <- getCoefTab(funcMaxed ~ Diversity, data = germanyThresh, coefVar = "Diversity", family = quasipoisson(link = "identity") ) getIndices(germanyLinearSlopes, germanyThresh, funcMaxed ~ Diversity) ## End(Not run)
A multifunctionality index rooted in Hill numbers.
getMF_eff
get multifunctionality index defined by function and effective number of functions
getMF_eff( data, vars, q = 1, standardized = FALSE, standardize_function = standardizeUnitScale, D = NULL, tau = NULL )
getMF_eff( data, vars, q = 1, standardized = FALSE, standardize_function = standardizeUnitScale, D = NULL, tau = NULL )
data |
A data frame with functions in columns and rows as replicates as well as other information. |
vars |
Name of function variables |
q |
Order of the diversity measure. Defaults to the Shannon case where q = 1. For Simpson, q=2. |
standardized |
Use standardized number of functions (scaled by total
number of functions, so between 0-1), or just raw effective number of
functions for calculation. Defaults to |
standardize_function |
A function to standardize each individual
function to the same scale, such as |
D |
A distance matrix describing dissimilarity between functions. Defaults
to NULL, and the index is calculated assuming all functions are different. If
it is not null, it must be a symmetric matrix with dimensions matching the
number of functions listed in |
tau |
A cutoff for degree of dissimilarity under which functions are considered to be different. If tau is the minimum non-zero value of D, all functions are different. if tau is the maximum value of D are greater, all functions are considered the same. |
Takes a data frame, variable names, a standardizing function, whether we want an index standardized by number of functions or not, an order of Hill number for our effective number of functions as well as a dissimilarity matrix (if desired) and value for a dissimilarity cutoff (defaults to the average dissimilarity). It then calculates both the average standardized function in each plot and the effective number of functions and returns their product as a measure of effective multifunctionality.
Returns a vector of effective or standardized effective multifunctionality.
Jarrett Byrnes.
Chao, A., Chiu, C.-H., Villéger, S., Sun, I.-F., Thorn, S., Lin, Y.-C., Chiang, J.-M. and Sherwin, W. B. 2019. An attribute-diversity approach to functional diversity, functional beta diversity, and related (dis)similarity measures. Ecological Monographs. 89: e01343.
Jost, L. 2006. Entropy and diversity. Oikos 113(2): 363-375.
Hill, M. 1973. Diversity and evenness: A unifying notation and its consequences. Ecology 54: 427-432.
getOverlap
goes through all m-wise combinations of species
and returns the amount of overlap between species in functions they perform
for each combination
getOverlap( overData, m = 2, type = "positive", index = "sorensen", denom = "set" )
getOverlap( overData, m = 2, type = "positive", index = "sorensen", denom = "set" )
overData |
Matrix of functions and which species affect them from |
m |
Number of functions. Defaults to 2. |
type |
Are the kinds of effects we're looking at "positive", "negative" or "all". |
index |
Type of overlap index to be used. Defaults to "sorenson" but currently incorporates "mountford" and "jaccard" as well. |
denom |
Should the denominator be "all" species or just the "set" of species with the types of interactions being considered? Defaults to "set". |
getOverlap takes a matrix of 1s and -1s, and depending on whether we're interested in positive, negative, or both types of interactions looks for the m-wise overlap between species and returns the overlap index for each combination
Returns a vector of overlap indices.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the # same sign-scale (e.g. the maximum level of a function is the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) getOverlap(redund, m = 2) getOverlap(redund, m = 2, index = "jaccard") getOverlap(redund, m = 2, index = "mountford") ######### # getOverlap takes a matrix of 1s and -1s, and depending on whether we're # interested in positive, negative, or both types of interactions looks for the # m-wise overlap #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the # same sign-scale (e.g. the maximum level of a function is the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) getOverlap(redund, m = 2) getOverlap(redund, m = 2, index = "jaccard") getOverlap(redund, m = 2, index = "mountford") ######### # getOverlap takes a matrix of 1s and -1s, and depending on whether we're # interested in positive, negative, or both types of interactions looks for the # m-wise overlap #########
getOverlapSummary
summarizes the number of species necessary for each function
including means, SDs, and other metrics
getOverlapSummary( overData, m = 2, type = "positive", index = "sorensen", denom = "set" )
getOverlapSummary( overData, m = 2, type = "positive", index = "sorensen", denom = "set" )
overData |
Matrix of functions and which species affect them from |
m |
Number of functions. Defaults to 2. |
type |
Are the kinds of effects we're looking at "positive", "negative" or "all". |
index |
Type of overlap index to be used by |
denom |
Type of denominator to be used by |
getOverlapSummary takes a matrix of 1s and -1s, and depending on whether we're interested in positive, negative, or both types of interactions looks for the m-wise overlap between species and then reports summary metrics of mean overlap, SD, and number of combinations
Returns a data frame of the mean overlap, SD, and number of possible combinations.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) getOverlapSummary(redund, m = 2) ######### # getOverlapSummary takes a matrix of 1s and -1s, and depending on whether we're # interested in positive, negative, or both types of interactions looks for the # m-wise overlap and then reports summary metrics of mean overlap, SD, and number of combinations #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars redund <- getRedundancy(vars, species, germany) getOverlapSummary(redund, m = 2) ######### # getOverlapSummary takes a matrix of 1s and -1s, and depending on whether we're # interested in positive, negative, or both types of interactions looks for the # m-wise overlap and then reports summary metrics of mean overlap, SD, and number of combinations #########
getRedundancy
examines which species have an effect on which function
getRedundancy( vars, species, data, negVars = NA, method = "lm", combine = "+", output = "effect", ... )
getRedundancy( vars, species, data, negVars = NA, method = "lm", combine = "+", output = "effect", ... )
vars |
Vector of column names of functions |
species |
Vector of column names of species |
data |
data frame with species presence/absence of values of functions |
negVars |
Vector of names of species for which a negative coefficient is actually a positive effect. |
method |
Fitting function for statistical models. Defaults to |
combine |
How are species combined in the model? Defaults to "+" for additive combinations. |
output |
Will the output be sign of effect or "coefficient". Defaults to "effect" |
... |
Other arguments to be supplied to fitting function. |
getRedundancy takes a matrix of 1s,0s, and -1s, and depending on whether we're interested in positive, negative, or both types of interactions looks for the m-wise overlap between species and returns the overlap index for each combination. For species whose effect is not different from 0 at the alpha=0.05 level, a 0 is returned.
Returns a matrix of functions and the effect of species on each. 1s, -1s, and 0s for "effect" or coefficients.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars getRedundancy(vars, species, germany) getRedundancy(vars, species, germany, output = "coef") ######### # takes a vector of responses, the species that may cause them # and returns a table of 1s, -1s, and 0s with regards to the kind of effect # or a coefficient table, if asked for. Arugments can take the form of the fitting function # how variables are combined, and additional arguments to the fitting function #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars getRedundancy(vars, species, germany) getRedundancy(vars, species, germany, output = "coef") ######### # takes a vector of responses, the species that may cause them # and returns a table of 1s, -1s, and 0s with regards to the kind of effect # or a coefficient table, if asked for. Arugments can take the form of the fitting function # how variables are combined, and additional arguments to the fitting function #########
getStdAndMeanFunctions
creates an average function multifunctionality index.
getStdAndMeanFunctions(data, vars, standardizeFunction = standardizeUnitScale)
getStdAndMeanFunctions(data, vars, standardizeFunction = standardizeUnitScale)
data |
A data frame with functions. |
vars |
The column names of the functions to be assessed. |
standardizeFunction |
A function to standardize each individual
function to the same scale, such as |
iterates over all functions and standardizes them between 0 and 1. Then it creates an averaged multifunctionality index by averaging over all standardized functions
Returns a data frame with standardized values for each function and an averaged index.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germany <- cbind(germany, getStdAndMeanFunctions(germany, vars))
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) germany <- cbind(germany, getStdAndMeanFunctions(germany, vars))
qw
Takes an unquoted vector and adds quotes to it like the qw function in perl.
qw(...)
qw(...)
... |
Any unquoted strings |
This is a helper function for data processing. Honestly, I use qw all the time in other languages, and wanted a version for R.
A vector
Jarrett Byrnes.
c("a", "b") qw(a, b) # qw - a helper function that we # will use later to deal with strings # analagous to qw in PERL
c("a", "b") qw(a, b) # qw - a helper function that we # will use later to deal with strings # analagous to qw in PERL
relevantSp
Which species are being used in this analysis.
relevantSp(data, colnums = 26:128)
relevantSp(data, colnums = 26:128)
data |
A data frame with presence/abscence of different species. |
colnums |
Column numbers that will be assessed. |
Which columns have values that are greater than zero.
A vector of columns names.
Jarrett Byrnes.
sAICfun
examines which species have an effect on which function using a stepwise AIC approach
sAICfun( response, species, data, positive.desired = TRUE, method = "lm", combine = "+", ... )
sAICfun( response, species, data, positive.desired = TRUE, method = "lm", combine = "+", ... )
response |
Name of the response column |
species |
Vector of column names of species |
data |
data frame with species presence/abscence of values of functions |
positive.desired |
Is a positive effect the desired sign. Defaults to TRUE |
method |
Fitting function for statistical models. Defaults to |
combine |
How are species combined in the model? Defaults to "+" for additive combinations. |
... |
Other arguments to be supplied to fitting function. |
sAICfun
takes a dataset, response, and function, and then uses a stepAIC approach
to determine the best model. From that it extracts the species with a positive,
negative, and neutral effect on that function.
Returns list of species with positive negative or neutral contributions, the relevant coefficient and effect matrices, and response name
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) spList <- sAICfun("biomassY3", species, germany) # " spList res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars ######### # sAICfun takes a dataset, response, and function, and then uses a stepAIC approach # to determine the best model. From that it extracts the species with a positive, # negative, and neutral effect on that function #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) spList <- sAICfun("biomassY3", species, germany) # " spList res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars ######### # sAICfun takes a dataset, response, and function, and then uses a stepAIC approach # to determine the best model. From that it extracts the species with a positive, # negative, and neutral effect on that function #########
standardizeUnitScale
standardized a variable so its maximum is 1
standardizeUnitScale(afun, min0 = TRUE, maxValue = max(afun, na.rm = T))
standardizeUnitScale(afun, min0 = TRUE, maxValue = max(afun, na.rm = T))
afun |
A vector of measurements of a function. |
min0 |
Must a minimum value be greater than or equal to 0? Defaults to TRUE. |
maxValue |
The maximum valye by which the vector will be standardized. Defaults to the vector's maximum. |
Takes a vector and then divides it by a maximum value.
Returns a standardized vector.
Jarrett Byrnes.
standardizeZScore
Z-standardizes a vector.
standardizeZScore(afun)
standardizeZScore(afun)
afun |
A vector of measurements of a function. |
Centers a vector and divides it by its standard deviation.
Returns a z-standardized vector.
Jarrett Byrnes.
stdEffects
obtains the standardized effect of each species on each function
stdEffects(cmat, adf, vars, species)
stdEffects(cmat, adf, vars, species)
cmat |
Matrix of coefficients of species effects on functions from |
adf |
Data frame with plot level data for species and functions. |
vars |
Names of columns with data for functions in adf. |
species |
Names of columns with data for species in adf. |
stdEffects takes a matrix of coefficients for relationships between species and functions, the data frame used to generate those coefficients and the names of species and function, and then it calculates standardized coefficients using std coef = b *sx/sy
Returns a matrix of standardized coefficients.
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars coefs <- getRedundancy(vars, species, germany, output = "coef") stdCoefs <- stdEffects(coefs, germany, vars, species) ######### # A function that uses the coefficient matrix and information from the # data to calculate standardized effects of species using the method # std coef = b *sx/sy #########
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars) species <- relevantSp(germany, 26:ncol(germany)) # re-normalize N.Soil so that everything is on the same # sign-scale (e.g. the maximum level of a function is # the "best" function) germany$N.Soil <- -1 * germany$N.Soil + max(germany$N.Soil, na.rm = TRUE) res.list <- lapply(vars, function(x) sAICfun(x, species, germany)) names(res.list) <- vars coefs <- getRedundancy(vars, species, germany, output = "coef") stdCoefs <- stdEffects(coefs, germany, vars, species) ######### # A function that uses the coefficient matrix and information from the # data to calculate standardized effects of species using the method # std coef = b *sx/sy #########
whichVars
takes a data frame and the names of a set of columns
and returns the names of those columns that do not have an excessive fraction
of NA values
whichVars(a.df, vars = NA, thresh = 2/3)
whichVars(a.df, vars = NA, thresh = 2/3)
a.df |
A data frame |
vars |
The names of the columns that contain data of interest |
thresh |
The fraction of NA values in a column that is acceptable |
This is a helper function for data processing.
A vector of column names
Jarrett Byrnes.
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars)
data(all_biodepth) allVars <- qw(biomassY3, root3, N.g.m2, light3, N.Soil, wood3, cotton3) germany <- subset(all_biodepth, all_biodepth$location == "Germany") vars <- whichVars(germany, allVars)