7.1 Nested

Nested sampling assumes that you have a nested structure, and allows you to sample different numbers at each hierarchical level. The param input is a matrix with (named) columns. The rows of this matrix represent different sampling sets. This is most easily put together using the cbind() (column bind) function, specifying the names. The number of repeat observations for a higher level can be specified using name ‘observation’ (this doesn’t have to exist in the data structure). For example

cbind(individual=c(10, 15),observation=c(10, 5))
##      individual observation
## [1,]         10          10
## [2,]         15           5

would represent sampling the data structure above, the first set having 10 individuals each with 10 observations

Note this sampling procedure only produces balanced sampling designs. For unbalanced designs see ‘missing data’ below.

7.1.1 Worked example 1

We want to see how the number of repeat measurements on individuals affects power. In order to vary the number of observations of an individual, we could specify:

param <- cbind(nest=10,individual=10,observation=c(20, 10, 5, 2))
pop_data <- simulate_population(
  data_structure = make_structure("nest(10)/individual(20)",repeat_obs=20),

  parameters = list(
    individual = list( 
      vcov = 0.1
    ),
    observation= list(
      names = c("environment"),
      beta =c(0.5)
    ), 
    residual = list(
      vcov = 0.8
    )
  ),

  sample_type = "nested", 
  sample_param = param
)

To extract the sampled data we can then use get_sample_data() specifying which sample set we want, for example the second set 10 nests, each with 10 individuals with 10 observations:

sample_data <- get_sample_data(pop_data, sample_set=2)
length(unique(sample_data$nest))
## [1] 10
length(unique(sample_data$individual))
## [1] 100
nrow(sample_data)
## [1] 1000