Difference between revisions of "Locfdr.R"

From Organic Design wiki
(New page: # 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)...)
 
m
Line 1: Line 1:
 +
# {{R}}
 
# 1) simulation page 17
 
# 1) simulation page 17
  

Revision as of 12:17, 10 July 2007

Code snipits and programs written in R, S or S-PLUS

  1. 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)

  1. 2) multtest

library(multtest) teststat <- mt.teststat(X, cl) hist(teststat)

  1. 3) locfdr

library(locfdr)

locfdr(teststat, type=1) locfdr(teststat, type=0)

q0 <- seq(-4,4, length=1001) null <- dnorm(q0) lines(q0, null*80, type="l", col="red")

lines(theoretical*10000, col="red") tmp <- density(theoretical) tmp$y <- tmp$y*p/10 lines(tmp, col="red")