Package 'hwig'

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

Help Index


Calculate HWI

Description

Calculates the Half-Weight Association Index

Usage

calc_hwi(DT, id, group, by = NULL)

Arguments

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

Details

Expects an input 'DT' with id and group column, e.g. as returned by group_pts.

Value

HWI data.table or list of data.tables.

See Also

calc_hwig

Examples

# 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

Description

Calculates the Half-Weight Association Index according to the method described in Godde et al. (2013).

Usage

calc_hwig(hwi)

Arguments

hwi

output of calc_hwi. Either a data.table or a list of data.tables. See Details.

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.

Value

HWIG data.table or list of data.tables.

References

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.

See Also

calc_hwi get_names

Examples

# 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'

Description

Example data for input to 'hwig'

Format

A data.table with 14297 rows and 3 variables:

ID

individual identifier

year

integer representing the year

Source

# 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')

Examples

# Load data.table
library(data.table)

# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "hwig"))

Get HWI/HWIG names

Description

Helper function, to return names of each matrix

Usage

get_names(DT, by)

Arguments

DT

input group membership data, in individual/group format

by

column(s) to split calculation by. e.g.: year

Value

names corresponding to values of by for each of the returned list of matrices in calc_hwi and calc_hwig.

See Also

calc_hwi calc_hwig

Examples

# 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