-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcd.Rmd
89 lines (70 loc) · 2.61 KB
/
cd.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: "Mapping disease risk loci using varbvs"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Crohn's disease demo}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
This vignettes demonstrates how to fit a Bayesian variable selection model
using **varbvs** to identify genetic markers associated with Crohn's
disease risk. The data consist of 442,001 SNPs genotyped for 1,748 cases
and 2,938 controls. Note that file `cd.RData` cannot be made publicly
available due to data sharing restrictions, so this vignette is for
viewing only.
```{r, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(eval = FALSE,collapse = TRUE,comment = "#")
```
Begin by loading a couple packages into the R environment.
```{r, eval = TRUE, message = FALSE}
library(lattice)
library(varbvs)
```
Set the random number generator seed.
```{r, eval = TRUE}
set.seed(1)
```
## Load the genotype and phenotype data
```{r}
load("cd.RData")
```
## Fit variational approximation to posterior
Here we fit the fully-factorized variational approximation to the posterior
distribution of the coefficients for a logistic regression model of a binary
outcome (case-control status), with spike and slab priors on the coefficients.
```{r}
r <- system.time(fit <- varbvs(X,NULL,y,family = "binomial",
logodds = seq(-6,-3,0.25),n0 = 0)
cat(sprintf("Model fitting took %0.2f minutes.\n",r["elapsed"]/60))
```
Compute "single-marker" posterior inclusion probabilities.
```{r}
pip <- c(varbvsindep(fit,X,NULL,y)$alpha %*% fit$w)
```
## Save the results to a file
```{r}
save(list = c("fit","map","pip","r"),
file = "varbvs.demo.cd.RData")
```
## Summarize the model fitting
```{r}
print(summary(fit,nv = 9))
```
Show two "genome-wide scans", one using the posterior inclusion
probabilities (PIPs) computed in the joint analysis of all
variables, and one using the PIPs that ignore correlations between
the variables. The latter is meant to look like a typical
genome-wide "Manhattan" plot used to summarize the results of a
genome-wide association study. Variables with `PIP > 0.5` are
highlighted.
```{r, fig.width = 9,fig.height = 4,fig.align = "center"}
i <- which(fit$pip > 0.5)
var.labels <- paste0(round(map$pos[i]/1e6,digits = 2),"Mb")
print(plot(fit,groups = map$chr,vars = i,var.labels = var.labels,gap = 7500,
ylab = "posterior prob."),
split = c(1,1,1,2),more = TRUE)
print(plot(fit,groups = map$chr,score = log10(pip + 0.001),vars = i,
var.labels = var.labels,gap = 7500,ylab = "log10 posterior prob."),
split = c(1,2,1,2),more = FALSE)
```