Skip to contents

First step of analysis pipeline: create STbayes data object from user supplied data to be used for generating and fitting models.

Usage

import_user_STb(
  event_data,
  networks,
  network_type = c("undirected", "directed"),
  ILV_c = NULL,
  ILV_tv = NULL,
  ILVi = NULL,
  ILVs = NULL,
  ILVm = NULL,
  t_weights = NULL,
  high_res = FALSE
)

Arguments

event_data

dataframe with columns id, trial, time, t_end

networks

Either a dataframe, a bisonr/STRAND fit, or a list of bisonr/STRAND fits. If dataframe: with columns trial, from, to, and one or more columns of edge weights named descriptively. Optionally an integer time column can be provided for dynamic network analysis, although networks must be provided for each inter-event interval.

network_type

"undirected" or "directed".

ILV_c

optional dataframe with columns id, and any constant individual-level variables

ILV_tv

optional dataframe with columns trial, id, time and any time-varying variables. Variable values should summarize the variable for each inter-acquisition period.

ILVi

Optional character vector of column names from ILV metadata to be considered when estimating intrinsic rate. If not specified, all ILV are applied to both.

ILVs

Optional character vector of column names from ILV metadata to be considered when estimating social transmission rate. If not specified, all ILV are applied to both.

ILVm

Optional character vector of column names from ILV metadata to be considered in a multiplicative model.

t_weights

Optional dataframe with columns trial, id, time and t_weight. Transmission rates represent rates of production/relevant cues per inter-event period.

high_res

Boolean indicating whether or not user is providing networks and transmission weights per period duration=1

Value

A list object containing properly formatted data to run social transmission models.

Examples

# very mock data
event_data <- data.frame(
    trial = rep(1:2, each = 3),
    id = LETTERS[1:6],
    time = c(0, 1, 2, 0, 1, 4),
    t_end = c(3, 3, 3, 4, 4, 4)
)
networks <- data.frame(
    trial = rep(1:2, each = 3),
    from = c("A", "A", "B", "D", "D", "E"),
    to = c("B", "C", "C", "E", "F", "F"),
    kin = c(1, 0, 1, 0, 1, 1),
    inverse_distance = c(0, 1, .5, .25, .1, 0)
)
ILV_c <- data.frame(
    id = LETTERS[1:6],
    age = c(-1, -2, 0, 1, 2, 0), # continuous variables should be normalized
    sex = c(0, 1, 1, 0, 1, 0), # Factor ILVs must be input as numeric
    weight = c(0.5, .25, .3, 0, -.2, -.4)
)
ILV_tv <- data.frame(
    trial = c(rep(1, each = 9), rep(2, each = 9)),
    id = c(rep(LETTERS[1:3], each = 3), rep(LETTERS[4:6], each = 3)),
    # these times correspond to the inter-acquisition periods
    # e.g. 1 is from [t_0 to t_1), 2 is [t_1 to t_2), 3 = [t_2 to t_3 or t_end])
    time = c(rep(1:3, times = 3), rep(1:3, times = 3)),
    # ensure the variable is summarizing these inter-acquisition time periods
    dist_from_task = rnorm(18)
)
t_weights <- data.frame(
    trial = c(rep(1, each = 9), rep(2, each = 9)),
    id = c(rep(LETTERS[1:3], each = 3), rep(LETTERS[4:6], each = 3)),
    time = c(rep(1:3, times = 3), rep(1:3, times = 3)),
    t_weight = exp(rnorm(18))
)
imported_data <- import_user_STb(
    event_data = event_data,
    networks = networks,
    ILV_c = ILV_c,
    ILV_tv = ILV_tv,
    # Use 'age' and time-varying ILV 'dist_from_task' for asocial learning
    ILVi = c("age", "dist_from_task"),
    # Use only 'sex' for social learning
    ILVs = c("sex"),
    # Use weight for multiplicative effect on asocial and social learning
    ILVm = c("weight")
)