Skip to content

Instantly share code, notes, and snippets.

View hakyim's full-sized avatar

Hae Kyung Im hakyim

View GitHub Profile
@hakyim
hakyim / qqR2.R
Last active March 17, 2022 20:50
Plots observed R^2 vs expected R2 under null of 0 correlation
qqR2 <- function(corvec,nn,pad_neg_with_0 = FALSE,...)
{
## nn is the sample size, number of individuals used to compute correlation.
## needs correlation vector as input.
## nullcorvec generates a random sample from correlation distributions, under the null hypothesis of 0 correlation using Fisher's approximation.
if(pad_neg_with_0) corvec[corvec < 0 | is.na(corvec) ]=0
mm <- length(corvec)
nullcorvec = tanh(rnorm(mm)/sqrt(nn-3)) ## null correlation vector
qqplot(nullcorvec^2,corvec^2,...); abline(0,1); grid()
}
@hakyim
hakyim / eFDR.R
Last active January 21, 2021 23:49
eFDR: compute empirical FDR based on observed vector of p values and empirical null p values computed using simulated phenotype
## May 7, 2012
## Hae Kyung Im
## haky@uchicago.edu
##
## Please cite:
## Eric R Gamazon, R. Stephanie Huang, Eileen Dolan, Nancy Cox, and Hae Kyung Im, (2012)
## Integrative Genomics: Quantifying significance of phenotype-genotype
## relationships from multiple sources of high-throughput data
@hakyim
hakyim / qqunif.R
Last active February 2, 2024 22:29
qqunif
## pvalue vs uniform
qqunif =
function(p,BH=T,CI=T,mlog10_p_thres=30,...)
{
## thresholded by default at 1e-30
p=na.omit(p)
nn = length(p)
xx = -log10((1:nn)/(nn+1))