# NOT RUN {
library(lfmm)
## An EWAS example with Y = methylation data
## and X = "exposure"
## Simulate the data
dat <- lfmm_sampler(n = 100,
p = 500,
K = 3,
outlier.prop = 0.01,
cs = 0.1,
sigma = 0.2,
B.sd = 5,
B.mean = 0,
U.sd = 1.0,
V.sd = 1.0)
Y <- pnorm(dat$Y)
X <- dat$X
## Fit an LFMM with 2 latent factors
mod.lfmm <- lfmm_ridge(Y = Y,
X = X,
K = 3)
## Perform association testing using the fitted model:
pv <- glm_test(Y = pnorm(Y),
X = X,
lfmm.obj = mod.lfmm,
family = binomial(link = "probit"),
calibrate = "gif")
## Manhattan plot with true associations shown
causal <- dat$outlier
pvalues <- pv$calibrated.pvalue
plot(-log10(pvalues),
pch = 19,
cex = .3,
xlab = "Probe",
col = "grey")
points(causal,
-log10(pvalues)[causal],
col = "blue")
# }
Run the code above in your browser using DataLab