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.
>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.