Displaying 1 result from an estimated 1 matches for "boot_script".
2017 Jun 21
0
Advanced bootstrap question
...ot to sample from a concatenation of the two
datasets. The two datasets have entirely different contents (variable and
numbers of observations. MWE follows:
library(boot)
library(car)
library(dplyr)
(first.df <- data.frame(cluster=gl(2,2,4),z=seq(1,2)))
(second.df <- data.frame(y=1:2))
boot_script <- function(X,d) {
zbar <- mean(sample_n(group_by(first.df,cluster),1)$z)
return( c(zbar, zbar * mean(X[d,"y"]) ))
}
## Results based on the original data
(original.zbar <- mean(first.df$z))
mean(original.zbar * second.df[,"y"])
## Bootstrapped results
##...