I am writing a bootstrap function to estimate the differences between two proportions; however, I have this error in my R code: number of items to replace is not a multiple of replacement length. I have attached the code and could anyone please help me with this? Thanks in advance.
b_prop=c(0.33,0.75,0.45,0.21,0.085,0.045,0.34,0.12,0.42,0.56,0.67,0.90,0.34,0.65,0.67,0.92,0.34,0.45,0.34,0.45,0.54,0.78,0.72,0.34)
w_prop=c(0.12,0.65,0.87,0.97,0.73,0.54,0.68,0.98,0.72,0.43,0.91,0.54,0.63,0.6,0.95,0.81,0.7,0.34,0.58,0.67,0.93,0.23,0.45,0.97)
Dcompute <- function (b_prop, w_prop, n.boot=1000)
{
D= w_prop-b_prop
D.boot<-numeric()
n <-24
for(j in 1:n.boot)
{
Samp <- sample(x=1:n, size=n, replace=TRUE)
b_prop.boot <- b_prop[Samp]
w_prop.boot <- w_prop[Samp]
D.boot[j]<-w_prop.boot-b_prop.boot. #the problem is here
}
D.estimate <-c(D, quantile(D.boot, c(0.025, 0.975)))
results <- list( D.estimate= D.estimate, D.boot=D.boot)
return(results)
}
Dcompute(b_prop=b_prop, w_prop=b_prop, n.boot=10000)
But i got : In ICE.boot[j] <- w_prop.boot - b_prop.boot : number of items to replace is not a multiple of replacement length