- httsp://hackingisbelieving.org/
- @dritoshien
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library("coin") | |
> data <- data.frame(value = c(1,4,3,2,5,9), exp.name = factor(c(rep("a", 3), rep("b", 3)))) | |
> data | |
value exp.name | |
1 1 a | |
2 4 a | |
3 3 a | |
4 2 b | |
5 5 b | |
6 9 b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## simulator for portliner's pass price vs. tickets | |
## | |
# http://www.knt-liner.co.jp/ticket/coupon.asp | |
# http://www.knt-liner.co.jp/station/fee.asp | |
days <- seq(18, 25) | |
one.month <- 9210 / 1 | |
six.month <- 46980 / 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> chooseBioCmirror() | |
BioC mirror | |
1: Seattle (USA) | |
2: Bethesda (USA) | |
3: Dortmund (Germany) | |
4: Bergen (Norway) | |
5: Cambridge (UK) | |
6: Riken, Kobe (Japan) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source("mci.r") | |
set.seed(1234) | |
x.num <- 1000 | |
x <- seq(0.1, 2.5, length = x.num) | |
m <- 100000 | |
u <- runif(m) | |
cdf <- numeric(x.num) | |
mci.profiles <- cbind( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mci.mclapply <- function(x, u) { | |
mclapply(x, | |
function(x) { | |
g <- x * exp( -(u * x)^2 / 2) | |
mean(g) / sqrt(2 * pi) + 0.5 | |
} | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_that("mci.mclapply return identical vector of mci.for", { | |
expect_identical(mci.for(x, u), unlist(mci.mclapply(x, u))) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source("mci.r") | |
context("mci function for multicore") | |
set.seed(1234) | |
x.num <- 100 | |
x <- seq(0.1, 2.5, length = x.num) | |
m <- 100000 | |
u <- runif(m) | |
cdf <- numeric(x.num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mci.sapply <- function(x, u) { | |
unlist(sapply(x, | |
function(x) { | |
g <- x * exp( -(u * x)^2 / 2) | |
mean(g) / sqrt(2 * pi) + 0.5 | |
} | |
)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mci.sapply.list <- function(x, u) { | |
sapply(x, | |
function(x) { | |
g <- x * exp( -(u * x)^2 / 2) | |
mean(g) / sqrt(2 * pi) + 0.5 | |
} | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mci.sapply.list <- function(x) { | |
sapply(x, | |
function(x) { | |
g <- x * exp( -(u * x)^2 / 2) | |
mean(g) / sqrt(2 * pi) + 0.5 | |
} | |
) | |
} |