1
$\begingroup$

I have 50 observations, and I can get a mean and standard deviation values. In this situation, how can I get a 95% confidence interval in R? using bootstrapping?

0.594697 0.7976501 0.7355372 0.62818 0.747004 0.7532847 0.7995311 0.6793388 0.8202614 0.8590078 0.738024 0.7661064 0.7637131 0.7321101 0.776 0.744 0.7648953 0.7586619 0.7785349 0.7878261 0.7713004 0.7475 0.6495327 0.7227616 0.7196819 0.8996283 0.782305 0.7246596 0.7146497 0.7353723 0.7438424 0.7124183 0.7059484 0.848659 0.7678571 0.737467 0.7839335 0.677763 0.7725173 0.7493671 0.7091932 0.7445008 0.7404922 0.816358 0.8039816 0.7058824 0.7371795 0.8243243 0.7151899 0.7307692

$\endgroup$
1
  • 1
    $\begingroup$ What's wrong with the regular t-stat approach to a confidence interval for $\bar{x}$? The command is something like t.test(X)\$conf.int. $\endgroup$
    – Dave
    Commented Aug 1, 2019 at 21:37

3 Answers 3

3
$\begingroup$

Check out the package simpleboot. To get the CI for the mean:

install.packages("simpleboot")
library(simpleboot)
library(boot)
d <- c(0.594697, 0.7976501, 0.7355372, 0.62818, 0.747004, 0.7532847, 
       0.7995311, 0.6793388, 0.8202614, 0.8590078, 0.738024, 0.7661064, 
       0.7637131, 0.7321101, 0.776, 0.744, 0.7648953, 0.7586619, 0.7785349,
       0.7878261, 0.7713004, 0.7475, 0.6495327, 0.7227616, 0.7196819,
       0.8996283, 0.782305, 0.7246596, 0.7146497, 0.7353723, 0.7438424,
       0.7124183, 0.7059484, 0.848659, 0.7678571, 0.737467, 0.7839335, 0.677763,
       0.7725173, 0.7493671, 0.7091932, 0.7445008, 0.7404922, 0.816358,
       0.8039816, 0.7058824, 0.7371795, 0.8243243, 0.7151899, 0.7307692)

boot.obj <- one.boot(d, FUN = mean, R = 10000)
boot.ci(boot.obj, conf = 0.95, type = "all")

BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 10000 bootstrap replicates

CALL : 
boot.ci(boot.out = boot.obj, conf = 0.95, type = "all")

Intervals : 
Level      Normal              Basic         
95%   ( 0.7354,  0.7655 )   ( 0.7357,  0.7655 )  

Level     Percentile            BCa          
95%   ( 0.7353,  0.7650 )   ( 0.7353,  0.7650 )  
Calculations and Intervals on Original Scale

The different types of CI's all look pretty similar.

$\endgroup$
2
  • $\begingroup$ For what it's worth: With data in x, my 'percentile boostrap' was as follows: a = replicate(2000, mean(sample(x, 50, rep=T))) quantile(a, c(.025,.975)), which returned $0.7361697, 0.7655921$--essentially the same result as above (+1). $\endgroup$
    – BruceET
    Commented Aug 1, 2019 at 23:37
  • 1
    $\begingroup$ Thanks professor! While I like the shortcuts, I can still bootstrap my 2.5 and 97.5 quintiles as you taught in your stochastic course. $\endgroup$ Commented Aug 2, 2019 at 3:31
3
$\begingroup$

I pasted your $n=50$ observations into R. A Shapiro-Wilk test doesn't reject the null hypothesis of normality, even though a histogram suggests slight left skewness. Any skewness may be inconsequential: the sample mean and median are nearly equal.

summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.5947  0.7232  0.7458  0.7504  0.7779  0.8996 

In these circumstances either of the following 95% confidence intervals from R seems useful: (a) a nonparametric confidence interval $(0.737,\, 0.746)$ for the population median $\eta,$ or (b) a t confidence interval $(0.735,\, 0.766)$ for the population mean $\mu.$

wilcox.test(x, conf.int=T)$conf.int
[1] 0.7371894 0.7641243
 attr(,"conf.level")
 [1] 0.95
t.test(x, conf.int=T)$conf.int
[1] 0.734852 0.765924
 attr(,"conf.level")
 [1] 0.95

In my experience I would expect a nonparametric bootstrap CI, as suggested by @storyteller0815 (+1), to give about the same result (because these two traditional CIs are in substantial agreement). I did a simple quantile-method bootstrap procedure with 2000 iterations, obtaining $(0.736, 0.766).$

$\endgroup$
1
$\begingroup$

Bootstrapping should work fine in your case. I would recommend having a look at the shape of your distribution because the choice of an adequate bootstrap method depends on the skewness of the distribution.

For an overview see here: https://projecteuclid.org/download/pdf_1/euclid.ss/1177013815

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.