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.
<- simulate_population(
squid_data 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
<- get_population_data(squid_data)
data head(data)
## body_mass temperature rainfall wind residual squid_pop
## 1 9.963488 -0.87042429 0.08123816 -1.46160423 1.00771338 1
## 2 11.679887 0.54596251 -1.35020676 0.44824010 0.82254729 1
## 3 10.205083 0.05409334 -0.59114054 0.30053533 -0.11952024 1
## 4 9.957851 -1.73773422 -0.62630133 -0.38115588 0.79129050 1
## 5 10.547339 1.61947126 0.76155388 -0.05519906 -0.01185064 1
## 6 10.196599 0.68431346 0.65455707 -2.19404168 0.92842638 1
tail(data)
## body_mass temperature rainfall wind residual squid_pop
## 9995 8.086665 -0.6214712 -0.8064454 -0.54186069 -1.6277892272 5
## 9996 11.521081 0.2075812 -2.0356218 -0.01890323 0.8141651756 5
## 9997 11.384367 -0.2871820 -1.1694008 0.59354828 0.9397186387 5
## 9998 11.682527 -0.1509205 -0.9174626 -0.46858243 1.6701819257 5
## 9999 9.570990 -1.4052158 -1.7697390 -0.97793190 0.1338485092 5
## 10000 9.421060 -1.1131408 -1.4915844 -1.17264236 -0.0007877935 5
It can also be output as a list, which might be more useful for processing many iterations of a simulation.
<- get_population_data(squid_data, list=TRUE)
data length(data)
## [1] 5