# Bootstrap confidence intervals for an index calculated on counts

#### Ornithoholik

##### New Member
Good morning!

I would like to calculate 95% confidence limits for both lower and upper possible values of the Ivlev’s index as it has been done on the below screenshot from a paper of Hebda, Wesołowski & Rowiński (2017) in order to assess the significance of the index values for particular groups (i.e. tree genera in my case). The index values range from -1 (suggesting avoidance) to 1 (preferance). 0 means that there is a random selection.
The index itself is easy to calculate which can be done using “ivlev_electivity(r, p)” in R, where r (numeric) means resource utilisation (in my case nesting holes in particular tree genera) and p (numeric) represents resource availability (all the identified trees i.e. 1050 trees). I would like to follow the instructions from the paper of Hebda, Wesołowski & Rowiński (2017), which goes:

“Significance of electivity indices was assessed by estimating confidence intervals using bootstrapping, i.e.
calculating electivity indices for random samples (with replacement) from the original dataset. This was repeated 100,000 times and the middle 95% of a resulting distribution provided the 95% confidence intervals. A 95% confidence interval including zero implied that electivity is not significant.”

So far, I have tried using “boot” package, but the problem is that R treats my proposed statistics (e.g. percentage of a given tree genus in the environment, Ivlev’s index itself) as invalid. I have also tried employing a code from the MarinStatsLectures-R Programming & Statistics youtube account in the following manner to my data set pasted below (it is named "Ivlev_tree").
n.p <- 5 # the number of observations to sample from the table
B <- 100000 # the number of bootstrap samples
Boot.All <- matrix( sample(Ivlev_tree\$Tree_number, size= B*n.p, replace=TRUE), nrow=n.p, ncol=B) However, it has not produced what I am aiming to achieve. This has just given me a matrix with 5 rows (each for each tree genus) and 100000 columns with randomly assigned numbers from the original data set (i.e. 464, 258, 193, 74 or 61). I would rather bootstrap each count for each tree genus separatly (like on the figure from below, but 100000 times), but this only prints logistic values rather than numeric when attempted in R. Then, I would like to calculate a proportion of each bootstarpped value in the entire sample (N=1050) that would then be used to calculate the Ivlev’s index (with r (Per_holes) for each tree genus being constant). Subsequently, I wanted to create a bootstrap sample distribution from which I would “cut out” the middle 95% of confidence intervals to obtain the interval between the lowest possible limit of the index and the upper limit of it. I have seen calculating the bootstrap confidence intervals a number of times on the internet but all of the code lines, suggestions and instructions have applied exclusively to populations’ means and median. Whereas I need to obtain this based on counts.

I would appreciate any guidence as to how to approach this from another angle or perhabs how to carry on from what I have done already.

Thank you for consideration.