Skip to content

Instantly share code, notes, and snippets.

View dritoshi's full-sized avatar

Itoshi NIKAIDO dritoshi

  • RIKEN/TMDU
  • Japan
  • X @dritoshien
View GitHub Profile
@dritoshi
dritoshi / wilocox_test.r
Created April 24, 2012 05:43
Exact Wilcoxon Mann-Whitney Rank Sum Test in R
> 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
@dritoshi
dritoshi / sim_portliner.r
Created April 4, 2012 10:28
A simulator for portliner's pass price vs. tickets
##
## 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
@dritoshi
dritoshi / set_bioconductor_jp.r
Created April 3, 2012 07:34
Set a bioconductor mirror in Japan
> chooseBioCmirror()
BioC mirror
1: Seattle (USA)
2: Bethesda (USA)
3: Dortmund (Germany)
4: Bergen (Norway)
5: Cambridge (UK)
6: Riken, Kobe (Japan)
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(
mci.mclapply <- function(x, u) {
mclapply(x,
function(x) {
g <- x * exp( -(u * x)^2 / 2)
mean(g) / sqrt(2 * pi) + 0.5
}
)
}
test_that("mci.mclapply return identical vector of mci.for", {
expect_identical(mci.for(x, u), unlist(mci.mclapply(x, u)))
})
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)
mci.sapply <- function(x, u) {
unlist(sapply(x,
function(x) {
g <- x * exp( -(u * x)^2 / 2)
mean(g) / sqrt(2 * pi) + 0.5
}
))
}
@dritoshi
dritoshi / mci.r
Created April 2, 2012 10:32
Monte Carlo for Unbounded Integration (sapply)
mci.sapply.list <- function(x, u) {
sapply(x,
function(x) {
g <- x * exp( -(u * x)^2 / 2)
mean(g) / sqrt(2 * pi) + 0.5
}
)
}
mci.sapply.list <- function(x) {
sapply(x,
function(x) {
g <- x * exp( -(u * x)^2 / 2)
mean(g) / sqrt(2 * pi) + 0.5
}
)
}