%
% NOTE -- ONLY EDIT THE .Rnw FILE!!!  The .tex file is
% likely to be overwritten.
%
%\VignetteIndexEntry{GLIDE}
%\VignetteDepends{}
%\VignetteKeywords{Documentation}
%\VignettePackage{GLIDE}
\documentclass[12pt]{article}
\usepackage{times}
\usepackage{hyperref}
%\usepackage[authoryear,round]{natbib}

\textwidth=6.2in
\textheight=8.5in
%\parskip=.3cm
\oddsidemargin=.1in
\evensidemargin=.1in
\headheight=-.3in

\newcommand{\scscst}{\scriptscriptstyle}
\newcommand{\scst}{\scriptstyle}

\newcommand{\R}{{\textsf{R}}}
\newcommand{\code}[1]{{\texttt{#1}}}
\newcommand{\term}[1]{{\emph{#1}}}
\newcommand{\Rpackage}[1]{\textsf{#1}}
\newcommand{\Rfunction}[1]{\texttt{#1}}
\newcommand{\Robject}[1]{\texttt{#1}}
\newcommand{\Rclass}[1]{{\textit{#1}}}
\newcommand{\Rmethod}[1]{{\textit{#1}}}
\newcommand{\Rfunarg}[1]{{\textit{#1}}}

%\bibliographystyle{plainnat}

\begin{document}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}
\SweaveOpts{concordance=TRUE}

\title{The \Rpackage{GLIDE} package: Global and Individual Tests for Direct Effects}
\author{Xiaoyu Wang, James Y. Dai}
\maketitle

\section{Introduction}

``Mendelian randomization'', an inferential method that uses germline genotypes as instrumental variables (IVs) to study the environmentally modifiable cause of human disease, has been increasingly popular in genetic epidemiology. Exploiting the random assortment of genes from parents to offsprings at the time of gamete formation, likened to ``Nature$\prime$s randomized experiment'', Mendelian randomization holds promise for removing confounding and reverse causation that loom over observational epidemiology. While conceptually appealing, skepticism has persisted on feasibility of strong assumptions required by Mendelian randomization, stated informally, that genetic variants are independent of confounders of the exposuredisease relation, that genetic variants are associated with the exposure, preferably strongly, and that there is no direct effect from genetic variants to the disease other than the pathway through the exposure, also known as no ``pleiotropy''. As the founding principle, the independence assumption is largely backed by random meiosis and further aided by adjustment for population substructures. The strength of IVs can be somewhat improved by inclusion of tens and hundreds of known risk loci identified by genome-wide association studies with increasingly larger sample sizes. Perhaps the Achilles$\prime$ heel for Mendelian randomization is potential pleiotropic effects among candidate genetic IVs, which can be sometimes plausible given complex biological pathways and networks. This threat to the validity of Mendelian randomization is heightened by the very practice of including a large number of risk variants to boost the strength of IVs.

Take current investigations on body mass index (BMI) and risk of colorectal cancer for example. Using seventy seven genome-wide significant SNPs for high BMI in the GIANT consortium study, several Mendelian randomization studies have reported strong evidence of causal relationship between BMI and colorectal cancer risk. However, as revealed by the GIANT consortium study, BMI is one of many metabolic phenotypes, and many BMI-associated SNPs are also associated with other metabolic phenotypes such as type2 diabetes, higher high-density lipoprotein cholesterol (HDL), and coronary artery diseases (CAD). Pathway analysis therein suggested that risk loci involve in central nervous system, glutamate signalling, energy metabolism, lipid biology and adipogenesis, underscoring the heterogeneous aetiology of obesity. Possibility of pleiotropy for these 77 SNPs, or a subset of them, is not dismissable. Methodologies for detecting pleiotropy and, more ambitiously, estimating causal effect in the presence of pleiotropy have been under active development. 

we propose \Rpackage{GLIDE}, GLobal and Individual tests for Direct Effects, a statistical method to assess pleiotropy and refine IVs for Mendelian randomization \cite{Dai2017}. Causal effects are defined in relative risk, a measure that is collapsible and well interpretable for binary disease endpoints. Though not all direct effects defined in a joint causal model are identifiable, we show that ``marginal'' direct effects, the direct effect for one individual variant that is not conditional on other direct effects, are estimable and provide valid tests for individual direct effects. A quantile-quantile plot is proposed to examine the degree of pleiotropy graphically. A parametric simulation procedure gives the significance of pleiotropic effect for any given variant, as well as evidence of global violation. Based on the proposed method, investigators can determine whether the set of genetic variants being considered for IVs are grossly invalid, or a subset of them appears trustworthy for Mendelian randomization. Our comprehensive simulation results suggest that the proposed test is nearly uniformly more sensitive than the Egger regression. When used to reanalyze BMI, height and colorectal cancer risk in the Genetics and Epidemiology of Colorectal Cancer Consortium (GECCO), our method suggests that at least several variants among the SNPs being used as IVs exhibit strong evidence of pleiotropy and therefore should be excluded in Mendelian randomization.



<<loadLibrary, echo=FALSE, results=hide>>=

library(GLIDE)
@

\section{Main function}

We show an example simulation data. 
First we load the example dataset:
<<data>>=
data(simdata)
simdat=simdata$simdat
coeff=simdata$coeff
ls()

@

We find the columns in dat that contain genotype data:
<<genotype_columns>>=
genotype_columns=which(grepl("^SNP",colnames(simdat)))
@

We feed in the formula of outcome ~ adjusting covariates:
<<formula>>=
formula=as.formula("outcome~age+sex+pc1+pc2+pc3")
formula
@

We then run the glide function:
<<out>>=
out=glide(formula=formula,exposure_coeff=coeff,genotype_columns,data=simdat,np=100000,
qcutoff=0.2,parallel=TRUE,corenumber=1,verbose=TRUE)
head(out)
@

\section{plot result}
We draw the q-q plot: plot.glide(out)
We draw the Egger plot: plot.egger(out)
The figures are shown as follows:
@<<fig=TRUE,echo=FALSE, width=10, height=5>>=
@@
<<echo = FALSE, results=tex>>=
cat('\\begin{figure}[h]\n')
file = "./plot.png"
cat('\\includegraphics{', file, '}\n', sep = '')
cat('\\end{figure}\n')
@



\section{session information}

The version number of \R{} and packages loaded for generating the vignette were:

\begin{verbatim}
<<sessionInfo, echo=FALSE, results=tex>>=
sessionInfo()
@
\end{verbatim}

\bibliographystyle{plain}
\bibliography{GLIDE}
 

\end{document}
