Skip to content
Prev 310451 / 398506 Next

Simulate nested data

On Fri, Nov 9, 2012 at 3:12 PM, Andrea Goijman
<agoijman at cnia.inta.gov.ar> wrote:
Okay.

What do you know beforehand?
That you have 10 species?
That you have 3 groups?
That 4 species belong to group 1?

You don't really explain which are the inputs and which are the
outputs, and what form either will take.

Say you know just the first two:
ngroups <- 3
nspecies <- 10

species.groups <- sample(seq(1, ngroups, by=1), nspecies, replace=TRUE)
# gives nspecies assigned randomly to ngroups

# I still don't know what p is supposed to be: a vector for
# storing further simulations, one per species?
p <- rep(NA, nspecies)

# and for neatness:
mysims <- data.frame(species = seq(1, nspecies, by = 10), groups =
species.groups, p = p)