Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Any R-package for weighted bootstrap?

Quite new to in this field thus any suggestion is appreciated.
Suppose I have a data on n=200 samples. I have to give weight to each of the sample.

Suppose, at first I generate data y=rnorm(200) and weight as w=rexp(200). This weight needs to be applied to my original sample (y). i have to do this 1000 time and regenerate 1000 data (bootstrap). How could I do it using simple R funtion? Is there any package? Or how to do it manually?
I know I can perform nonparametric bootstrap using ‘sample’ with ‘replace=TRUE" in R. But i don’t know how to do weighted bootstrap.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like this should work:

y <- rnorm(200)
w <- rexp(200)
w <- w/sum(w)
y_samp <- sample(y, length(y), replace=TRUE, prob = w)

The prob argument allows you to apply a weight to the values of your sampling.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading