Library: | stats |
See also: | uniform permutation |
Quantlet: | bootstrap | |
Description: | calculates from data vector x different bootstrap replications |
Usage: | bx = bootstrap(x,nb,opt) | |
Input: | ||
x | n x 1 vector, data | |
nb | scalar, number of bootstrap replications | |
opt | string, option that defines the kind of bootstrap: "wild" - using golden section rule, "permut" - simple permutation, "naive" - naive bootstrap | |
Output: | ||
bx | n x nb matrix, bootstrap replications |
library("stats") randomize(4321) n = 100 x = normal(n) ; generate normal data bx = bootstrap(x,200,"wild") ; wild bootstrap sample "mean of data vector" mean(x) ; mean of original data "mean of wild bootstrap" mean(mean(bx)') ; mean of wild bootstrap bx = bootstrap(x,200,"permut") "mean of permutation bootstrap" mean(mean(bx)') ; mean of permutations = mean of data bx = bootstrap(x,200,"naive") "mean of naive bootstrap" mean(mean(bx)') ; mean of naive bootstrap
Contents of _tmp [1,] "mean of data vector" Contents of mean [1,] 0.17198 Contents of _tmp [1,] "mean of wild bootstrap" Contents of mean [1,] 0.0049184 Contents of _tmp [1,] "mean of permutation bootstrap" Contents of mean [1,] 0.17198 Contents of _tmp [1,] "mean of naive bootstrap" Contents of mean [1,] 0.16547
library("stats") randomize(4321) n = 100 x = normal(n) ; generate normal data bx = bootstrap(x,200,"naive") mubx = mean(bx)' ; mean of bootstrap samples stdbx = sqrt(var(bx))' ; std. deviation of bootstrap samples bxm = sqrt(n) *(mubx - mean(x)) / stdbx bxm ; one may now plot a density of these values and calculate ; quantiles for confidence intervals
Only first and last five elements are shown: Contents of bxm [ 1,] -0.2676 [ 2,] -0.47251 [ 3,] -1.1546 [ 4,] 1.33 [ 5,] -0.72827 ... [196,] 1.6301 [197,] 1.5728 [198,] 0.36706 [199,] -0.52581 [200,] 0.11956