Skip to contents

Combine multiple individual ABC simulation runs into one

Usage

combine_data(...)

Arguments

...

Either a list of objects of the class demografr_abc_sims as produced by the function simulate_abc, or individual objects of this class given as standard function arguments, or paths to 'rds' files containing serializations of such demografr_abc_sims objects.

Value

A combined object of the class demografr_abc_sims

Examples

library(slendr)
init_env(quiet = TRUE)

# simulate three runs of a slendr model across a parameter grid
model <- function(Ne_p1, Ne_p2, Ne_p3, Ne_p4) {
  p1 <- population("p1", time = 1, N = 1000)
  p2 <- population("p2", time = 2000, N = 3000, parent = p1)

  model <- compile_model(
    populations = list(p1, p2),
    generation_time = 1,
    simulation_length = 10000, serialize = FALSE
  )

  return(model)
}

grid <- expand.grid(Ne_p1 = c(10, 100), Ne_p2 = c(10, 100))

compute_diversity <- function(ts) {
  samples <- list(ts_samples(ts)$name)
  ts_diversity(ts, sample_sets = samples, mode = "branch")
}
functions <- list(diversity = compute_diversity)

nreps <- 1
run1 <- simulate_grid(model, grid, functions, replicates = nreps,
                      sequence_length = 10000, recombination_rate = 0)
run2 <- simulate_grid(model, grid, functions, replicates = nreps,
                      sequence_length = 10000, recombination_rate = 0)

# combine both simulation runs
combine_data(run1, run2)
#> # A tibble: 8 × 4
#>     rep Ne_p1 Ne_p2 diversity       
#>   <int> <dbl> <dbl> <list>          
#> 1     1    10    10 <tibble [1 × 2]>
#> 2     1   100    10 <tibble [1 × 2]>
#> 3     1    10   100 <tibble [1 × 2]>
#> 4     1   100   100 <tibble [1 × 2]>
#> 5     2    10    10 <tibble [1 × 2]>
#> 6     2   100    10 <tibble [1 × 2]>
#> 7     2    10   100 <tibble [1 × 2]>
#> 8     2   100   100 <tibble [1 × 2]>