2 Hierarchical structure
There are two parts to simulating hierarchical data. First you need to have a hierarchical data structure and second you need parameters at each of the different hierarchical levels. The data structure is essentially a data.frame (or matrix), with all the grouping factors and their levels, as we would see in a typical dataset. Lets take the blue tit dataset we explored earlier:
data(BTdata)
head(BTdata)
## tarsus back animal dam fosternest hatchdate sex
## 1 -1.89229718 1.1464212 R187142 R187557 F2102 -0.6874021 Fem
## 2 1.13610981 -0.7596521 R187154 R187559 F1902 -0.6874021 Male
## 3 0.98468946 0.1449373 R187341 R187568 A602 -0.4279814 Male
## 4 0.37900806 0.2555847 R046169 R187518 A1302 -1.4656641 Male
## 5 -0.07525299 -0.3006992 R046161 R187528 A2602 -1.4656641 Fem
## 6 -1.13519543 1.5577219 R187409 R187945 C2302 0.3502805 Fem
Here animal
, dam
, fosternest
and sex
make up the data structure.
In this Section, we will first demonstrate how to make a simple hierarchical structure using the make_structure
function. simulate_population
also allows pre-existing data structures to be incorporated into simulations. The remaining part of the section details how to simulate hierarchical data once you have a hierarchical data structure.