Locfdr.R
From Organic Design wiki
Code snipits and programs written in R, S or S-PLUS
- 1) simulation page 17
p <- 1000 n <- 10 Ind <- matrix(rep(rep(c(-1,1), each=n), each=p), nr=p)
Sb <- 20
u <- matrix(rnorm(p*2*n, 0, 1 ), nr=p, nc=2*n)
B <- matrix(rnorm(p*2*n, 0, Sb), nr=p, nc=2*n)
X <- u + B*Ind/2
cl <- rep(0:1, each=n)
- 2) multtest
library(multtest) teststat <- mt.teststat(X, cl) hist(teststat)
- 3) locfdr
library(locfdr)
locfdr(teststat, bre=100, type=1)
locfdr(teststat, bre=100, type=0)
a <- hist(teststat, breaks=100, plot=FALSE) q0 <- seq(-4,4, length=1001) null <- dnorm(q0) lines(q0, null*sum(a$counts)*diff(a$breaks)[1], type="l", col="red")
- prob=TRUE
a <- hist(teststat, breaks=120, prob=TRUE) q0 <- seq(-4,4, length=1001) null <- dnorm(q0) lines(q0, null, type="l", col="red")