I am trying to the bootstrap the proportional occurrence of diet items for 7 individuals and calculate a sd()
Lets say there are 9 prey items on the menu.
Diet <- c("Beaver","Bird", "Bobcat","Coyote", "Deer", "Elk",
"Porcupine", "Raccoon", "SmMamm")
And that these prey items are eaten by 7 different individuals of the same species
Inds <- c("P01", "P02", "P03", "P04", "P05", "P06", "P07")
My goal is the bootstrap the proportional occurrence of each diet item for each individual.
The loop below generates five diets for each individual (each diet containing N = 20 feedings) that were sampled with replacement. The data are stored as a list of the individuals, each of which contains a list of the sample diets.
BootIndDiet <- list()
IndTotboot <- list()
for(i in Inds){
for(j in 1:5){
BootIndDiet[[j]] <- prop.table(table(sample(Diet, 20 ,replace = T)))
}
IndTotboot[[i]] <- BootIndDiet
}
Below I have included the first two diets of individual P07 as an example of the loop results
$P07
$P07[[1]]
Beaver Bird Bobcat Deer Elk
0.05 0.15 0.20 0.10 0.15
Porcupine Raccoon SmMamm
0.15 0.15 0.05
$P07[[2]]
Beaver Bird Bobcat Coyote Deer
0.15 0.10 0.20 0.05 0.05
Elk Porcupine Raccoon SmMamm
0.05 0.20 0.10 0.10
I then want to calculate the sd() of the proportional of each species for each individual. Equivocally, for each individual (P01 - P07) I want the sd()
of the proportional occurrence of each prey species across the 5 diets.
While my loop above runs, I suspect there is a better way (possibly using the boot() function) that avoids lists...
While I have only included 5 samples (bootstraps) for each individual here, I hope to generate 10000.
Suggestions on a different strategy or how to apply sd()
across sub-lists is greatly appreciated.
See Question&Answers more detail:
os