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)...)
 
(fudge to add N(0,1) under NULL)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
# {{R}}
 
# 1) simulation page 17
 
# 1) simulation page 17
  
Line 21: Line 22:
 
library(locfdr)
 
library(locfdr)
  
locfdr(teststat, type=1)
+
locfdr(teststat, bre=100, type=1)
locfdr(teststat, type=0)
 
  
 +
locfdr(teststat, bre=100, type=0)
 +
 +
a <- hist(teststat, breaks=100, plot=FALSE)
 
q0 <- seq(-4,4, length=1001)  
 
q0 <- seq(-4,4, length=1001)  
 
null <- dnorm(q0)
 
null <- dnorm(q0)
lines(q0, null*80, type="l", col="red")
+
lines(q0, null*sum(a$counts)*diff(a$breaks)[1], type="l", col="red")
  
lines(theoretical*10000, col="red")
+
# prob=TRUE
tmp <- density(theoretical)
+
a <- hist(teststat, breaks=120, prob=TRUE)
tmp$y <- tmp$y*p/10
+
q0 <- seq(-4,4, length=1001)  
lines(tmp, col="red")
+
null <- dnorm(q0)
 +
lines(q0, null, type="l", col="red")

Latest revision as of 12:47, 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, 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")

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