alpha: Calculate Alpha Irreplaceability

View source: R/alphabeta.R

alphaR Documentation

Calculate Alpha Irreplaceability

Description

This function calculates Alpha irreplaceability. Inputs can be single parameter values needed to calculate Alpha, vectors of parameter values to calculate a vector of Alpha values, or a data.frame with columns containing parameters needed to calculate a vector of Alpha values.

  • Single Alpha measurement: If local, global and target are numeric, it calculates and returns Alpha irreplaceability.

  • Vectorized Alpha measurement: If local, global and target are vectors of the same length, a vector of Alpha irreplaceability values will be calculated and returned.

  • Dataframe Alpha measurement: If df is provided and local, global and target are strings representing field names in df, a vector of Alpha irreplaceability values will be caluclated and returned. Optionally: If alpha_col is also provided, a data.frame identical to df will be returned with the calculated Alpha values in the alpha_col column.

Usage

alpha(
  local,
  global,
  target,
  df = NULL,
  alpha_col = NULL,
  triage = FALSE,
  na.allow = NULL,
  overwrite = FALSE
)

Arguments

local

number, vector or string - The feature's representation at the site, or the name of the column containing the feature's representation at the site.

global

number, vector or string - The feature's globally available representation, or the name of the column containing the feature's globally available representation.

target

number, vector or string - The feature's target, or the name of the column containing the feature's target.

df

data.frame - Optional; an input data.frame.

alpha_col

string - The name of the column where to write alpha values. If both df and alpha_col are provided, the output will be the input dataframe with the additional column.

triage

logical - Should features with unachievable targets be ignored? Defaults to FALSE. If FALSE, these species will be always assigned an Alpha irreplaceability of 1 wherever they occur. If TRUE, these species will always be assigned an Alpha irreplaceabiltiy of 0.

na.allow

logical - Allaw NA values in input? If TRUE, NA values in local, global or target walues will result in NA being returned, otherwise an error will be raised. Defaults to FALSE for single Alpha calculations, and to TRUE for calculations over vectors or data.frames.

overwrite

logical - Should alpha_col be overwritten if it already exists?

Value

A number, vector or data.frame

Author(s)

Daniele Baisero, daniele.baisero@gmail.com

Examples

alpha(1, 100, 45)
alpha(c(1,25,45), c(100,100,100), c(50,50,50))
dtfrm = data.frame(
  loc = c(1,25,45),
  glob = c(100,100,100),
  targ = c(50,50,50)
)
alpha('loc', 'glob', 'targ', df = dtfrm)

proxirr documentation built on May 29, 2024, 9:38 a.m.