1 | bootstrip(mat, mod, fn, iterations = 100, p_samples = 0.5, mc.cores = 12)
|
mat |
|
mod |
|
fn |
|
iterations |
|
p_samples |
|
mc.cores |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (mat, mod, fn, iterations = 100, p_samples = 0.5, mc.cores = 12)
{
stopifnot(nrow(mod) == ncol(mat))
ta = mclapply(1:iterations, function(core_i) {
idx = sample.int(ncol(mat), p_samples * ncol(mat), replace = TRUE)
msub = mat[, idx, drop = TRUE]
fit = lmFit(msub, mod[idx, , drop = TRUE])
fn(fit)
}, mc.cores = mc.cores)
beta = matrix(NA, nrow(mat), ncol = iterations)
for (i in 1:iterations) {
beta[, i] = ta[[i]]
}
colnames(beta) = paste0("sample_", 1:iterations)
rownames(beta) = rownames(mat)
beta
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.