Title: | Half-Weight Index Gregariousness |
---|---|
Description: | The half-weight index gregariousness (HWIG) is an association index used in social network analyses. It extends the half-weight association index (HWI), correcting for level of gregariousness in individuals. It is calculated using group by individual data according to methods described in Godde et al. (2013) <doi:10.1016/j.anbehav.2012.12.010>. |
Authors: | Alec L. Robitaille [aut, cre] |
Maintainer: | Alec L. Robitaille <[email protected]> |
License: | GPL-3 |
Version: | 0.0.2 |
Built: | 2024-11-22 03:06:00 UTC |
Source: | https://github.com/robitalec/hwig |
Calculates the Half-Weight Association Index
calc_hwi(DT, id, group, by = NULL)
calc_hwi(DT, id, group, by = NULL)
DT |
input group membership data, in individual/group format |
id |
column indicating id in DT |
group |
column indicating group in DT |
by |
column(s) to split calculation by. e.g.: year |
Expects an input 'DT' with id and group column, e.g. as returned by group_pts.
HWI data.table or list of data.tables.
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr')
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr')
Calculates the Half-Weight Association Index according to the method described in Godde et al. (2013).
calc_hwig(hwi)
calc_hwig(hwi)
hwi |
output of calc_hwi. Either a data.table or a list of data.tables. See Details. |
It is expected that the input 'hwi' is the output from 'calc_hwi'. If 'by' was provided in that function, 'hwi' will be a list of data.tables. Alternatively if ‘by' wasn’t provided, 'hwi' will be a single data.table.
HWIG data.table or list of data.tables.
Sophie Godde, Lionel Humbert, Steeve D. Côté, Denis Réale, Hal Whitehead. Correcting for the impact of gregariousness in social network analyses. Animal Behaviour. Volume 85, Issue 3. 2013.
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr') # Calculate HWIG hwig <- calc_hwig(hwi)
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr') # Calculate HWIG hwig <- calc_hwig(hwi)
Example data for input to 'hwig'
A data.table with 14297 rows and 3 variables:
individual identifier
integer representing the year
# Load packages library(spatsoc) library(data.table)
# Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))
# Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]
# Temporal grouping group_times(DT, datetime = 'datetime', threshold = '20 minutes')
# Spatial grouping with timegroup group_pts( DT, threshold = 5, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup' )
fwrite(DT[, .(id = ID, group, yr = year(datetime))], 'inst/extdata/DT.csv')
# Load data.table library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig"))
# Load data.table library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig"))
Helper function, to return names of each matrix
get_names(DT, by)
get_names(DT, by)
DT |
input group membership data, in individual/group format |
by |
column(s) to split calculation by. e.g.: year |
names corresponding to values of by for each of the returned list of matrices in calc_hwi and calc_hwig.
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr') # Calculate HWIG hwig <- calc_hwig(hwi) # Set names nms <- get_names(DT, 'yr') names(hwig) <- nms
# Load data.table library(data.table) # Load example data DT <- fread(system.file("extdata", "DT.csv", package = "hwig")) # Calculate HWI hwi <- calc_hwi(DT, 'id', 'group', 'yr') # Calculate HWIG hwig <- calc_hwig(hwi) # Set names nms <- get_names(DT, 'yr') names(hwig) <- nms