If I want to use the the boot() function from R’s boot package for calculating the significance of the Pearson correlation coefficient between two vectors, should I do it like this:
boot(re1, cor, R = 1000)
where re1 is a two column matrix for these two observation vectors? I can’t seem to get this right because cor of these vectors is 0.8, but the above function returns -0.2 as t0.
Just to emphasize the general idea on bootstrapping in R, although @caracal already answered your question through his comment. When using
boot, you need to have a data structure (usually, a matrix) that can be sampled by row. The computation of your statistic is usually done in a function that receives this data matrix and returns the statistic of interest computed after resampling. Then, you call theboot()that takes care of applying this function toRreplicates and collecting results in a structured format. Those results can be assessed usingboot.ci()in turn.Here are two working examples with the
low birth babystudy in theMASSpackage.