R/bootstrap.R

Defines functions boot.median CV bootCV

## calc median and bootstrap confidence intervals
boot.median <- function(x, Rep = 10000, ...){
    require(boot)
    b <- boot(x, function(x, i){ median(x[i]) }, R = Rep, ...)
    bci <- boot.ci(b, type = 'perc')
    res <- c(Median = bci$t0, Lower = bci$percent[4], Upper = bci$percent[5])
    return(res)
}



## coefficient of variation (CV)
CV <- function(x) sd(x) / mean(x)

## bootstrap confidence interval of CI
bootCV <- function(x, Rep = 1000, ...){
    require(boot)
    b <- boot(x, function(x, i){ CV(x[i]) }, R = Rep, ...)
    bci <- boot.ci(b, type = 'perc')
    res <- c(CV = bci$t0, Lower = bci$percent[4], Upper = bci$percent[5])
    return(res)
}
mt1022/Rutils documentation built on May 25, 2019, 10:34 p.m.