This is similar to Bootstrap: estimate is outside of confidence interval
I have some data that represents counts of genotypes in a population. I want to estimate genetic diversity using Shannon's index and also generate a confidence interval using bootstrapping. I've noticed, however, that the estimate via bootstrapping tends to be extremely biased and results in a confidence interval that lies outside of my observed statistic.
Below is an example.
# Shannon's index
H <- function(x){
x <- x/sum(x)
x <- -x * log(x, exp(1))
return(sum(x, na.rm = TRUE))
}
# The version for bootstrapping
H.boot <- function(x, i){
H(tabulate(x[i]))
}
Data generation
set.seed(5000)
X <- rmultinom(1, 100, prob = rep(1, 50))[, 1]
Calculation
H(X)
## [1] 3.67948
xi <- rep(1:length(X), X)
H.boot(xi)
## [1] 3.67948
library("boot")
types <- c("norm", "perc", "basic")
(boot.out <- boot::boot(xi, statistic = H.boot, R = 1000L))
##
## CASE RESAMPLING BOOTSTRAP FOR CENSORED DATA
##
##
## Call:
## boot::boot(data = xi, statistic = H.boot, R = 1000)
##
##
## Bootstrap Statistics :
## original bias std. error
## t1* 3.67948 -0.2456241 0.06363903
Generating the CIs with bias-correction
boot.ci(boot.out, type = types)
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 1000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = boot.out, type = types)
##
## Intervals :
## Level Normal Basic Percentile
## 95% ( 3.800, 4.050 ) ( 3.810, 4.051 ) ( 3.308, 3.549 )
## Calculations and Intervals on Original Scale
Assuming that the variance of t can be used for the variance of t0.
norm.ci(t0 = boot.out$t0, var.t0 = var(boot.out$t[, 1]))[-1]
## [1] 3.55475 3.80421
Would it be correct to report the CI centered around t0? Is there a better way to generate the bootstrap?