Diff for "FAQ/FDR" - CBU statistics Wiki
location: Diff for "FAQ/FDR"
Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2006-12-11 17:54:35
Size: 1024
Comment:
Revision 5 as of 2006-12-12 08:26:42
Size: 1104
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
* R Code to Perform the Benjamini and Hochberg FDR procedure [Insert P values in any order] === R Code to Perform the Benjamini and Hochberg FDR procedure ===
Line 3: Line 3:
'''
pvalue <- c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1) sorted.pvalue<-sort(pvalue) sorted.pvalue j.alpha <- (1:10)*(.05/10) diff <- sorted.pvalue-j.alpha neg.diff <- diff[diff<0] pos.diff <- neg.diff[length(neg.diff)] index <- diff==pos.diff p.cutoff <-sorted.pvalue[index] p.cutoff p.sig <- pvalue[pvalue <= p.cutoff] p.sig
{{{
Line 6: Line 5:
R Output > pvalue<-c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1) > sorted.pvalue <- sort(pvalue) > sorted.pvalue [Insert P values in any order]

pvalue <- c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1)
sorted.pvalue<-sort(pvalue)
sorted.pvalue
j.alpha <- (1:10)*(.05/10)
diff <- sorted.pvalue-j.alpha
neg.diff <- diff[diff<0]
pos.diff <- neg.diff[length(neg.diff)]
index <- diff==pos.diff
p.cutoff <-sorted.pvalue[index]
p.cutoff
p.sig <- pvalue[pvalue <= p.cutoff]
p.sig
}}}

=== R Output ===

{{{
> pvalue<-c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1)
> sorted.pvalue <- sort(pvalue)
> sorted.pvalue
Line 9: Line 29:
[1] 0.001 0.005 0.017 0.021 0.023 0.036 0.041 0.042 0.070 0.100
Line 10: Line 31:
[1] 0.001 0.005 0.017 0.021 0.023 0.036 0.041 0.042 0.070 0.100 > j.alpha <- (1:10) * (0.05/10) > diff <- sorted.pvalue - j.alpha > neg.diff <- diff[diff < 0] > pos.diff <- neg.diff[length(neg.diff)] > index <- diff == pos.diff > p.cutoff <- sorted.pvalue[index] > p.cutoff [1] 0.023 > p.sig <- pvalue[pvalue <= p.cutoff] > p.sig > j.alpha <- (1:10) * (0.05/10)
> diff <- sorted.pvalue - j.alpha
> neg.diff <- diff[diff < 0]
> pos.diff <- neg.diff[length(neg.diff)]
> index <- diff == pos.diff
> p.cutoff <- sorted.pvalue[index]
> p.cutoff
[1] 0.023
Line 12: Line 40:
[significant p values by B-H method]: [1] 0.021 0.001 0.017 0.005 0.023
'''
> p.sig <- pvalue[pvalue <= p.cutoff] > p.sig

[significant p values by B-H method]:
[1] 0.021 0.001 0.017 0.005 0.023
}}}

R Code to Perform the Benjamini and Hochberg FDR procedure

[Insert P values in any order]

pvalue <- c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1) 
sorted.pvalue<-sort(pvalue) 
sorted.pvalue 
j.alpha <- (1:10)*(.05/10) 
diff <- sorted.pvalue-j.alpha 
neg.diff <- diff[diff<0] 
pos.diff <- neg.diff[length(neg.diff)] 
index <- diff==pos.diff 
p.cutoff <-sorted.pvalue[index] 
p.cutoff 
p.sig <- pvalue[pvalue <= p.cutoff] 
p.sig

R Output

> pvalue<-c(0.021,0.001,0.017,0.041,0.005,0.036,0.042,0.023,0.07,0.1) 
> sorted.pvalue <- sort(pvalue) 
> sorted.pvalue

[sorted P values in ascending order]
[1] 0.001 0.005 0.017 0.021 0.023 0.036 0.041 0.042 0.070 0.100 

> j.alpha <- (1:10) * (0.05/10) 
> diff <- sorted.pvalue - j.alpha 
> neg.diff <- diff[diff < 0] 
> pos.diff <- neg.diff[length(neg.diff)] 
> index <- diff == pos.diff 
> p.cutoff <- sorted.pvalue[index] 
> p.cutoff 
[1] 0.023 

> p.sig <- pvalue[pvalue <= p.cutoff] > p.sig

[significant p values by B-H method]: 
[1] 0.021 0.001 0.017 0.005 0.023

None: FAQ/FDR (last edited 2015-03-11 11:55:06 by PeterWatson)