Checks analysis with partial bootstrap resampling.
Usage
bootstrap(object, ...)
# S4 method for numeric
bootstrap(object, do, n, ...)
# S4 method for integer
bootstrap(object, do, n, ...)
# S4 method for BootstrapVector
summary(
object,
level = 0.95,
type = c("student", "normal"),
probs = c(0.25, 0.75),
na.rm = FALSE,
...
)
# S4 method for CA
bootstrap(object, n = 30)
# S4 method for PCA
bootstrap(object, n = 30)
Arguments
- object
A
numeric
or aninteger
vector or aCA
orPCA
object (see below).- ...
Currently not used.
- do
A
function
that takesobject
as an argument and returns a single numeric value.- n
A non-negative
integer
giving the number of bootstrap replications.- level
A length-one
numeric
vector giving the confidence level. Must be a single number between \(0\) and \(1\). IfNULL
, no confidence interval are computed.- type
A
character
string giving the type of confidence interval to be returned. It must be one "student
" (default) or "normal
". Any unambiguous substring can be given. Only used iflevel
is notNULL
.``- probs
A
numeric
vector of probabilities with values in \([0,1]\) (seestats::quantile()
). IfNULL
, quantiles are not computed.- na.rm
A
logical
scalar: should missing values be removed fromobject
before the sample statistics are computed?
Value
If object
is a numeric
or an integer
vector, bootstrap()
returns a BootstrapVector
object (i.e. a numeric
vector of the n
bootstrap values of do
).
If object
is a CA
or a PCA
object, bootstrap()
returns a BootstrapCA
or a BootstrapPCA
object.
summary()
returns a numeric
vector with the following elements:
min
Minimum value.
mean
Mean value.
max
Maximum value.
lower
Lower bound of the confidence interval.
upper
Upper bound of the confidence interval.
Q*
Sample quantile to
*
probability.
Methods (by class)
numeric
: Samples randomly from the elements ofobject
with replacement.integer
: Samples observations from a multinomial distribution.
References
Greenacre, Michael J. Theory and Applications of Correspondence Analysis. London: Academic Press, 1984.
Lebart, L., Piron, M. and Morineau, A. Statistique exploratoire multidimensionnelle: visualisation et inférence en fouille de données. Paris: Dunod, 2006.
See also
Other resampling methods:
jackknife()
Examples
library(ggrepel)
#> Loading required package: ggplot2
## Random samples from x with replacement
x <- rnorm(20) # numeric
boot <- bootstrap(x, do = mean, n = 100) # Sample mean
summary(boot)
#> min mean max lower upper Q25 Q75
#> -0.5513971 -0.2265232 0.1135029 -0.2539695 -0.1990769 -0.3070494 -0.1453175
## Sample observations from a multinomial distribution
x <- sample(1:100, 100, TRUE) # integer
boot <- bootstrap(x, do = median, n = 100)
summary(boot)
#> min mean max lower upper Q25 Q75
#> 47.50000 52.24000 55.50000 51.92422 52.55578 51.00000 53.12500
## Partial bootstrap on CA
## Data from Lebart et al. 2006, p. 170-172
color <- data.frame(
brun = c(68, 15, 5, 20),
chatain = c(119, 54, 29, 84),
roux = c(26, 14, 14, 17),
blond = c(7, 10, 16, 94),
row.names = c("marron", "noisette", "vert", "bleu")
)
## Compute correspondence analysis
X <- ca(color)
## Plot results
plot(X) +
ggrepel::geom_label_repel()
## Bootstrap (30 replicates)
Y <- bootstrap(X, n = 30)
# \donttest{
## Get replicated coordinates
get_replications(Y, margin = 1)
#> , , 1
#>
#> F1 F2 F3
#> marron -0.4968409 -0.04052014 -0.03448478
#> noisette -0.2801690 0.20991548 -0.08570937
#> vert 0.1915258 0.47303899 0.05672297
#> bleu 0.6681489 -0.04706335 0.09370971
#>
#> , , 2
#>
#> F1 F2 F3
#> marron -0.4266518 -0.08965565 0.01612008
#> noisette -0.1342900 0.14072659 -0.18957888
#> vert 0.1902645 0.41381118 -0.02292729
#> bleu 0.5993245 -0.05458878 -0.00108376
#>
#> , , 3
#>
#> F1 F2 F3
#> marron -0.50527923 -0.10880017 0.05160920
#> noisette -0.28601734 0.16528556 -0.21062051
#> vert 0.09873293 0.41035293 0.24913979
#> bleu 0.60452358 -0.01664752 0.02504948
#>
#> , , 4
#>
#> F1 F2 F3
#> marron -0.4954443 -0.06264414 0.01338949
#> noisette -0.2743768 0.05372142 -0.16906055
#> vert 0.2201216 0.43043519 0.27186302
#> bleu 0.4737709 -0.06126353 0.06875306
#>
#> , , 5
#>
#> F1 F2 F3
#> marron -0.4785781 -0.22411964 0.02433008
#> noisette -0.1187314 0.27249073 -0.03024807
#> vert 0.1164296 0.43053511 0.18204483
#> bleu 0.6291912 -0.09128479 0.02233978
#>
#> , , 6
#>
#> F1 F2 F3
#> marron -0.5078252 -0.04102762 0.06874547
#> noisette -0.1230552 0.09780219 -0.11043461
#> vert 0.1671452 0.60015320 0.56604576
#> bleu 0.6870312 0.02339697 0.11180070
#>
#> , , 7
#>
#> F1 F2 F3
#> marron -0.51189928 -0.04501766 0.028384753
#> noisette -0.31921420 0.22260054 -0.066571295
#> vert 0.05672785 0.28218536 -0.283326965
#> bleu 0.54927232 -0.07269472 0.003922112
#>
#> , , 8
#>
#> F1 F2 F3
#> marron -0.5383825 -0.20287009 0.073645619
#> noisette -0.3656142 0.14344170 -0.117080228
#> vert 0.3113755 0.39336768 -0.082046866
#> bleu 0.5532826 -0.09154363 0.005212133
#>
#> , , 9
#>
#> F1 F2 F3
#> marron -0.4886783 -0.001307766 -0.07175611
#> noisette -0.1442102 0.296500137 -0.21460999
#> vert 0.1907226 0.557960934 0.10661186
#> bleu 0.5855256 -0.076942869 -0.03069651
#>
#> , , 10
#>
#> F1 F2 F3
#> marron -0.5143124 -0.094541388 0.13561883
#> noisette -0.2841814 0.249033864 -0.12938756
#> vert 0.1025561 0.502291077 0.16009193
#> bleu 0.4443887 -0.004232189 -0.02911958
#>
#> , , 11
#>
#> F1 F2 F3
#> marron -0.55231194 -0.2581747 0.11602764
#> noisette -0.17238176 0.1742198 -0.25507409
#> vert 0.05766812 0.1005296 -0.18748527
#> bleu 0.68315232 -0.1091198 0.06008005
#>
#> , , 12
#>
#> F1 F2 F3
#> marron -0.4545648 0.00751877 -0.06010826
#> noisette -0.2357174 0.27527322 -0.16388842
#> vert 0.0382763 0.38303264 0.07677478
#> bleu 0.6014437 -0.12646372 0.03458661
#>
#> , , 13
#>
#> F1 F2 F3
#> marron -0.4700825 -0.08142334 0.0049320566
#> noisette -0.2515297 0.14386093 -0.0360870827
#> vert 0.1145290 0.22828078 0.2511933718
#> bleu 0.5419223 -0.10750104 -0.0006808738
#>
#> , , 14
#>
#> F1 F2 F3
#> marron -0.5343218 -0.14652139 0.046857581
#> noisette -0.1961443 0.05525988 0.018576513
#> vert 0.1642068 0.29359199 0.006815422
#> bleu 0.5169950 -0.09129082 -0.046587497
#>
#> , , 15
#>
#> F1 F2 F3
#> marron -0.5181599 -0.2082055 0.125672234
#> noisette -0.2394027 0.1765941 -0.149003801
#> vert 0.1664211 0.1678250 0.002383024
#> bleu 0.6369644 -0.1733670 0.031740956
#>
#> , , 16
#>
#> F1 F2 F3
#> marron -0.4995219 -0.018118054 0.06886520
#> noisette -0.3871333 0.168166619 -0.09159875
#> vert 0.0915638 0.271941656 0.16359099
#> bleu 0.5566087 0.008611832 0.03284469
#>
#> , , 17
#>
#> F1 F2 F3
#> marron -0.49560397 -0.08958042 0.02124663
#> noisette -0.21605482 0.14936315 0.01398777
#> vert 0.03792371 0.40342426 0.28317595
#> bleu 0.66280894 -0.07338752 0.04194923
#>
#> , , 18
#>
#> F1 F2 F3
#> marron -0.5063867 -0.11129252 0.06136288
#> noisette -0.1786158 0.25948802 -0.16069921
#> vert 0.2096213 0.35650565 0.03092348
#> bleu 0.5962728 -0.03636342 0.03077159
#>
#> , , 19
#>
#> F1 F2 F3
#> marron -0.4722995 -0.10358887 -0.03592057
#> noisette -0.2457857 0.19896146 -0.06533668
#> vert 0.2707471 0.37943749 -0.05915964
#> bleu 0.3037658 0.03886311 -0.16988001
#>
#> , , 20
#>
#> F1 F2 F3
#> marron -0.3968674 -0.02113082 -0.10163432
#> noisette -0.2664539 0.22388959 -0.36791876
#> vert 0.1137417 0.30431192 0.01229836
#> bleu 0.5330735 -0.02388479 0.08693941
#>
#> , , 21
#>
#> F1 F2 F3
#> marron -0.5142415 -0.20147680 -0.03580960
#> noisette -0.1614675 0.28064614 -0.13868540
#> vert 0.1329746 0.43497052 0.07973258
#> bleu 0.4984402 -0.09704152 -0.07472603
#>
#> , , 22
#>
#> F1 F2 F3
#> marron -0.50199731 -0.11941160 0.012276199
#> noisette -0.32135814 -0.08652371 -0.005533253
#> vert 0.09343504 0.24511623 -0.012088451
#> bleu 0.48233881 -0.10897452 0.083188745
#>
#> , , 23
#>
#> F1 F2 F3
#> marron -0.5063608 -0.20189570 0.01815830
#> noisette -0.1990184 0.30297308 -0.04461261
#> vert 0.1368976 0.35598442 0.20222171
#> bleu 0.4367196 -0.07462164 0.04315444
#>
#> , , 24
#>
#> F1 F2 F3
#> marron -0.4656598 -0.1464057 -0.00686596
#> noisette -0.2164907 0.2731396 -0.06514263
#> vert 0.1586176 0.2205339 -0.06825168
#> bleu 0.6612424 -0.1110803 0.04296612
#>
#> , , 25
#>
#> F1 F2 F3
#> marron -0.49175020 -0.03554677 -0.111346975
#> noisette -0.10275958 0.17709523 -0.199828225
#> vert -0.01271032 0.25078139 -0.003267128
#> bleu 0.55077929 -0.05778111 -0.103824950
#>
#> , , 26
#>
#> F1 F2 F3
#> marron -0.49726317 -0.11633750 0.003577148
#> noisette -0.15663524 0.23494492 -0.087567341
#> vert -0.04337431 0.36987134 0.040765420
#> bleu 0.58803058 -0.02735104 0.034038865
#>
#> , , 27
#>
#> F1 F2 F3
#> marron -0.45476114 -0.06607246 -0.094070271
#> noisette -0.07745407 0.24723342 -0.001522229
#> vert 0.18696197 0.19056501 0.035341403
#> bleu 0.62871984 -0.07295266 -0.050086284
#>
#> , , 28
#>
#> F1 F2 F3
#> marron -0.55666875 -0.1549199 0.02823233
#> noisette -0.06938401 0.2769595 -0.26627861
#> vert 0.27283738 0.2991760 0.27496736
#> bleu 0.47951271 -0.1061164 -0.05738948
#>
#> , , 29
#>
#> F1 F2 F3
#> marron -0.5389254 -0.27419032 -0.02987881
#> noisette -0.2258271 0.03922894 -0.12298783
#> vert 0.1229234 0.32547954 0.11642078
#> bleu 0.4931448 -0.06385428 -0.04511109
#>
#> , , 30
#>
#> F1 F2 F3
#> marron -0.5312066 -0.1001550 0.02764545
#> noisette -0.1679850 0.1533494 -0.08249576
#> vert 0.1616451 0.3717303 0.24085748
#> bleu 0.5199715 -0.1395455 0.10521657
#>
get_replications(Y, margin = 2)
#> , , 1
#>
#> F1 F2 F3
#> brun -0.59269891 -0.27204877 0.007852403
#> chatain -0.27281028 0.04681004 -0.002172651
#> roux -0.07894285 0.31193899 0.098088424
#> blond 0.91046920 -0.10867858 0.052481630
#>
#> , , 2
#>
#> F1 F2 F3
#> brun -0.59663951 -0.31518789 0.069082406
#> chatain -0.16170474 0.06547917 -0.020619830
#> roux -0.09568452 0.27202671 0.169957965
#> blond 0.73789742 -0.08217788 0.003462903
#>
#> , , 3
#>
#> F1 F2 F3
#> brun -0.6722810 -0.27229639 0.14893530
#> chatain -0.2670570 -0.06685766 -0.07957773
#> roux -0.1326102 0.16561042 0.15924910
#> blond 0.8750771 -0.20363343 0.01772279
#>
#> , , 4
#>
#> F1 F2 F3
#> brun -0.44080207 -0.14841907 -0.01139760
#> chatain -0.21371308 0.07253944 -0.09943133
#> roux -0.03550838 0.41751186 0.30373907
#> blond 0.80193880 0.07894975 0.11453392
#>
#> , , 5
#>
#> F1 F2 F3
#> brun -0.56746420 -0.2535260 0.11515772
#> chatain -0.16416613 0.0387354 -0.08483334
#> roux -0.03139334 0.5370875 -0.05586640
#> blond 0.76855654 -0.1082736 -0.05868684
#>
#> , , 6
#>
#> F1 F2 F3
#> brun -0.5759453 -0.15372011 0.06638289
#> chatain -0.1806496 -0.05234133 -0.15630344
#> roux 0.0620854 0.32812748 0.25824293
#> blond 0.8783074 -0.11191292 -0.06920610
#>
#> , , 7
#>
#> F1 F2 F3
#> brun -0.44163968 -0.2550011 0.009631931
#> chatain -0.03437326 0.1489022 0.085702965
#> roux -0.10025730 0.1704124 -0.017817128
#> blond 0.96966902 -0.1823600 0.048389341
#>
#> , , 8
#>
#> F1 F2 F3
#> brun -0.54753857 -0.3425506 -0.01580713
#> chatain -0.07088389 0.0990347 0.00787293
#> roux -0.02587502 0.3516112 0.11746743
#> blond 0.90995830 -0.0568574 0.16221455
#>
#> , , 9
#>
#> F1 F2 F3
#> brun -0.5273692 -0.39199947 0.10806708
#> chatain -0.1626601 -0.02809348 -0.06711148
#> roux -0.1358804 0.33392208 0.11022104
#> blond 0.9157005 -0.14530349 -0.03999555
#>
#> , , 10
#>
#> F1 F2 F3
#> brun -0.5784176 -0.25454316 0.06633064
#> chatain -0.1106519 0.07867519 -0.11933827
#> roux -0.1275282 0.35497775 0.10121385
#> blond 0.8299634 -0.07856896 0.05536390
#>
#> , , 11
#>
#> F1 F2 F3
#> brun -0.6194985 -0.2495996 0.14073623
#> chatain -0.2114464 0.1975855 -0.18902804
#> roux -0.1375554 0.1407045 -0.17317934
#> blond 0.8341036 -0.1324184 -0.08543657
#>
#> , , 12
#>
#> F1 F2 F3
#> brun -0.4116441 -0.22430509 0.07717900
#> chatain -0.2201247 0.02831498 -0.08138473
#> roux -0.1894939 0.30188537 0.01618851
#> blond 0.8947725 -0.20746209 -0.02547889
#>
#> , , 13
#>
#> F1 F2 F3
#> brun -0.4046455 -0.04333794 0.03514153
#> chatain -0.1377127 0.02174883 -0.09827104
#> roux -0.1241763 0.40782474 0.04116631
#> blond 0.8197239 -0.05931764 0.03160987
#>
#> , , 14
#>
#> F1 F2 F3
#> brun -0.53234455 -0.18867796 0.005517542
#> chatain -0.09873327 0.02976044 0.024497595
#> roux -0.14348834 0.33223669 0.084524031
#> blond 0.83258143 -0.01170232 -0.005895072
#>
#> , , 15
#>
#> F1 F2 F3
#> brun -0.5163777 -0.24237766 0.10358194
#> chatain -0.1564821 0.08166781 -0.11748283
#> roux -0.2267366 0.24557530 -0.05278090
#> blond 0.8494555 -0.14158647 0.01553918
#>
#> , , 16
#>
#> F1 F2 F3
#> brun -0.48318379 -0.04148297 -0.01736949
#> chatain -0.09889756 0.06885155 -0.13361032
#> roux -0.04492404 0.22275668 0.02967480
#> blond 0.94854826 -0.15808658 0.08831282
#>
#> , , 17
#>
#> F1 F2 F3
#> brun -0.5636659 -0.08611450 0.07687446
#> chatain -0.2370838 0.02937827 -0.01580499
#> roux -0.1134973 0.47490608 0.15868144
#> blond 0.8317807 -0.08237761 -0.01346469
#>
#> , , 18
#>
#> F1 F2 F3
#> brun -0.59922543 -0.32243102 0.123487752
#> chatain -0.16292227 0.03906659 -0.084685748
#> roux -0.08872457 0.21934736 0.007324563
#> blond 0.85286612 -0.10605186 -0.000924499
#>
#> , , 19
#>
#> F1 F2 F3
#> brun -0.56795655 -0.276891586 -0.04356517
#> chatain -0.02607463 -0.008921548 -0.04491184
#> roux -0.05985666 0.313750345 -0.04866088
#> blond 0.74113333 0.048811590 0.08068146
#>
#> , , 20
#>
#> F1 F2 F3
#> brun -0.40621518 -0.23812614 0.11264511
#> chatain -0.23377642 0.08431617 -0.11761991
#> roux 0.02862494 0.16997076 0.09701370
#> blond 0.80210101 -0.15907429 0.07108569
#>
#> , , 21
#>
#> F1 F2 F3
#> brun -0.57188450 -0.32359253 0.161653144
#> chatain -0.15040018 0.03231398 -0.005517225
#> roux -0.07578767 0.59690153 0.096270049
#> blond 0.80768318 -0.03244748 0.024497874
#>
#> , , 22
#>
#> F1 F2 F3
#> brun -0.42588402 -0.12637937 -0.08040199
#> chatain -0.20720144 0.03686945 0.01005777
#> roux -0.07575059 0.16708763 0.12349757
#> blond 0.83299148 -0.09070656 0.01060690
#>
#> , , 23
#>
#> F1 F2 F3
#> brun -0.429003553 -0.22855922 0.12555614
#> chatain -0.144193729 0.04396478 -0.07019129
#> roux 0.008980427 0.50144763 -0.02727208
#> blond 0.784751572 -0.01336707 0.04307175
#>
#> , , 24
#>
#> F1 F2 F3
#> brun -0.5295646 -0.21008775 0.11278127
#> chatain -0.1833138 0.13556901 0.02086187
#> roux -0.1077644 0.37929143 -0.08297452
#> blond 0.8113060 -0.06337545 0.07058767
#>
#> , , 25
#>
#> F1 F2 F3
#> brun -0.5369188 -0.14360603 0.23964367
#> chatain -0.1428582 0.02511217 0.07650986
#> roux -0.1415312 0.33963835 0.21323621
#> blond 0.8712755 -0.07346265 -0.03620212
#>
#> , , 26
#>
#> F1 F2 F3
#> brun -0.5490216 -0.25372342 0.12327074
#> chatain -0.1523089 -0.02117028 -0.04869329
#> roux -0.0189157 0.20330619 -0.03596923
#> blond 0.8828647 -0.24208431 -0.11218509
#>
#> , , 27
#>
#> F1 F2 F3
#> brun -0.5734908 -0.1307679903 0.05285589
#> chatain -0.2097141 0.0206665511 -0.07507213
#> roux -0.1963413 0.3805453640 -0.24167375
#> blond 0.7414199 0.0008124745 -0.09777576
#>
#> , , 28
#>
#> F1 F2 F3
#> brun -0.5050929 -0.31971389 0.23883374
#> chatain -0.1423565 -0.01289670 -0.16935324
#> roux -0.1470608 0.40217121 0.07552330
#> blond 0.8297251 0.04805687 -0.02872387
#>
#> , , 29
#>
#> F1 F2 F3
#> brun -0.51606001 -0.196506577 0.055839675
#> chatain -0.07723371 -0.006013988 -0.041895825
#> roux 0.14301315 0.460882233 0.148864353
#> blond 0.85722496 -0.087894418 -0.001393031
#>
#> , , 30
#>
#> F1 F2 F3
#> brun -0.39199683 -0.20562793 0.082352500
#> chatain -0.22404812 0.04025555 -0.050761391
#> roux -0.08660588 0.41098261 0.166909451
#> blond 0.84403054 0.01123001 0.004460793
#>
# }
## Plot with ellipses
plot_rows(Y) +
ggplot2::stat_ellipse()
plot_columns(Y) +
ggplot2::stat_ellipse()
## Partial bootstrap on PCA
## Compute principal components analysis
data(iris)
X <- pca(iris)
#> 1 qualitative variable was removed: Species.
## Plot results
plot_columns(X) +
ggrepel::geom_label_repel()
## Bootstrap (30 replicates)
Y <- bootstrap(X, n = 30)
## Plot with ellipses
plot_columns(Y) +
ggplot2::stat_ellipse()