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 11.005226  -1.8727163 -1.4047080 -0.7400397  1.81618743         1
## 2  9.036770  -0.5297638  0.7530046  1.1945503 -0.95026697         1
## 3  9.458323  -0.1054163 -0.5120713  0.7014982 -0.92318933         1
## 4 10.013197   0.3494991 -0.1389098 -0.7104103  0.08093893         1
## 5  8.339910   0.2269021  1.5342122  0.3712021 -1.46175871         1
## 6  9.538418  -0.8228852 -0.1279289  0.9499106 -0.46848205         1
tail(data)
##       body_mass temperature   rainfall         wind    residual squid_pop
## 9995   9.432963 -0.24449153  1.4748153 -0.740536096  0.29386791         5
## 9996  11.619580  0.27952629 -0.4021390 -0.008896803  1.36273375         5
## 9997  10.799467  0.27860645 -0.8437127 -0.788461164  0.72243480         5
## 9998   9.488702 -2.66231456  1.3492665  0.650127585  0.96458811         5
## 9999   9.948296  0.08454109  0.1613247 -0.352362135  0.09536773         5
## 10000  8.940678 -1.26133105 -0.1903078  0.516066626 -0.69217548         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