Examples for 'boot::boot.ci'


Nonparametric Bootstrap Confidence Intervals

Aliases: boot.ci

Keywords: nonparametric htest

### ** Examples

# confidence intervals for the city data
ratio <- function(d, w) sum(d$x * w)/sum(d$u * w)
city.boot <- boot(city, ratio, R = 999, stype = "w", sim = "ordinary")
boot.ci(city.boot, conf = c(0.90, 0.95),
        type = c("norm", "basic", "perc", "bca"))
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = city.boot, conf = c(0.9, 0.95), type = c("norm", 
    "basic", "perc", "bca"))

Intervals : 
Level      Normal              Basic         
90%   ( 1.074,  1.878 )   ( 1.059,  1.763 )   
95%   ( 0.997,  1.955 )   ( 0.907,  1.792 )  

Level     Percentile            BCa          
90%   ( 1.278,  1.982 )   ( 1.283,  2.005 )   
95%   ( 1.248,  2.133 )   ( 1.251,  2.161 )  
Calculations and Intervals on Original Scale
# studentized confidence interval for the two sample 
# difference of means problem using the final two series
# of the gravity data. 
diff.means <- function(d, f)
{    n <- nrow(d)
     gp1 <- 1:table(as.numeric(d$series))[1]
     m1 <- sum(d[gp1,1] * f[gp1])/sum(f[gp1])
     m2 <- sum(d[-gp1,1] * f[-gp1])/sum(f[-gp1])
     ss1 <- sum(d[gp1,1]^2 * f[gp1]) - (m1 *  m1 * sum(f[gp1]))
     ss2 <- sum(d[-gp1,1]^2 * f[-gp1]) - (m2 *  m2 * sum(f[-gp1]))
     c(m1 - m2, (ss1 + ss2)/(sum(f) - 2))
}
grav1 <- gravity[as.numeric(gravity[,2]) >= 7, ]
grav1.boot <- boot(grav1, diff.means, R = 999, stype = "f",
                   strata = grav1[ ,2])
boot.ci(grav1.boot, type = c("stud", "norm"))
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = grav1.boot, type = c("stud", "norm"))

Intervals : 
Level      Normal            Studentized     
95%   (-5.901,  0.210 )   (-7.476,  0.012 )  
Calculations and Intervals on Original Scale
# Nonparametric confidence intervals for mean failure time 
# of the air-conditioning data as in Example 5.4 of Davison
# and Hinkley (1997)
mean.fun <- function(d, i)
{    m <- mean(d$hours[i])
     n <- length(i)
     v <- (n-1)*var(d$hours[i])/n^2
     c(m, v)
}
air.boot <- boot(aircondit, mean.fun, R = 999)
boot.ci(air.boot, type = c("norm", "basic", "perc", "stud"))
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = air.boot, type = c("norm", "basic", "perc", 
    "stud"))

Intervals : 
Level      Normal              Basic         
95%   ( 33.0, 178.2 )   ( 21.9, 167.5 )  

Level    Studentized          Percentile     
95%   ( 45.4, 282.0 )   ( 48.7, 194.2 )  
Calculations and Intervals on Original Scale
# Now using the log transformation
# There are two ways of doing this and they both give the
# same intervals.

# Method 1
boot.ci(air.boot, type = c("norm", "basic", "perc", "stud"),
        h = log, hdot = function(x) 1/x)
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = air.boot, type = c("norm", "basic", "perc", 
    "stud"), h = log, hdot = function(x) 1/x)

Intervals : 
Level      Normal              Basic         
95%   ( 4.033,  5.404 )   ( 4.097,  5.481 )  

Level    Studentized          Percentile     
95%   ( 3.923,  5.742 )   ( 3.885,  5.269 )  
Calculations and Intervals on  Transformed Scale
# Method 2
vt0 <- air.boot$t0[2]/air.boot$t0[1]^2
vt <- air.boot$t[, 2]/air.boot$t[ ,1]^2
boot.ci(air.boot, type = c("norm", "basic", "perc", "stud"),
        t0 = log(air.boot$t0[1]), t = log(air.boot$t[,1]),
        var.t0 = vt0, var.t = vt)
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 999 bootstrap replicates

CALL : 
boot.ci(boot.out = air.boot, type = c("norm", "basic", "perc", 
    "stud"), var.t0 = vt0, var.t = vt, t0 = log(air.boot$t0[1]), 
    t = log(air.boot$t[, 1]))

Intervals : 
Level      Normal              Basic         
95%   ( 4.036,  5.401 )   ( 4.097,  5.481 )  

Level    Studentized          Percentile     
95%   ( 3.923,  5.742 )   ( 3.885,  5.269 )  
Calculations and Intervals on Original Scale

[Package boot version 1.3-28.1 Index]