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  9.369764  -1.1830537 -0.46893722  0.88840715 -0.5347529         1
## 2  8.499772  -1.7192827 -0.05694062 -0.01411928 -0.6520216         1
## 3 11.151019  -0.3770438 -0.15465879 -0.81390605  1.6187058         1
## 4 10.592297  -1.1760859  0.55469813  1.31959453  0.8189114         1
## 5 11.541493  -0.5370830 -2.66897280 -0.42429615  1.1790607         1
## 6 10.155592  -0.2426915  0.05478356  0.04630962  0.2748485         1
tail(data)
##       body_mass temperature   rainfall       wind   residual squid_pop
## 9995  10.116462  -1.0543945 -1.8597309 -0.8617747  0.4304499         5
## 9996   9.121754   0.6501680  0.3395459  0.3824208 -1.2544341         5
## 9997   9.142314  -0.3360826  0.8804852 -0.7172734 -0.1385899         5
## 9998   7.694607  -0.3669761  3.2124110 -0.0745173 -1.1283751         5
## 9999   9.306256   1.1088145 -1.6084340 -2.2160486 -0.8442623         5
## 10000  8.276687   0.5646602  0.6777146 -1.2828554 -1.2891862         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