Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rcpp::sourceCpp("parallel_boot_lm.cpp") # could be found at http://pastebin.com/Xir4LYei
- set.seed(1234)
- N <- 1e3L
- p <- 50L
- R <- 500L
- dmat <- cbind(1, matrix(rnorm(N * p), ncol = p))
- beta <- c(2, runif(p))
- yvec <- as.vector(dmat %*% beta + rnorm(N, sd = 3))
- dall <- cbind(y = yvec, as.data.frame(dmat[,-1]))
- myindex <- matrix(sample(0:(N - 1), N * R, TRUE), ncol = R)
- system.time(res1 <- parallelFit(dmat, yvec, myindex))
- # user system elapsed
- # 1.00 0.00 0.14
- system.time(res2 <- apply(myindex, 2, function(i) coef(lm(y ~ ., data = dall[i+1, ]))))
- # user system elapsed
- # 4.59 0.00 4.59
- stopifnot(all(abs(res1 - res2) < 1e-8))
Advertisement
Add Comment
Please, Sign In to add comment