1.8 Simulating multiple populations

We can use the simulate_population() function to generate multiple datasets (populations) form the same set of parameters (world). To do this we can specify the n_pop argument in simulate_population(). This defaults to 1.

squid_data <- simulate_population(
  n=2000,
  response_name = "body_mass",
  parameters=list(
    intercept=10,
    observation=list(
      names=c("temperature","rainfall", "wind"),
      beta =c(0.5,-0.3,0.4)
    ),
    residual=list(
      vcov=0.8
    )
  ),
  n_pop=5
)

By default get_population_data returns a data.frame, where the squid_pop column indicates the population

data <- get_population_data(squid_data)
head(data)
##   body_mass temperature   rainfall        wind    residual squid_pop
## 1 10.132368  -1.9546951  0.4197320  0.21029426  1.15151743         1
## 2  8.687849  -0.9974609 -0.3074322 -0.99049972 -0.50945076         1
## 3  9.531882   0.5667092  0.1024663 -0.01125458 -0.71623081         1
## 4 10.089348  -0.2627402  1.8010146 -0.71568383  1.04729598         1
## 5 11.162227  -0.4583614 -1.6298772 -0.61950140  1.15024515         1
## 6 10.154952   0.4401542  0.3017782  0.22296725 -0.06377881         1
tail(data)
##       body_mass temperature   rainfall        wind   residual squid_pop
## 9995  10.782432  1.05603425 -0.8132784  1.12810452 -0.4408101         5
## 9996  10.458162  0.04709716 -0.3317510 -0.30729659  0.4580066         5
## 9997  12.266405  2.09337257  0.6128256  0.27880803  1.2920434         5
## 9998   8.853503  1.31778772  2.3277415 -0.55672678 -0.8843778         5
## 9999   8.352746 -1.79613660 -0.7984681 -0.35913346 -0.8450724         5
## 10000 10.080702 -2.51007818 -0.4660681 -0.04906956  1.2155489         5

It can also be output as a list, which might be more useful for processing many iterations of a simulation.

data <- get_population_data(squid_data, list=TRUE)
length(data)
## [1] 5