The socialSim R package provides tools to simulate and analyse datasets of social interactions between individuals using hierarchical Bayesian models implemented in Stan.
This vignette demonstrates a typical workflow using three main functions:
simulate_data() – generate datasets of social
interactionsrun_model() – fit a Stan model to the simulated
datasetssummarise_results() – evaluate bias and dispersion of
estimated parameterssim <- simulate_data(
  ind = 200,
  partners = 4,
  repeats = 1,
  iterations = 5,
  B_0 = 1,
  psi = 0.3,
  Valpha = 0.2,
  Vepsilon = 0.1
)This creates a list of datasets representing repeated social
interactions.
You can control study design components, variance components and
correlations between direct and indirect effect.
To analyse the data, fit one of the included Stan models:
Importantly, you will need cmdstanr or
rstan installed for this step.
Using cmdstanr will be faster since it compiles and runs models in
parallel.
Once the models are fitted, summarise bias and dispersion across simulations:
This function extracts model estimates and computes metrics such as mean absolute deviation (MADm) across replicates.
Here’s a minimal example with few iterations for a fast runtime:
sim <- simulate_data(ind = 50, partners = 2, iterations = 4, Valpha = 0.2, Vepsilon = 0.1)
res <- run_model(sim, model = "Trait.stan", iter = 500, cores = 4)
summary <- summarise_results(res)
print(summary)The socialSim package helps researchers design, simulate, and evaluate models of social phenotypes and indirect genetic effects.
and visit the GitHub page for the latest updates.