bootstats: Calculate mean and median with bootstrapped confidence...

Description Usage Arguments Examples

Description

This function returns the bootstrapped mean and median, and the respective confidence intervals, of the supplied numeric vector.

Usage

1
2
bootstats(x, p.level = 0.95, nrep = NULL, exact.thrs = 8, smooth = TRUE,
  return_resamples = FALSE)

Arguments

x

A vector of numerical values.

p.level

A number giving the level of confidence for the intervals

nrep

The number of repetitions, or resamples, to perform. Defaults to max(500, 2*(10^5)/length(x)), except if length(x) <= exact.thrs.

exact.thrs

Upper level of length(x) at which all possible subsamples are used

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
bootstats(rnorm(1000), p.level=0.9, smooth=FALSE)

bootstats(c(1, 3, 4, 4, 6, 7, 9), exact.thrs=7, smooth=FALSE)

bootstats(c(1, 3, 4, 4, 6, 7, 8), exact.thrs=1, smooth=FALSE)

## Simple smooth function based on jitter()
bootstats(1:5, smooth=function(b=b) jitter(b))

## Alternative entropy based smooth function
x <- round(rnorm(15, 10, 2))

entropy <- function(x, base=2) {
    freqs <- table(x) / length(x)
    -sum(freqs * log(freqs, base=base))
}

H5 <- entropy(x, base=5)

bootstats(x, 
  smooth=function(b=b, x=x, H5=H5) {
      b + rnorm(length(b), 0, H5/sqrt(length(x)))
  })

bootstats(x)

## Return resamples and plot distribution of means
bst <- bootstats(c(1, 2, 2, 4), return_resamples=TRUE)
t(bst[[2]])
plot(density(colMeans(bst[[2]])))

AkselA/R-confintplot documentation built on May 9, 2019, 12:52 p.m.