Skip to contents

This function summarizes the prevalence of tracked behaviors over time, either returning a summary for each individual trial or averaging across multiple trials. Prevalence is normalized by the number of agents in each trial.

Usage

summarise_prevalence(
  trials_or_trial,
  tracked_behaviors = c("Adaptive"),
  across_trials = TRUE
)

Arguments

trials_or_trial

A Trial object or a list of Trial objects

tracked_behaviors

Character vector of behavior names to include in the summary. Defaults to "Adaptive".

between_trials

Logical. If TRUE (default), returns a summary aggregated across trials. If FALSE, returns per-trial prevalence values with a trial_id column distinguishing replicates.

Value

A tibble with columns:

Step

The time step (from observations)

Behavior

The behavior being tracked

Count

The number of agents exhibiting this behavior at this Step

Prevalence

The fraction of agents exhibiting this behavior (Count / n_agents)

trial_id

The trial index (only included if between_trials = FALSE)

One column per input parameter in the Trial's model

Examples

mps <- make_model_parameters(n_agents = 10, adoption_rate = 1.0, learning_strategy = contagion_learning_strategy)
abm <- make_abm(mps)
trial <- make_trial(abm)
#> Error in make_trial(abm): could not find function "make_trial"
trial$run(steps = 5)
#> Error: object 'trial' not found

# Summary aggregated across trials (default)
summary <- summarise_prevalence(trial, tracked_behaviors = c("A", "B"))
#> Error: object 'trial' not found
print(summary)
#> function (object, ...) 
#> UseMethod("summary")
#> <bytecode: 0x10956dae0>
#> <environment: namespace:base>

# Per-trial summary without aggregation
summary_per_trial <- summarise_prevalence(trial, tracked_behaviors = c("A", "B"), between_trials = FALSE)
#> Error in summarise_prevalence(trial, tracked_behaviors = c("A", "B"),     between_trials = FALSE): unused argument (between_trials = FALSE)
print(summary_per_trial)
#> Error: object 'summary_per_trial' not found