\subsubsection{Training Neural Network Vehicle Dynamics}

Our fully-connected neural network approximates the nonlinear vehicle dynamics. Note that only the dynamic state variables are considered as input to the neural network. We denote $\left|{\bf x}_{d}\right|$ and $\left|{\bf u}\right|$ as the size of the controller's state and action. The history of states and actions, which has a size of $(\left|{\bf x}_{d}\right| + \left|{\bf u}\right|) \cdot H $, is forward propagated to the neural network. Then, the output of the network predicts the residual difference between the current state and the next state, which has the size of $\left|{\bf x}_{d}\right|$. The network was implemented as an MLP with four hidden layers. We applied a hyperbolic tangent (tanh) activation function, and the network was trained with the mean squared error loss function and Adam optimizer.

We collected a human-controlled driving dataset, with a data rate of $10$ Hz, to train our network by expanding the methods used in our previous work \cite{bae_curriculum_2021}. We found that the dataset should comprise three types of distinct maneuvers in order for the neural network to accurately represent the vehicle dynamics for various friction conditions:
\begin{enumerate}
    \item Zig-zag driving at low speeds ($20-25$ km/h) on the race track, in both clockwise and counter-clockwise directions. Each driving in a different direction was treated as a separate maneuver.

    \item High speed driving on the race track in both directions, trying to maintain $40$ km/h as much as possible.

    \item Sliding maneuvers at the friction limits on flat ground, in combinations of acceleration and deceleration with various steering angles.
\end{enumerate}
The above five maneuvers were done with seven different friction coefficients: $[0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]$. These $35$ maneuvers were logged for two minutes each, obtaining a total of $70$ minutes of driving data. We divided the data into $70 \, \%$ for training and $30 \, \%$ for testing after randomizing the data to break temporal correlations. The trained model was saved when it showed the best result for test error. Then, it was evaluated with the validation dataset. We collected the validation data on the race track in both directions. The default friction coefficient was set to $0.8$ and the friction coefficients of the six curves were set to $[0.95, 0.85, 0.75, 0.65, 0.55, 0.45]$, respectively, which were previously not included in the training data.

The test and validation errors of our neural network are shown in Table~\ref{table:errors}. Root Mean Square Error (RMSE) is denoted as $\mathbf{E}_{RMS}$ and the max error is denoted as $\mathbf{E}_{max}$. The results show that our neural network can make accurate one-step predictions under a variety of driving conditions.

\begin{table}[ht]
\renewcommand\arraystretch{1.2}
\captionsetup{justification=centering}
\caption{Test and validation errors of the neural network vehicle dynamics.}
\label{table:errors}
\begin{center}
\begin{tabularx}{1.0\columnwidth}{c|cc|cc|cc|}
& \multicolumn{2}{c|}{$v_x$ [m/s]} & \multicolumn{2}{c|}{$v_y$ [m/s]} & \multicolumn{2}{c|}{$r$ [rad/s]} \\ \cline{2-7}
& $\mathbf{E}_{RMS}$ & $\mathbf{E}_{max}$ & $\mathbf{E}_{RMS}$ & $\mathbf{E}_{max}$ & $\mathbf{E}_{RMS}$ & $\mathbf{E}_{max}$  \\ \cline{1-7}
\textbf{Test} & 0.0273 & 0.3940 & 0.0178 & 0.3180 & 0.0147 & 0.3455 \\
\textbf{Val.} & 0.0220 & 0.3753 & 0.0114 & 0.1127 & 0.0095 & 0.1413 \\
\end{tabularx}
\end{center}
\vspace*{-0.15in}
\end{table}

\subsubsection{Experimental Setup}
We designed the state-dependent cost function $c({\bf x})$ in MPC to have the following form:
\begin{equation} \label{eq:cost}
\begin{aligned}
    c({\bf x}) & = \alpha_1{\text{Track}({\bf x})} + \alpha_2{\text{Speed}({\bf x})} + \alpha_3{\text{Slip}({\bf x})}, \\
    \text{Track}({\bf x}) & = (0.9)^t\,{10000 \, \textbf{M}(p_x,p_y)} , \\
    \text{Speed}({\bf x}) & = (v_x - v_{ref})^2 , \\
    \text{Slip}({\bf x}) & = \sigma^2 + 10000I \, (\{\left | \sigma \right | > 0.2\}) ,
\end{aligned}
\end{equation}
where $I$ is an indicator function. $\textbf{M}(p_x,p_y)$ in track cost is the two-dimensional cost map value at the global position $(p_x, p_y)$. Thanks to the sampling-based derivation of SMPPI, we can provide an impulse-like penalty in the cost function. The speed cost is a simple quadratic cost to achieve the reference vehicle speed $v_{ref}$. The slip cost imposes both soft and hard costs to discourage slip angle in the trajectory $( \sigma = -\text{arctan}  ( \frac{v_y}{\lVert v_x \rVert} ) )$. The trajectory expected to have a slip angle greater than $0.2$ rad (approximately $11.46 \, ^{\circ}$) will be penalized since it has the potential to make the vehicle unstable.

For SMPPI, the number of parallel samples was $10000$ and the number of time steps was $35$. For TOAST, the control parameters were set as follows:
\begin{equation}
\begin{aligned}
{\bf Q} &= \text{Diag}
\begin{pmatrix}
5, & 5, & 0.01, & 0.05, & 0.05, & 0.025
\end{pmatrix}, \\
{\bf R} &= \text{Diag}
\begin{pmatrix}
0.4, & 0.1
\end{pmatrix} .
\end{aligned}
\end{equation}

\begin{figure}[t]
\centering
\includegraphics[width=0.99\linewidth]{Figures/gain_plot.pdf}
\caption{Visualization of the time-varying feedback gains with different controllers while they are driving the same section. (a) ``Low Gain", (b) ``High Gain", and (c) TOAST. For clarity, only the gains corresponding to the steering angle are visualized. We applied rotation on the hand-tuned gains of $p_x$ and $p_y$ from global to vehicle coordinate frame. TOAST adaptively changes the gains according to the time-varying dynamic characteristics of the system.}
\label{fig:gain_plot}
\end{figure}
\begin{figure}[t]
\centering
\includegraphics[width=0.95\linewidth]{Figures/trajectory.pdf}
\caption{Vehicle trajectories of the compared controllers. The friction coefficient of \textit{Corner \#2} (in gray) is 0.60 and \textit{Corner \#3} (in brown) is 0.65.}
\label{fig:trajectory_compare}
\end{figure}

\subsubsection{Experimental Results\label{subsubsection:result}}
We evaluated the control performance of the four controllers on the race track. The goal of the controllers was to complete whole laps in a clockwise direction.

The race track was adjusted to be more challenging to drive than it was when the training dataset was collected. The friction coefficients $\mu$ were modified to have values of $[0.55, 0.60, 0.65, 0.70, 0.75, 0.80]$ at the corners, respectively, and to have a default of $1.0$. During ten laps around the course, we measured average lap times on the six corners at a reference speed of $40$ km/h. When the vehicle left the track, it was placed at the starting point and started a new lap. All of the methods used the same pre-trained model and no further training was given throughout the experiments. The results are shown in Table~\ref{table:time_took}.

\begin{table}[ht]
\renewcommand\arraystretch{1.2}
\captionsetup{justification=centering}
\caption{Average lap times on the six corners of different control methods. The minimum speed (in [km/h]) and maximum slip angle (in [$^{\circ}$]) at each corner are also analyzed with our method. The success rates (SR) are also displayed.}
\label{table:time_took}
\begin{center}
\begin{tabular}{c|cccccc|c}
Lap time [s] & \#1 & \#2 & \#3 & \#4 & \#5 & \#6 & SR \\\hline
No Feedback      & 7.8 & 9.4 & 12.2 & 8.7 & 7.0 & 11.9  & 1/10   \\
Low Gain & 7.9 & 8.9 & 12.2 & 8.9 & 6.9 & 12.2  & 3/10  \\
High Gain      & 8.3 & 8.7 & 12.2 & 10.0 & 7.6 & 13.6  & 10/10  \\
\rowcolor{gray!50} TOAST     & 7.7 & 7.8 & 11.8 & 9.5 & 8.3 & 9.4  & 10/10  \\  \hline \hline
\rowcolor{gray!50} Min. Speed      & 33.2 & 24.4 & 22.6 & 33.5 & 26.7 & 26.7  &  \\
\rowcolor{gray!50} Max. Slip      & 3.4 & 7.2 & 6.8 & 2.8 & 7.4 & 4.2  &  \\
\end{tabular}
\end{center}
\vspace*{-0.1in}
\end{table}

``No Feedback" and ``Low Gain" barely got through \textit{Corner \#2} and \textit{Corner \#3}, which are the most challenging sections of the track. They completed the full course with only one and three out of ten laps, respectively. The learned dynamics predicted that the vehicle would slide greatly if it did not slow down due to the low friction surfaces. Therefore, SMPPI generated trajectories that applied brakes first, then steered the vehicle and slowly accelerated it to pass the corners. However, the vehicle failed to follow the planned trajectory and understeering occurred due to model uncertainty. In contrast, ``High Gain" and ``TOAST" completed entire laps in $100\%$ of the trials. However, the results show that TOAST has a faster lap time than ``High Gain" in most cases. This is because if the feedback controller keeps a fixed high gain all the time, it frequently interferes with the control sequence of the MPC and thus loses the optimality of the solution. Our controller computes the optimal feedback gain for each optimal control sequence based on the contextual information encoded in the neural network dynamics. As a result, a low gain can be maintained in situations where feedback compensation is not greatly required. We show the time-varying feedback gains of the compared controllers in Fig.~\ref{fig:gain_plot}. For TOAST, the overall average speed during ten laps was $33.4$ km/h and the maximum slip angle was $7.4 \, ^{\circ}$. We visualize the vehicle trajectories on \textit{Corner \#2} and \textit{Corner \#3} in Fig.~\ref{fig:trajectory_compare}.

\begin{wrapfigure}{R}{0.5\linewidth}
\centering
\includegraphics[width=0.99\linewidth]{Figures/du.pdf}
\caption{Derivative action for each control variable. They are quantified by the L2 norm.}
\label{fig:du}
\end{wrapfigure}

We also analyzed the degree of chattering on control values with ``High Gain" and TOAST. It is a well-known fact that rapid changes in the action commands are a burden to the actuators. In the straight sections of the track with high friction coefficients, the vehicle is stable and the requirement for a feedback controller becomes negligible. Therefore, we analyzed the derivative actions during $10$ laps excluding the corners. The results are shown in Fig.~\ref{fig:du}. For ``High Gain", the average derivative actions of the steering angle ($\delta$) and the desired speed ($v_{des}$) were $1.31$, and $0.81$, respectively. On the other hand, those of TOAST were $0.96$ and $0.46$. The results demonstrate that the adaptive manner of our proposed method can alleviate chattering.

\section{INTRODUCTION}
\input{_I.Introduction/intro}
\section{METHODOLOGY}
\input{_II.Methodology/_intro}
\subsection{Smooth Model Predictive Path Integral Controller}
\input{_II.Methodology/a_mppi}
\subsection{Designing a Simultaneous Optimal Tracking Controller}
\input{_II.Methodology/b_lqr}
\subsection{Trajectory Optimization and Simultaneous Tracking}
\input{_II.Methodology/c_toast}
\subsection{Extension to an Aggressive Autonomous Driving Task \label{subsection:extension}}
\input{_II.Methodology/d_extension}
\section{EXPERIMENTS}
\input{_III.Experiments/_intro}
\subsection{Pendulum}
\input{_III.Experiments/a_pendulum}
\subsection{Cartpole}
\input{_III.Experiments/b_cartpole}
\subsection{Aggressive Autonomous Driving}
\input{_III.Experiments/c_carmaker}
\section{CONCLUSION}
\input{_IV.Conclusion/conclusion}

\bibliographystyle{IEEEtran}
\typeout{}


\section{Introduction} \label{sec:intro}

\subsection{A brief history of Mendelian
  randomization} \label{sec:intro:historyofmr}

Mendelian randomization (MR) is a causal inference approach that uses the
random allocation of genes from parents to offspring as a foundation
for causal inference \parencite{Sanderson2022}. The ideas behind MR can be traced
back to the intertwined beginning of modern statistics and genetics
about a century ago. In one of the earliest examples, \textcite{Wright1920} used
selective inbreeding of guinea pigs to investigate the causes of
colour variation and, in particular, the relative contribution of
heredity and environment. In a later defence of this work,
\textcite[p.\ 251]{Wright1923} argued that his analysis of path
coefficients, a precursor to modern causal graphical models, ``rests
on the validity of the premises, i.e., on the evidence for Mendelian
heridity'', and the ``universality'' of Mendelian laws justifies
ascribing a causal interpretation to his findings.

At around the same time, \textcite{fisher26_arran_field_exper} started
to contemplate the randomization principle in experimental design and
used it to justify his analysis of variance (ANOVA) procedure, which was
motivated by genetic problems. In fact, the term ``variance'' first
appeared in Fisher's groundbreaking paper that bridged Darwin's
theory of evolution and Mendel's theory of genetic inheritance
\parencite{fisher19_correlation}. \textcite{Fisher1935} described
randomization as the ``reasoned basis'' (p.\ 12) for inference and
``the physical basis of the validity of the
test'' (p.\ 17). Later, it was revealed that his
factorial method of experimentation derives ``its structure and its
name from the simultaneous inheritance of Mendelian factors''
\parencite[p. 330]{Fisher1951}. Indeed,
Fisher viewed randomness in meiosis as uniquely shielding geneticists from the
difficulties of establishing reliably controlled comparisons,
remarking that ``the different genotypes possible from the same mating
have been beautifully randomized by the meiotic process''
\parencite[p. 332]{Fisher1951}.

While this source of randomization was originally used for eliciting
genetic causes of phenotypic variation, it was later identified as a
possible avenue for understanding causation among modifiable
phenotypes
themselves \parencite{DaveySmith2006}. \textcite{lower79_n_acety_phenot_risk_urinar_bladd_cancer}
used N-acetylation, a phenotype of known genetic regulation and a
component of detoxification pathways for arylamine, to strengthen the
inference that arylamine exposure causes bladder
cancer. \textcite{Katan2004a} proposed to address
reverse causation in the hypothesized effect of low serum cholesterol
on cancer risk via polymorphisms in the apolipoprotein E
(\textit{APOE}) gene. He argued that, if low cholesterol was indeed a
risk factor for cancer, we would expect to see higher rates of cancer
in individuals with the low cholesterol allele. Another pioneering
application of this reasoning can be found in a proposed study of the
effectiveness of bone marrow transplantation relative to chemotherapy \parencite{Gray1991}, for example, in the treatment of acute myeloid leukaemia \parencite{Wheatley2004}. Patients with a compatible
donor sibling were more likely to receive transplantation than
patients without. Since compatibility is a consequence of random
genetic assortment, comparing survival outcomes between the two groups
can be viewed as akin to an intention-to-treat analysis in a
randomized controlled trial. This paper appears to be the first to
use the term ``Mendelian randomization''.

It would be a dozen more years before an argument for the broader applicability of MR was put forward by \textcite{DaveySmith2003}. At the time, a number of criticisms had been levelled against the state of observational epidemiology and its methods of inquiry \parencite{Feinstein1988, Taubes1995, DaveySmith2001}. Several high profile results failed to be corroborated by subsequent randomized controlled trials, such as the role of beta-carotene consumption in lowering risk of cardiovascular
disease, with unobserved confounding identified as the likely culprit \parencite[p.\ 329-330]{DaveySmith2001}. This string of failures motivated the development of a more rigorous observational design with an explicit source of unconfounded randomization in the exposures of interest \parencite{DaveySmith2020}.

Originally, \textcite{DaveySmith2003} recognized that MR is best justified in a within-family design with parent-offspring trios. MR is commonly described as being analogous to a randomized controlled trial with non-compliance. This analogy is based on exact randomization in the transmission of alleles from parents to offspring which can be viewed as a form of treatment assignment. From its inception, it was recognized that data limitations would largely restrict MR to be performed in samples of unrelated individuals, which \cite{DaveySmith2003} termed ``approximate MR''. Such approximate MR has been the norm, seen in the majority of applied and methodological studies to date. However, MR in unrelated individuals lacks the explicit source of randomization offered by the within-family design, thereby suffering potential biases from dynastic effects, population structure and assortative mating \parencite{Davies2019, Brumpton2020, Howe2022}.

In addition to random assignment of exposure-modifying genetic
variants, we must also assume that the effects of these genetic
variants on the outcome are fully mediated by the exposure, known as
the exclusion restriction. When this assumption holds, MR can be
framed as a special case of instrumental variable analysis
\parencite{Thomas2004, Didelez2007a}. Within this framework, there has
been considerable recent methodological work to replace the exclusion
restriction with more plausible assumptions, typically by placing
structure on the sparsity \parencite{kang16_instr_variab_estim_with_some} or distribution of pleiotropic
effects across individual genetic variants \parencite{Bowden2015,
  Zhao2020,kolesar15_ident_infer_with_many_inval_instr}.

\subsection{Towards an almost exact inference for MR} \label{sec:intro:ourtest}

As parent-offspring trio data becomes more widely available, it is
increasingly feasible to perform MR within families, as originally intended. There has been
some recent methodological and applied development for within-family designs
\parencite{Davies2019, Brumpton2020}. Thus far this has consisted of
extensions of traditional MR techniques in which structural models for
the gene-exposure and gene-outcome relationships are proposed and
samples are assumed to be drawn according to these models from some
large population. In particular, \textcite{Brumpton2020} propose a
linear regression model with parental genotype fixed effects. Their
inference is based on this model and so the role of meiotic
randomization is only implicit.

However, one of the unique advantages of MR as an observational design
is that it has an explicit inferential basis, randomness in meiosis and fertilization,
which has been thoroughly studied and modelled in genetics since
\textcite{Haldane1919}. Haldane developed a simple model for
recombination during meiosis that has demonstrated good performance on multiple
pedigrees across many species. The connection between this meiosis
model and causal inference in parent-offspring trio studies was
recently described in the context of identifying causal genetic
variants \parencite{Bates2020a} and was implicit in earlier genetic
linkage analysis \parencite{morton1955sequential} and the transmission
disequilibrium test \parencite{Spielman1993}. \textcite{Lauritzen2003}
attempted to represent meiosis models using graphs; however, they were
concerned with computatational advantages of graphical models and did
not consider their potential for causal inference.

The idea of exact hypothesis testing dates back to Fisher's original
proposal for randomized experiments and is well illustrated in his
famous `lady tasting tea' example
\parencite{Fisher1935}. \textcite{pitman37_signif_tests_which_may_be}
appears to be the first to fully embraced the idea of randomization
testing. This mode of reasoning is
usually referred to as randomization inference or design-based
inference to contrast with model-based inference. With the aid of the
potential outcome framework \parencite{Neyman1923,Rubin1974}, we can
construct an exact randomization test for the sharp null hypothesis by
conditioning on all the potential outcomes
\parencite{Rubin1980,Rosenbaum1983}. Randomization tests are widely
used in a variety of settings, including genetics
\parencite{Spielman1993,Bates2020a}, clinical trials
\parencite{Rosenberger2019}, program evaluation
\parencite{Heckman2019} and instrumental variable analysis
\parencite{Rosenbaum2004, Kang2018}.

\subsection{Our contributions}
\label{sec:our-contribution}

In this article, we propose a statistical framework that enables us to
use meiosis models as the ``reasoned basis'' for inference in MR by
unifying several ideas mentioned above. The randomization test we
propose is \emph{almost exact} in the sense that the test has exactly
the nominal size if the meiosis and fertilization model is correct.

Our first contribution is a theoretical
description of MR (and the assumptions therein) via the language of
causal directed acyclic graphs (DAGs) \parencite{Pearl2009}. These
graphical tools allow us to visualize and dissect the assumptions imposed
on the biological processes involved in heredity. In particular, we
show how various biological and social processes, including population
stratification, gamete formation, fertilization, genetic linkage,
assortative mating, dynastic effects, and pleiotropy, can be
represented using a DAG and how they can introduce bias in MR
analyses. Furthermore, by using single world intervention graphs
(SWIGs) \parencite{Richardson2013b}, we identify sufficient confounder
adjustment sets to eliminate these sources of bias. Our results
provide important theoretical insights into a trade-off between
reducing pleiotropy-induced bias and increasing statistical power.

For statistical inference, we propose a randomization test by
connecting two existing literatures. The first literature concerns
randomization inference for instrumental variable analyses, which
usually assumes that the instrumental variables are randomized
according to a simple design (such as random sampling of a binary
instrument without replacement) \parencite{Rosenbaum1983,
  Kang2018}. However, in MR, offspring genotypes are very
high-dimensional and are randomized based on the parental
haplotypes. The second literature attempts to identify the approximate
location of (``map'') causal genetic variants by modelling the meiotic
process \parencite{morton1955sequential,Spielman1993,Bates2020a}. %
We show how the hidden Markov model for meiosis and fertilization implied by
\textcite{Haldane1919} greatly simplifies the sufficient adjustment
sets and computation of the randomization test. In essence, our
proposal extends existing randomization inference techniques for
instrumental variables to allow testing based on biological randomness
in reproduction (i.e.\ Mendelian randomization).

In addition to the considerable conceptual advantages, our almost
exact MR approach has several practical advantages too. First, unlike
model-based approaches for within-family MR \parencite{Brumpton2020},
our approach does not rely on a correctly specified phenotype
model. Nonetheless, the randomization test can take advantage of an
accurate phenotype model to dramatically improve its
power. Furthermore, the hidden Markov model based on Haldane's original formulation implies a propensity
score for each instrument given a sufficient adjustment set
\parencite{Rosenbaum1983}. This can be used as a ``clever covariate''
\parencite{Rose2008} to build powerful test statistics with attractive
 robustness properties. Second,
since the randomization test is exact, it is robust to arbitrarily
weak instruments. For an ``irrelevant'' instrument which induces no
variation in the exposure, the test will simply have no
power. Finally, by taking advantage of the DAG representation and
using a sufficient confounder adjustment set, our method is also
provably robust to biases arising from population structure (including
multi-ethnic samples), assortative mating, dynastic effects and
pleiotropy by linkage.

We demonstrate these advantages with a simulation study and real data example in the Avon Longitudinal Study of Parents and Children (ALSPAC). The simulation study first confirms that our almost exact test produces uniformly-distributed p-values under the null and then explores the power of the test in a number of scenarios. The applied examples consists of a negative control and a positive control. The negative control is the effect of child's body mass index (BMI) at age 7 on mother's BMI pre-pregnancy. Although a causal effect is temporally impossible, backdoor paths could exist to produce a false rejection of the null. We provide evidence that our almost exact test closes these paths. The positive control is the effect of child's BMI on itself plus some zero-mean noise. We also compare our results with the results from a ``typical'' MR analysis unconditional on any parental or offspring haplotypes.

\section{Background} \label{sec:background}

\subsection{Causal inference preliminaries} \label{sec:causal-inference}

This section lays out some standard notation and assumptions in causal inference. Readers looking for an introduction to causal inference concepts, including causal graphical models, single world intervention graphs, randomization inference, and instrumental variables, can consult \Cref{sec:intro-to-causal-inference}. We express our causal assumptions and model via causal graphs, then demonstrate that randomization inference for instrumental variables is a natural vehicle for inference in within-family MR. As such, a good grasp of these concepts is required to understand the remainder of the article.

Suppose we have a collection of $N$ individuals indexed by $i = 1, 2, \ldots, N$ and, among these individuals, we are interested in the effect of an exposure $D_i$ on an outcome $Y_i$. For example, the exposure could be the level of alcohol consumption over some period of time and the outcome could be the resulting incidence of cardiovascular disease. Individual $i$'s \emph{potential outcomes} (also called \emph{counterfactuals}) corresponding to exposure level $D_i = d$ are given by $Y_i(d)$. The collection of potential outcomes for the sample is given by $\mathcal{F} = \{ (Y_i(0), Y_i(1)) \colon i = 1, 2, \ldots, N \}$.

We make the \emph{no interference} assumption which posits that the potential outcomes of each individual are unaffected by the exposures of other individuals \parencite{Rubin1980, Imbens2015}, such that $Y_i(d) \perp\mkern-9.5mu\perp D_j$ for all $i \neq j$ and $d$ in the support of $D_i$. We also assume \emph{no hidden versions of the same treatment}. A violation of this assumption could occur if $D_i \in \{0, 1\}$ were a binary measure indicating abstinence ($D_i = 0$) or some alcohol consumption ($D_i = 1$). The effect of alcohol consumption on cardiovascular disease is likely to exhibit a dose-response relationship, meaning that the potential outcome $Y_i(1)$ is not well-defined since it could take multiple distinct values depending on the unobserved amount of consumption. The previous two assumptions are sometimes jointly referred to as the \emph{stable unit treatment value assumption} \parencite{Rubin1980}. We also make the \emph{consistency} assumption \parencite{Hernan2020} which states that the observed outcome corresponds to the potential outcome at the realized exposure level $Y_i = Y_i(D_i)$.

\subsection{Genetic preliminaries} \label{sec:genetic-preliminaries}

Before we proceed, it is instructive to provide a basic overview of the relevant concepts in genetics, with a focus on modelling the processes involved in genetic inheritance, namely \emph{meiosis} and \emph{fertilization}. For a thorough exposition on statistical models for meiosis and pedigree data, see \textcite{Thompson2000}.

Human somatic cells consist of 23 pairs of chromosomes, with one in each pair inherited from the mother and the other from the father. Each chromosome is a doubled strand of helical DNA comprised of complementary nucleotide base pairs. A base pair which exhibits population-level variation in its nucleotides is called a \emph{single nucleotide polymorphism} (SNP). DNA sequences are typically characterized by the detectable variant forms induced by different combinations of SNPs. These variant forms are called \emph{alleles}. In this article, we will only consider variants with two alleles. A set of alleles on one chromosome inherited together from the same parent is called a \emph{haplotype} \parencite{Bates2020a} and the two haplotypes forming a homologous pair of chromosomes is called a \emph{genotype}.

Meiosis is a type of cell division that results in reproductive cells containing one copy of each chromosome. During this process, homologous chromosomes line up and exchange segments of DNA between themselves in a biochemical process called \emph{crossover}. The recombined chromosomes are then further divided and separated into gametes. Since recombinations are infrequent (roughly one to four per chromosome in most eukaryotes) SNPs located nearby on the same parental chromosome are more likely to be transmitted together, which results in \emph{genetic linkage}. Fertilization is the process by which germ cells in the father (sperm cells) and mother (egg cells) join together to form a zygote, which will normally develop into an embryo.

In genetic trio studies we observe the haplotypes of the mother, father and their child at $p$ SNPs on a single chromosome, where $\mathcal{J} = \{ 1, 2, \ldots , p \}$ is the set of SNP indices. We will denote the haplotypes as follows:
\[ \begin{array}{lll}%
     \text{Individual's haplotypes:} & \bm{Z}^m = (Z_1^m, \ldots, Z_p^m) \in \{ 0, 1 \}^p, & \bm{Z}^f = (Z_1^f, \ldots, Z_p^f) \in \{ 0, 1 \}^p; \\[0.3em]
     \text{Mother's haplotypes:} & \bm{M}^m = (M_1^m, \ldots, M_p^m) \in \{ 0, 1 \}^p, & \bm{M}^f = (M_1^f, \ldots, M_p^f) \in \{ 0, 1 \}^p; \\[0.3em]
     \text{Father's haplotypes:} & \bm{F}^m = (F_1^m, \ldots, F_p^m) \in \{ 0, 1 \}^p, & \bm{F}^f = (F_1^f, \ldots, F_p^f) \in \{ 0, 1 \}^p,
   \end{array}\]%
 where the superscript $m$ (or $f$) indicates a maternally (or
 paternally) inherited haplotype. Furthermore, denote $\bm{M}_j^{mf} =
 (M_j^m, M_j^f)$ as the mother's haplotypes at site $j$ and similarly
 for $\bm{F}_j^{mf}$ and $\bm{Z}_j^{mf}$.
 The offspring's genotype
 at site $j \in \mathcal{J}$ is given by $Z_j = Z_j^m + Z_j^f$ and let
 $\bm{Z} = \bm{Z}^m + \bm{Z}^f \in \{ 0, 1, 2 \}^p$ denote the vector
 of offspring genotypes.

 \begin{figure}[t]
   \begin{center}
     \caption{Illustration of the meiotic process for five sites on a chromosome.}
     \includegraphics[scale=1.25]{recombination.pdf}
     \label{fig:recombination}
   \end{center}
 \end{figure}

 \Cref{fig:recombination} illustrates how an offspring's maternally-inherited haplotype $\bm{Z}^m$ at five sites on a chromosome are related to the mother's haplotypes
 $\bm{M}^m$ and $\bm{M}^f$. At site $j \in \mathcal{J}$ in a gamete produced by meiosis, the allele is inherited from either the mother's $m$ haplotype or $f$ haplotype (ignoring mutations). This can be formalized as an ancestry  indicator, $U_j^m \in \{m,f\}$. The classical meiosis model of \textcite{Haldane1919} assumes that  $\bm U^m = (U_1^m,\dotsc,U_p^m)$ follows a homogeneous Poisson process. Haldane's model is described in \Cref{sec:randomization-distribution} in detail and can simplify our method considerably (\Cref{subsec:hmm-simplification}). Nonetheless, our ``almost exact'' MR framework is modular and does not rely on a specific meiosis model. In fact, it is theoretically straightforward to incorporate more sophisticated meiosis models that allow for ``interference'' between the crossovers \parencite{Otto2019}. As the meiosis model become more accurate, our test will become closer to exact randomization inference.

 The description in the last paragraph does not take genetic mutation into account. Many meiosis models assume that there is a small probability of independent mutations. This is formalized in the next assumption.
 \begin{assumption}[Haldane's model] \label{assum:de-novo-distribution}
   Given that $U_j^m = u_j^m \in \{m, f\}$ and fertilization occurs
   (this is represented as $S=1$ in \Cref{sec:exacttest}),  each
   $Z_j^m$ is equal to $M_j^{(u_j^m)}$ unless an independent mutation
   occurs. More specifically,
   \[
     Z_j^m = \begin{cases}
       M_j^{(u_j^m)} & \text{with probability $1 - \epsilon$} \\
       1-M_j^{(u_j^m)} & \text{with probability $\epsilon$.}
     \end{cases}
   \]
   The same model holds for the paternally-inherited haplotypes.
 \end{assumption}
 The rate of \emph{de novo} mutation $\epsilon$ is about $10^{-8}$ in
 humans \parencite{Acuna-Hidalgo2016}. Unless it is necessary to
 compute the exact randomization distribution under a recombination
 model, for practical purposes it often suffices to treat $\epsilon =
 0$ (i.e., no mutations).
 %
 %
 %

This meiosis model assumes the absence of \emph{transmission ratio distortion}. Transmission ratio distortion occurs when one of the two parental alleles is passed on to the (surviving) offspring at more or less than the expected Mendelian rate of 50\%. Transmission ratio distortion falls into two categories: segregation distortion, when processes during meiosis or fertilization select certain alleles more frequently than others, and viability selection, when the viability of zygotes themselves depend on the offspring genotype \parencite{Davies2019}. While we sidestep this discussion for now, we return to it in \Cref{sec:discussion}.

 \section{Almost exact Mendelian randomization} \label{sec:exacttest}

 \subsection{A causal model for Mendelian inheritance}
 \label{sec:setup}

Returning to the alcohol and cardiovascular disease example in \Cref{sec:causal-inference}, observational studies suggest that moderate alcohol consumption confers reduced risk relative to abstinence or heavy consumption \parencite{Millwood2019}. This could indicate systematic differences among people with different drinking patterns (confounding) rather than a causal effect. There is a genetic variant in the \emph{ALDH2} gene which regulates acetaldehyde metabolism. In some populations, an allele of \emph{ALDH2} produces a protein that is inactive in metabolising acetaldehyde, causing discomfort while drinking and thereby reducing consumption. We might like to use the random allocation of variant copies of \emph{ALDH2} during meiosis and fertilization to make causal inference about the downstream effect of alcohol consumption on cardiovascular disease, however, we need to carefully clarify the conditions under which this inference would be valid. To this end, we construct a very general causal model in this section to describe the process of Mendelian inheritance and genotype-phenotype relationships. This causal model allows us to identify sources of bias in within-family MR and construct sufficient adjustment sets to control for them.

Under this causal model, the central idea behind almost exact MR is to base statistical inference precisely on randomness in genetic inheritance via a model for meiosis and fertilization. Technically speaking, we would like to apply the randomization test described in \Cref{sec:rand-infer} to MR.

 \begin{figure}[htp]
   \begin{center}
     \includegraphics[scale=0.95]{images/fammr_dag.pdf}
     \caption{The single world intervention graph for a working
       example of a chromosome with $p = 3$ variants. Transparent
       nodes are observed and grey nodes are unobserved. Square nodes
       are the confounders being conditioned on in
       \Cref{prop:example-adjustment-set}. $A$ is ancestry; $\bm M^f =
       (M_1^f,M_2^f,M_3^f)$ is the mother's haplotype inherited from
       her father; $\bm M^m,\bm F^m$, and $\bm F^f$ are defined
       similarly; $C^m$ and $C^f$ are generic phenotypes of the mother
       and father; $S$ is an indicator of mating; $\bm Z^m =
       (Z_1^m,Z_2^m,Z_3^m)$ is the offspring's maternal haplotype and
       $\bm U^m$ is a meiosis indicator; $\bm Z^f$ and $\bm U^f$ are
       defined simlarly; $\bm Z = (Z_1,Z_2,Z_3)$ is the offspring's
       genotype; $D$ is the exposure of interest; $Y(d)$ is the
       potential outcome of $Y$ under the intervention that sets $D$
       to $d$; $C$ is an environmental confounder between $D$ and
       $Y$.}
     \label{fig:fammr_dag}
   \end{center}
 \end{figure}

 \Cref{fig:fammr_dag} shows a working example of our causal model
 on a chromosome with just $p=3$ variants. The directed acyclic graph
 is structured in roughly chronological order from left to right,
 where $A$ describes the population structure, $S$ is an indicator for
 mating, and $C$ is any environmental confounder between the exposure
 $D$ and outcome $Y$. %

 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %
 %

 At first glance, \Cref{fig:fammr_dag} appears to be quite complicated
 but, by the modularity of graphical models, it can be
 decomposed into a collection of much simpler subgraphs that describe different
 biological processes (\Cref{fig:subgraphs}). By
 definition, a joint distribution \emph{factorizes} according to the
 DAG in \Cref{fig:fammr_dag} if its density function can be decomposed
 as (let $f$ be a generic symbol for density function)
 \begin{align*}
   %
   %
     & f(\text{all variables}) & \\
   =& f(A) f(\bm U^m) f(\bm U^f) f(C)   &\text{(Exogenous variables)} \\ &  f(\bm M^m, \bm M^f, \bm F^m, \bm F^f \mid A) & \text{(Population stratification, \Cref{sec:parental-genotypes})}
   \\ & f(C^m \mid A, \bm M^m, \bm M^f) f(C^f \mid A, \bm F^m, \bm F^f) &\text{(Parental phenotypes, \Cref{sec:parental-phenotypes})} \\ & f(\bm Z^m \mid \bm M^m, \bm M^f, \bm U^m) f(\bm Z^f \mid \bm F^m, \bm F^f, \bm U^f) & \text{(Meiosis, \Cref{sec:offspring-genotypes})} \\
     & f(S \mid C^m, C^f)  &\text{(Assortative mating, \Cref{sec:offspring-genotypes})} \\
     & f(\bm Z \mid \bm Z^m, \bm Z^f, S) & \text{(Fertilization, \Cref{sec:offspring-genotypes})} \\ & f(D \mid  A, \bm Z, C^m, C^f, C) f(Y(d) \mid A, \bm Z, C^m, C^f, C) & \text{(Offspring phenotypes, dynastic effects,} \\ & & \text{ confounding, \Cref{sec:offspring-phenotypes})}
 \end{align*}

Next, we describe each term on the right hand side above and its
corresponding subgraph and biological process. To simplify the
discussion, we assume all DAGs in this article are faithful, so
conditional independence between random variables is equivalent to
d-separation in the DAG.

\begin{figure}[htp]
\centering
\begin{subfigure}[b]{0.22\textwidth}
 \centering
 \includegraphics[width=\textwidth]{images/population_stratification.pdf}
 \caption{Population structure (\Cref{sec:parental-genotypes}).}
 \label{fig:parental-genotypes}
\end{subfigure}

\par\bigskip

\begin{subfigure}[b]{0.6\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/meiosis_dag.pdf}
     \caption{Meiotic recombination of the mother's haplotypes (\Cref{sec:genetic-preliminaries}).}
     \label{fig:meiosis_dag}
    \end{subfigure}

    \par\bigskip

    \begin{subfigure}[b]{0.275\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/assortative_mating.pdf}
     \caption{Assortative mating (\Cref{sec:offspring-genotypes}).}
     \label{fig:assortative-mating}
    \end{subfigure}
    \par\bigskip

    \begin{subfigure}[b]{0.29\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/offspring_phenotypes.pdf}
     \caption{Offspring phenotypes. (\Cref{sec:offspring-phenotypes}).}
     \label{fig:offspring-phenotypes}
    \end{subfigure}
    \hspace{15mm}
    \begin{subfigure}[b]{0.42\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/dynastic_effects.pdf}
     \caption{Dynastic effects (\Cref{sec:parental-phenotypes}).}
     \label{fig:dynasticeffects}
    \end{subfigure}%
    \caption{The constituent subgraphs of our within-family Mendelian
     randomization model. White nodes represent observed variables;
     grey nodes represent unobserved variables; and striped nodes
     represent variables for which some elements may be unobserved.}
   \label{fig:subgraphs}
\end{figure}

\subsubsection{Parental genotypes} \label{sec:parental-genotypes}

We assume that parental genotypes originate from some arbitrary, latent
population structure. Population stratification is a phenomenon characterized by systematic differences in the distribution of alleles among subgroups of a population. These disparities
typically emerge from social and genetic mechanisms including
non-random mating, migration patterns and `founder effects'
\parencite{Cardon2003} and can often be detected by principal
component analysis \parencite{patterson06_popul_struc_eigen}. This
can introduce spurious associations between genetic variants and
traits \parencite{Lander1994}.

We represent population structure via the node $A$ in the subgraph in
\Cref{fig:parental-genotypes}. The arrows from $A$ to $\bm{M}^m,
\bm{M}^f$ and $\bm{F}^m, \bm{F}^f$ indicate that the distribution of
parental haplotypes depends on the latent population structure. This
is formalized in the assumption below. \begin{assumption}
\label{assum:parental-genotypes}
The parental haplotypes $\bm M^m$, $\bm M^f$, $\bm F^m$, and $\bm F^f$
depend on the latent population structure $A$, so
\[
 A \centernot{\independent} (\bm M^m, \bm M^f, \bm F^m, \bm F^f).
\]
\end{assumption}

The node $A$ may also capture any linkage disequilibrium in the
parental haplotypes. That is, because the parental haplotypes are
determined by the same process as the grandparental haplotypes and
so on, recombination introduces dependence among nearby genetic
variants. The distribution of $A$ and the distribution of the parental
haplotypes given $A$ are not important below, because an appropriate
subset of the parental haplotypes will be conditioned on and the paths
from $A$ to $\bm M^m$, $\bm M^f$, $\bm F^m$, and $\bm F^f$ will be blocked.

\subsubsection{Parental phenotypes} \label{sec:parental-phenotypes}

We impose no assumptions on the nature and the distribution of the parental
phenotypes $C^m$ and $C^f$. They can depend arbitrarily on the
parental haplotypes $\bm{M}^m, \bm{M}^f, \bm{F}^m, \bm{F}^f$ and the
population structure $A$, once again because our proposal for almost
exact MR conditions on the parental haplotypes.

\begin{assumption} \label{assum:parental-phenotypes}
The parental phenotypes $C^m$ and $C^f$ are descendants of the
latent population structure $A$ and the corresponding parental
haplotypes (i.e. $(\bm M^m,\bm M^f)$ for $C^m$ and $(\bm F^m,\bm
F^f)$ for $C^f$). In other words, we allow the following dependence:
\[
 C^m \centernot{\independent} (A, \bm{M}^m, \bm{M}^f),~
 C^f \centernot{\independent} (A, \bm{F}^m, \bm{F}^f).
\]%
\end{assumption}

\subsubsection{Offspring genotypes} \label{sec:offspring-genotypes}

There are two biological processes involved in the genesis of the
offspring's genotype: meiosis (gamete formation) and
fertilization. The meiotic process is briefly reviewed in
\Cref{sec:genetic-preliminaries}, and the key
\Cref{assum:de-novo-distribution} can be represented by the causal
diagram in \Cref{fig:meiosis_dag} (for the mother). A crucial
assumption underlying our almost
exact inference is the exogeneity of the meiosis indicators $\bm
U^m$ and $\bm U^f$. This is reflected in \Cref{fig:fammr_dag,fig:meiosis_dag} as $\bm
U^m$ and $\bm U^f$ have no parents and their only children are the
offspring's haplotypes. Formally, we assume:
\begin{assumption} \label{assum:meiosis-indicator-independence}
The meiosis indicators are independent of parental haplotypes and
phenotypes and any other confounders:
\[
 (\bm{U}^m, \bm{U}^f) \perp\mkern-9.5mu\perp (A, C^m, C^f, C, \bm{M}^m, \bm{M}^f, \bm{F}^m, \bm{F}^f).
\]%
\end{assumption}

Many different models have been proposed for the distribution of the
ancestry indicator $\bm U^m$;  see \textcite{Otto2019} for a recent
review. Due to the dependence in $\bm U^m$, nearby alleles on the same
chromosome tend to be inherited together. This phenomenon is known as
\emph{genetic linkage}. In \Cref{sec:genetic-preliminaries}, we describe
the classical model of \textcite{Haldane1919} which assumes $\bm
U^m$ follows a Poisson process. This model has been used by
\textcite{Bates2020a} to locate causal variants. We will see in
\Cref{subsec:hmm-simplification} that such Markovian structure
greatly simplifies randomization inference.

Another mechanism that needs to be modeled is fertilization. In
Mendelian inheritance, it is assumed that the potential gametes
(sperms and eggs) come together at random. However, mating may not be
a random event. \emph{Assortative mating} refers to the phenomenon
where individuals are more likely to mate if they have complementary
phenotypes. For example, there is evidence in UK Biobank that a SNP on the \emph{ADH1B} gene related to alcohol consumption is more likely to be shared among spouses relative to non-spouses \parencite{Howe2019}. This suggests assortative mating on
drinking behaviour and may introduce bias to MR studies on alcohol
consumption \parencite{Hartwig2018}. The subgraph describing assortative
mating is shown in \Cref{fig:assortative-mating}, where the mating
indicator $S \in \{0, 1\}$ is a common child of the parental phenotypes
$C^m$ and $C^f$ ($S = 1$ means mating).
In any MR study, we necessarily condition on $S = 1$, otherwise the
offspring would not exist. This is formalized in
\Cref{fig:assortative-mating} by the arrows from $S$ to $\bm{Z}$. In
particular, we may define the offspring's genotype $\bm Z$ as
\begin{align} \label{eqn:offspring-genotype-undefined}
\bm{Z} = \begin{cases}
 \bm{Z}^m + \bm{Z}^f, & \text{if $S = 1$},  \\
 \text{Undefined}, & \text{if $S = 0$.}
\end{cases}
\end{align}
Notice that the above definition recognizes the fact that the gametes
$\bm{Z}^m$ and $\bm{Z}^f$ are produced regardless of whether
fertilization actually takes place.

Our causal model implies that $\bm{Z}^m \perp\mkern-9.5mu\perp \bm{Z}^f \mid (\bm{M}^m, \bm{M}^f, \bm{F}^m, \bm{F}^f, S = 1)$, however, this is not necessarily a benign assumption. Indeed, there is empirical evidence that gametes may pair up non-randomly \parencite{Nadeau2017}, which could be represented by arrows from $\bm{Z}^m$ and $\bm{Z}^f$ to $S$. This is an example of transmission ratio distortion, which we discuss later in \Cref{sec:discussion}. For now, we simply note that we must assume the absence of this phenomenon.

\subsubsection{Offspring phenotypes} \label{sec:offspring-phenotypes}

Finally, we describe assumptions on the offspring phenotypes. We
are interested in estimating the causal effect of an offspring
phenotype $D \in \mathcal{D} \subseteq
\mathbb{R}$ on another offspring phenotype $Y  \in
\mathcal{Y} \subseteq \mathbb{R}$. We refer to $D$ as the exposure
variable and $Y$ as the outcome variable. These phenotypes are
determined by the offspring genotypes and environmental factors
(including parental traits). For a particular realization of the genotypes $\bm z$, we denote the counterfactual exposure as $D(\bm{z})$. Furthermore, under an additional intervention that sets
$D$ to $d$, we denote the counterfactual outcome as $Y(\bm{z},
d)$. These potential outcomes are related to the observed data tuple
$(\bm{Z}, D, Y)$ by
\[\begin{array}{ll}%
 D = D(\bm{Z}),~ %
 Y = Y(\bm{Z}, D) = Y(\bm{Z},D(\bm{Z})), %
\end{array}\]%
which is a simple extension of the consistency assumption
\eqref{eq:consistency} before.

We are interested in making inference about the counterfactuals $Y(d)
= Y(\bm{Z},d)$ when the exposure is set to $d \in \mathcal{D}$. As the
exposure $D$ typically varies according to population structure,
parental phenotypes and other environmental factors, it is not randomized.

\begin{assumption}
There may be unmeasured confounders between the exposure and outcome,
so that
\[
 Y(d) \centernot{\independent} D ~ \text{for some or all $d \in
   \mathcal{D}$}.
\]
\end{assumption}
For example, if $D$ is alcohol consumption and $Y$ is cardiovascular
disease, there may exist offspring confounders such as diet or smoking
habits which are common causes of both $D$ and $Y$. The exact nature
of the confunders is not very important as MR uses unconfounded
variation (in $\bm U^m$ and $\bm U^f$) to make causal inference.

It will be helpful to categorize the genetic variants based on whether
they have direct causal effects on $D$ and/or $Y$.

\begin{assumption} \label{assum:snp-subsets}
The set $\mathcal{J} = \{1, \ldots, p\}$ of genetic variants can be
paritioned as $\mathcal{J} = \mathcal{J}_y \cup \mathcal{J}_d \cup
\mathcal{J}_0$, where
\begin{itemize}
\item $\mathcal{J}_y$ includes all \emph{pleiotropic} variants with a direct causal
 effect on $Y$ (some of which may have a causal effect on $D$ as well).
\item $\mathcal{J}_d$ includes all causal variants for $D$ with no direct effect on $Y$.
\item $\mathcal{J}_0 = \mathcal{J} \setminus (\mathcal{J}_y \cup
  \mathcal{J}_d)$ includes all other variants.
\end{itemize}
\end{assumption}

In our working example in \Cref{fig:fammr_dag}, $\mathcal{J}_y =
\{3\}$, $\mathcal{J}_d = \{2\}$, and $\mathcal{J}_0 = \{1\}$. If the
exposure $D$ indeed has a causal effect on the outcome $Y$, the loci
of the causal variants of $Y$ are given by $\mathcal{J}_y \cup
\mathcal{J}_d$.

For subscripts $s \in \{ 0, d, y \}$, we let $\bm{Z}_s = \{
Z_j \colon j \in \mathcal{J}_s \}$ denote the corresponding genotypes,
which has support $\mathcal{Z}_s = \{ 0, 1, 2
\}^{|\mathcal{J}_s|}$. By \Cref{assum:snp-subsets}, our potential
outcomes can be written as (with an abuse of notation)
\[
D(\bm z) = D(\bm z_d),~Y(\bm z, d) = Y(\bm z_y, d),~Y(\bm z) =
Y(\bm z_y, D(\bm z_d)) = Y(\bm z_y, \bm z_d),
\]
where $\bm z = (\bm z_d, \bm z_y, \bm z_0) \in \mathcal{Z}_d \times \mathcal{Z}_y \times \mathcal{Z}_0 = \mathcal{Z}$ and $d \in \mathcal{D}$.

\Cref{fig:offspring-phenotypes} provides the graphical representation
of \Cref{assum:snp-subsets}. Each element of $\bm{Z}_0$ has no
effect on $D$ or $Y(d)$, each element of $\bm{Z}_d$ has an effect on
$D$ and each element of $\bm{Z}_y$ has an effect on $Y(d)$ (some are
also causes of $D$). The vector $\bm{Z}_y$ contains the so-called
pleiotropic variants that are causally involved in the
expression of multiple phenotypes \parencite{Hemani2018a}. The view that pleiotropy is widespread, if not
universal, is implied in Fisher's infinitesimal model
\parencite{fisher19_correlation} and supported by recent human
genetic studies \parencite{Boyle2017}.

\emph{Dynastic effects}, sometimes called \emph{genetic nurture} \parencite{Kong2018}, is a phenomenon characterized by parental phenotypes exerting a direct influence on the offspring's
phenotypes. This is depicted in
\Cref{fig:dynasticeffects}, where paths emanate from the
parental haplotypes $\bm M^m, \bm M^f$ and $\bm F^m, \bm
F^f$ to the parental phenotypes $C^m$ and $C^m$ and on to the
offspring phenotypes $D$ and $Y$.

\subsection{Conditions for identification}
\label{sec:identification}

With the causal model outlined in \Cref{sec:setup} in mind, we now
describe some sufficient conditions under which some $Z_j \in \bm Z$
is a valid instrumental variable for estimating the causal effect of
$D$ on $Y$. Recall that an instrumental
variable induces unconfounded variation in the exposure without otherwise
affecting the outcome. Due to population stratification
(\Cref{fig:parental-genotypes}), assortative mating
(\Cref{fig:assortative-mating}), and dynastic effects
(\Cref{fig:dynasticeffects}), the offpsring genotypes $\bm Z$ as a
whole are usually not properly randomized without conditioning on the
parental haplotypes. That is,
\[
\bm Z \not \perp\mkern-9.5mu\perp D(\bm z), Y(\bm z, d) ~ \text{for some or
 all $\bm z \in \mathcal{Z}$ and $d \in \mathcal{D}$.}
\]

To restore validity of genetic instruments, the key idea is to
condition on the parental haplotypes \parencite{Spielman1993, Bates2020a}. This allows us to
use precisely the exogenous randomness in the ancestry indicators $\bm
U^m$ and $\bm U^f$ that occurs during meiosis and fertilization. This idea is formalized in the next proposition.

\begin{proposition}
\label{prop:offspring-genotype-independence}
Under the causal graphical model described in \Cref{sec:setup},
the offspring's haplotype $Z_j^m$ (or genotype $Z_j$) at some site
$j \in \mathcal{J}$ is independent of all ancestral and offspring
confounders given the maternal (or parental) haplotypes at site $j$:
\begin{equation}
 \label{eq:zj-independence}
 \begin{split}
   &Z_j^m \perp\mkern-9.5mu\perp (A, C^m, C^f, C) \mid (M_j^m, M_j^f, S=1), \\
   &Z_j \perp\mkern-9.5mu\perp (A, C^m, C^f, C) \mid (M_j^m, M_j^f, F_j^m,
   F_j^f, S=1). \\
   %
 \end{split}
\end{equation}
\end{proposition}

However, the conditional independence \eqref{eq:zj-independence}
alone does not guarantee the validity of $Z_j$ as an instrumental
variable. The main issue is that $Z_j$ might be in linkage disequilibrium with other
causal variants of $Y$, as recognized by \textcite{Bates2020a} in the
context of mapping causal variants. Our goal is
to find a set of variables $\bm V$ such that $Z_j$ is conditionally
independent of the potential outcome $Y(d)$. This is formalized in
the definition below.
\begin{definition} \label{def:identification-conditions}
We say a genotype $Z_j$ is a \emph{valid instrumental variable} given $\bm V$ (for estimating the
causal effect of $D$ on $Y$) if the following conditions are
satisfied:
\begin{enumerate}
\item Relevance: $Z_j \not \perp\mkern-9.5mu\perp D \mid \bm V$;
\item Exogeneity: $Z_j \perp\mkern-9.5mu\perp Y(d) \mid \bm V ~ \text{for all
   $d \in \mathcal{D}$}$;
\item Exclusion restriction: $Y(z_j, d) = Y(d) ~ \text{for all
   $z_j \in \{0,1,2\}$ and $d \in \mathcal{D}$}$.
\end{enumerate}
Simiarly, we say a haplotype $Z_j^m$ is a valid instrument given
$\bm V$ if the same conditions above hold with $Z_j$ replaced by
$Z_j^m$ and $z_j \in \{0,1,2\}$ replaced by $z_j^m \in \{0,1\}$.
\end{definition}
In our setup (\Cref{assum:snp-subsets}), the exclusion restriction is
satisfied if and only if $j \not \in \mathcal{J}_y$.

Returning to the example in \Cref{fig:fammr_dag}, we see that $Z_3$
does not satisfy the exclusion restriction because $Z_3$ has a direct
effect on $Y$. The causal variant $Z_2$ for $D$ would be a valid
instrument if we condition on the corresponding haplotypes and $Z_3$,
but $Z_2$ is not observed in this example. This leaves us with one
remaining candidate instrument: $Z_1$ (and potentially its
haplotypes $Z_1^m$ and $Z_1^f$). The relevance
assumption is satisfied as long as $\bm V$ does not block both of the
following paths
\[\begin{array}{ll}%
 Z_1 \leftarrow Z_1^m \leftarrow \bm{U}^m \rightarrow Z_2^m \rightarrow Z_2 \rightarrow D; \\[0.3em]
 Z_1 \leftarrow Z_1^f \leftarrow \bm{U}^f \rightarrow Z_2^f \rightarrow Z_2 \rightarrow D. \\[0.3em]
\end{array}\]%
The exclusion restriction is satisfied because $Z_1$ is not a causal
variant for $Y$. Finally, exogeneity is satisfied if $\bm V$ blocks the
path
\[\begin{array}{ll}%
 Z_1 \leftarrow Z_1^m \leftarrow \bm{U}^m \rightarrow Z_3^m \rightarrow Z_3 \rightarrow Y(d); \\[0.3em]
 Z_1 \leftarrow Z_1^f \leftarrow \bm{U}^f \rightarrow Z_3^f \rightarrow Z_3 \rightarrow Y(d). \\[0.3em]
\end{array}
\]%
Thus, we have the following result:

\begin{proposition} \label{prop:example-adjustment-set}
For the example in \Cref{fig:fammr_dag}, the following conditional
independence relationships are true for all $d \in
\mathcal{D}$:
\begin{align}
 \label{eqn:adjustment-set-1} Z_1^m \perp\mkern-9.5mu\perp Y(d) &\mid (\bm M_1^{mf}, \bm V_{\{3\}}^m  = (\bm M_3^{mf}, Z_3^m), S = 1), \\
 \label{eqn:adjustment-set-2} Z_1 \perp\mkern-9.5mu\perp Y(d) & \mid (\bm M_1^{mf}, \bm F_1^{mf}, \bm V_{\{3\}} = ( \bm M_3^{mf}, \bm F_3^{mf}, Z_3), S=1).
\end{align}
The adjustment variables above are minimal in the sense
that no subsets of them satisfy the same conditional independence.
\end{proposition}
\begin{table}[tb]
    \caption{Some paths between $Z_1$ and $Y(d)$ in \Cref{fig:fammr_dag}.}
    \label{tab:dseparation}
    \begin{center}
     \begin{tabular}{ccl}
       \toprule
       Name of bias & Path & Blocking variable \\
       \midrule
       Dynastic effect & $ Z_1^m \leftarrow M_1^m, M_1^f \rightarrow C^m \rightarrow Y(d)$ & $(M_1^m, M_1^f)$ \\[0.5em]
       Population stratification &  $ Z_1^m \leftarrow M_1^m, M_1^f \leftarrow A \rightarrow Y(d)$ & $(M_1^m, M_1^f)$ \\[0.5em]
       Pleiotropy & $Z_1^m \leftarrow \bm{U}^m  \rightarrow Z_3^m \rightarrow Z_3 \rightarrow Y(d)$ & $Z_3^m$ or $Z_3$ \\[0.5em]
       Assortative mating & $Z_1^m \leftarrow M_1^m, M_1^f \leftarrow C^m \rightarrow \boxed{S} \leftarrow$ & $(M_1^m, M_1^f)$ or $Z_3^f$ \\
       & $C^f \leftarrow F_3^m, F_3^f \rightarrow Z_3^f \rightarrow Z_3 \rightarrow Y(d)$ & or $Z_3$ or $(F_3^m, F_3^f)$ \\[0.5em]
       Nearly determined ancestry & $Z_1^m \leftarrow \bm{U}^m \rightarrow \boxed{Z_3^m} \leftarrow $ & $(M_3^m, M_3^f)$ \\
       & $M_3^m, M_3^f \leftarrow A \rightarrow Y(d)$ & \\
       \bottomrule
     \end{tabular}
    \end{center}
\end{table}

\begin{proof}
The conditional independence follows almost immediately from
our discussion above. To show $\bm V = (\bm M_1^{mf}, \bm V_{\{3\}}^m)$ is
minimal for \eqref{eqn:adjustment-set-1} and better understand the
potential biases in MR studies, \Cref{tab:dseparation} lists several
paths between $Z_1^m$ and $Y(d)$ that are named after the key
biological mechanism involved. The table only includes the maternal
paths, but the same blocking also holds for the paternal paths.
\end{proof}

To our knowledge, the potential bias in
\Cref{tab:dseparation} due to nearly determined ancestry has not yet
been identified in the literature. This is a form of collider bias introduced because the ancestry indicator
$U_j^m$ can often be almost perfectly determined if we are given the
mother's haplotypes and the offspring's maternal haplotype . For
example, if the mother is heterozygous $M_3^m = 1,
M_3^f = 0$ and the offspring's maternal haplotype is $Z_3^m = 1$,
then we know that $U_3^m = m$ is true with very high probability. Due to
genetic linkage, there is also a high probability that $U_1^m = m$.

We conclude this section with a sufficient condition for the validity
of $Z_j^m$ and $Z_j$ in our general setting. To simplify the
exposition, let $\bm V_{\mathcal{B}}^m = (\bm{M}_{\mathcal{B}}^{mf},
\bm{Z}_{\mathcal{B}}^m)$ be a set of maternal
adjustment variables, where $\mathcal{B} \subseteq \mathcal{J}
\setminus \{j\}$ is a subset of loci. Furthermore, let $\bm
V_{\mathcal{B}} = (\bm{M}_{\mathcal{B}}^{mf}, \bm
{F}_{\mathcal{B}}^{mf}, \bm{Z}_{\mathcal{B}})$.

\begin{theorem} \label{thm:sufficient-adjustment-set}
Suppose $\bm{Z} = (Z_1,\dotsc, Z_p)$ is a full chromosome. Consider
the general causal model for Mendelian randomization in
\Cref{sec:setup} and let $j \in
\mathcal{J}$ be the index of a candidate instrument. Then $Z_j^m$ is a
valid instrument conditional on $(\bm M_j^{mf}, \bm V_{\mathcal{B}}^m)$ if the following conditions
are satisfied:
\begin{enumerate}
\item $Z_j^m \not \perp\mkern-9.5mu\perp \bm Z_d^m \mid (\bm M_j^{mf}, \bm V_{\mathcal{B}}^m, S = 1)$;
\item $Z_j^m \perp\mkern-9.5mu\perp \bm Z_y^m \mid (\bm M_j^{mf}, \bm V_{\mathcal{B}}^m, S = 1)$;
\end{enumerate}
\end{theorem}

\begin{proof}
The relevance of $Z_j^m$ follows from the first condition, because $Z_j^m$
is dependent on some causal variants (or is itself a causal
variant) of $D$. The exclusion restriction ($j \not \in
\mathcal{J}_y$) follows directly from the second
condition. For exogeneity, paths from $Z_j^m$ to $Y(d)$ either go
through the confounders $A$, $C^f$, $C^m$, or $C$, which are blocked
by $\bm M_j^{mf}$ by \Cref{prop:offspring-genotype-independence},
or through some causal variants of the outcome as in $Z_j^m \leftarrow
\bm U^m \rightarrow \bm Z_y^m \rightarrow \bm Z_y \rightarrow Y(d)$,
which are blocked by the second condition.
\end{proof}

Since \Cref{prop:offspring-genotype-independence} ensures that, after conditioning on $\bm{M}_j^{mf}$, $Z_j^m$ is independent of all ancestral and offspring confounders $(A, C^m, C^f, C)$, the only remaining threats to the validity of $Z_j^m$ as an instrument are irrelevance and pleiotropy. The set $\mathcal{B}$ is chosen to ensure that $Z_j^m$ is independent of all pleiotropic variants conditional on $\bm{V}_{\mathcal{B}}^m$ (condition 2 of \Cref{thm:identification}) but not independent of the set of causal variants (condition 1 of \Cref{thm:identification}). We will work with a general $\mathcal{B}$ until \Cref{subsec:hmm-simplification} where we describe the structure of this set. It is straightforward to extend \Cref{thm:sufficient-adjustment-set} to establish validity of the genotype $Z_j$ at locus $j$ as an instrumental variable. Details are omitted.

\subsection{Hypothesis testing}
\label{subsec:hypothesis-test}
This section describes our randomization-based approach to statistical inference in Mendelian randomization studies. We begin by describing an idealized exact setting where the randomization distribution is known. We then discuss the realistic setting where the randomization distribution must be approximated by a meiosis model.

We first describe the simplest case where we use a single genetic
variant from the offspring's maternally-inherited haplotype as an
instrument. In particular, define the \emph{propensity
  score} for some instrument $Z_{ij}^m$ at locus $j$ of individual $i$
as
\begin{equation} \label{eqn:exact-propensity-score}
\pi_{ij}^m = \mathbb{P}(Z_{ij}^m = 1 \mid \bm{M}_{ij}^{mf}, \bm{V}_{i\mathcal{B}}^m)
\end{equation}
where $\mathcal{B} \subseteq \mathcal{J}$. In words, $\pi_{ij}^m$ describes the
randomization distribution of the haplotype $Z_{ij}^m$ conditional on
a set of parental and offspring haplotypes or genotypes chosen to satisfy
the conditions in \Cref{thm:sufficient-adjustment-set}.

Let us consider a model for the potential outcomes of the form
\begin{equation}
Y_i(d) = Y_i(0) + \beta d ~ \text{for all $d \in \mathcal{D}$ and $i = 1, \ldots, N$}.
\label{eqn:potential-outcomes}
\end{equation}
Let $\mathcal{F} = \{Y_i(0) \colon i = 1, \ldots, N\}$ denote the
collection of potential outcomes for all individuals $i$ under no
exposure $d = 0$. Our goal is to test null hypotheses of the form
\begin{equation} \label{eqn:hypothesis-test}
H_0 \colon \beta = \beta_0, ~ H_1 \colon \beta \neq \beta_0
\end{equation}
where $\beta_0$ is some hypothetical value of the causal effect. If the null hypothesis is true, then the model \eqref{eqn:potential-outcomes} implies that the potential outcome under no exposure $d = 0$ can be identified from the observed data since
\[
Y_i(0) = Y_i(D_i) - \beta_0 D_i = Y_i - \beta_0 D_i.
\]
For ease of notation, let $Q_i(\beta_0) = Y_i - \beta_0 D_i$ be the adjusted outcome.

\Cref{thm:identification} and the model \eqref{eqn:potential-outcomes}
imply that we are testing the following conditional independence:
\begin{equation} \label{eqn:hypothesis-adjusted-outcome}
H_0 \colon Z_{ij}^m \perp\mkern-9.5mu\perp Q_i(\beta_0) \mid \bm (\bm{M}_{ij}^{mf}, \bm{V}_{i\mathcal{B}}^m), \quad H_1 \colon Z_{ij}^m \centernot{\independent} Q_i(\beta_0) \mid (\bm{M}_{ij}^{mf}, \bm{V}_{i\mathcal{B}}^m).
\end{equation}
Suppose we have selected a test statistic $T(\bm{Z}_j^m \mid
\mathcal{F})$ where possible dependence on $(\bm{M}_j^{mf},
\bm{V}_{\mathcal{B}}^m)$ is implicit. For example, this could be the
coefficient from a regression of the adjusted outcome on the
instrument. The randomization-based p-value for $H_0$ can then be
written as
\begin{equation}\begin{array}{ll} \label{eqn:randomization-pvalue}
P(\bm{Z}_j^m \mid \mathcal{F}) &= \tilde{\mathbb{P}}(T(\tilde{\bm{Z}}_j^m \mid \mathcal{F}) \leq T(\bm{Z}_j^m \mid \mathcal{F})) \\[1em]
&= \displaystyle \sum_{\tilde{\bm{z}}^m \in \{0,1\}^N} I\{T(\tilde{\bm{z}}_j^m \mid \mathcal{F}) \leq T(\bm{Z}_j^m \mid \mathcal{F})\} \prod_{\tilde{z}_i^m \in \tilde{\bm{z}}^m} (\pi_{ij}^m)^{\tilde{z}_i} (1-\pi_{ij}^m)^{1-\tilde{z}_i},
\end{array}\end{equation}
where $I\{\cdot\}$ is the indicator function, $\tilde{\bm{Z}}_j^m$ denotes a random draw from the distribution \eqref{eqn:exact-propensity-score} and $\tilde{\mathbb{P}}$ denotes probability with respect to the distribution \eqref{eqn:exact-propensity-score}. Given the propensity score and the
null hypothesis, this p-value can be computed exactly by enumerating
over all possible values of $\tilde{\bm{Z}}^m$ or approximated by
drawing $\tilde{\bm{Z}}^m$ a finite number of times from
$\bm{\pi}_j^m$; see Algorithm \ref{algo:pvalue} for the pseudo-code. It is
straightforward to replace the haplotype $Z_{ij}^m$ with the genotype
$Z_{ij}$; the randomization distribution of $Z_{ij} \in \{0,1,2\}$ is
a simple function of $\pi_{ij}^m$ and $\pi_{ij}^f$ since meioses in
the mother and father are independent.

\Cref{eqn:randomization-pvalue} highlights that knowledge of the
propensity score $\bm{\pi}_j^m$ is essential for performing
randomization inference. However, $\bm{\pi}_j^m$ describes a biochemical
process occurring in the human body which is not precisely known to,
or controlled by, the analyst. Therefore, the best we can do is
perform \emph{almost exact} inference by replacing $\bm{\pi}_j^m$ with
a reasonable model-based approximation. The model we use in this paper
is Haldane's hidden Markov model described in
\Cref{sec:randomization-distribution}. As discussed in
\Cref{sec:genetic-preliminaries} our method is modular in the sense
that more sophisticated meiosis models can easily be substituted as
the randomization distribution; see \textcite{Broman2000,Otto2019} for
discussion and comparison of alternative models.

\begin{algorithm}[H] \label{algo:pvalue}
\caption{Almost exact test}
\SetAlgoLined
 Compute the test statistic on the observed data $t = T(\bm{Z}_j^m \mid \mathcal{F})$\;
 \For{$k = 1, \ldots, K$}{
  Sample a counterfactual instrument $\tilde{\bm{Z}}_j^m$ from the
  randomization distribution (e.g. \Cref{thm:propensity-score} in
  \Cref{sec:randomization-distribution} based on Haldane's model)\;
  Compute the test statistic using the counterfactual instrument $\tilde{t}_k = T(\tilde{\bm{Z}}_j^m \mid \mathcal{F})$\;
 }
 Compute an approximation to the p-value in \Cref{eqn:randomization-pvalue} via the proportion of $\tilde{t}_1, \ldots, \tilde{t}_K$ which are larger than $t$:
 \[ \hat{P}(\bm{Z}_j^m \mid \mathcal{F}) = \frac{|\{k \colon t \leq \tilde{t}_k \}|}{K}. \]
\end{algorithm}

\subsection{Choosing a test statistic} \label{subsec:test-statistic}

Our randomization test retains exact nominal size under the null
hypothesis regardless of test statistic, however, we can often improve
power by selecting a test statistic that better blocks the confounding
paths between $Z_j$ and $Q(\beta_0)$. We show in
\Cref{sec:simulation-test-statistics} that test statistics that do not control for confounders can have almost
no power for certain null hypotheses. We propose a powerful test
statistic that can be constructed by including a so-called ``clever covariate'' \parencite{scharfstein1999adjusting, Rose2008} in the test statistic
\[
X_j^m = \frac{Z_j^m}{\pi_j^m} - \frac{1-Z_j^m}{1-\pi_j^m}
\]
such that
\[
T(\bm{Z}_j^m \mid \mathcal{F}) = \sum_{i=1}^N Q_i(\beta_0) X_j^m.
\]
This covariate exploits the ``central role of the propensity score'' \parencite{Rosenbaum1983} that
\[
Y(d) \perp\mkern-9.5mu\perp Z_j^m \mid \pi_j^m.
\]
where $\pi_j^m$ is defined as in equation \eqref{eqn:exact-propensity-score}, provided $0 < \pi_j^m < 1$. Conditioning on $\pi_j^m$ blocks all confounding paths between $Z_j^m$ and $Y(d)$. Furthermore, $\pi_j^m$ reduces to a single variable the adjustment set $(\bm{M}_j^{mf}, \bm{V}_{\mathcal{B}})$ which is potentially high dimensional and highly correlated.

Alternatively, we could improve power by constructing data-driven test
statistics via flexible machine learning techniques such as neural
networks, gradient boosting or random forests, although this may be
computationally costly \parencite{Watson2019}.

\subsection{Simplification via Markovian
structure} \label{subsec:hmm-simplification}

Conditional independencies implied by Haldane's model for meiosis also
allow us to greatly simplify the sufficient confounder adjustment
set. \Cref{thm:sufficient-adjustment-set} highlights a trade-off in
choosing the adjustment variables $\bm V_{\mathcal{B}}$: by choosing a
larger subset $\mathcal{B}$, the second condition is more likely but
the first condition is less likely to be satisfied. The reason is
that, when conditioning on more genetic variants, we are more likely
to block the pleiotropic paths to $Y$ but we are also more likely to
block the path between the instrument and the causal variant.

The conditions in \Cref{thm:sufficient-adjustment-set} are trivially
satisfied with $\mathcal{B} = \emptyset$ if $\mathcal{J}_y =
\emptyset$ and $\mathcal{J}_d \neq \emptyset$, i.e., all causal
variants of $Y$ on this chromosome only affect $Y$ through
$D$. However, this is a rather unlikely situation. More often, we
need to condition on other variants to block the pleiotropic paths, as
illustrated in the working example in \Cref{fig:fammr_dag}. To this
end, we can utilize the Markovian structure on the meiosis indicators
$\bm U^m$ and $\bm U^f$ implied by Haldane's model. Roughly speaking, such structure allows us to
conclude $Z_j \perp\mkern-9.5mu\perp Z_l \mid \bm M_j^{mf}, \bm F_j^{mf}, \bm
V_{\{k\}}$ for all $j < k < l$ if there are no mutations and $M_k^f \neq M_k^m$.

Let $b_1$ and $b_2$ ($b_1 < j < b_2$) be two heterozygous loci in
the mother's genome, i.e., $M_{b_1}^f \neq M_{b_1}^m$ and
$M_{b_2}^f \neq M_{b_2}^m$. Let $\mathcal{A} =
\{b_1+1,\dotsc,b_2-1\}$ be the loci between $b_1$ and $b_2$, which of
course contains the locus $j$ of interest.

\begin{theorem} \label{thm:identification}
Consider the setting in \Cref{thm:sufficient-adjustment-set} and
suppose
\begin{enumerate}
\item The meiosis indicator process is a Markov chain so that $U^m_j
 \perp\mkern-9.5mu\perp U^m_l \mid U^m_k$ for all $j < k < l$;
\item There are no mutations: $\epsilon = 0$.
\end{enumerate}
Then
$Z_j^m$ is a valid instrumental variable conditional on $(\bm
M_j^{mf}, \bm V^m_{\{b_1,b_2\}})$ if
\begin{enumerate}[resume]
\item $\mathcal{A} \cap \mathcal{J}_d \neq \emptyset$;
\item $\mathcal{A} \cap \mathcal{J}_y = \emptyset$.
\end{enumerate}
\end{theorem}
\begin{proof}
Because there are no mutations and $M_{b_1}$ and $M_{b_2}$ are
heterozygous, we can uniquely determine $U^m_{b_1}$ and $U^m_{b_2}$
from $\bm V_{\{b_1,b_2\}}^m$. By the assumed Markovian structure,
this means that
\[
 Z_j^m \perp\mkern-9.5mu\perp Z_l^m \mid \bm M_j^{mf}, \bm
 V^m_{\{b_1,b_2\}}~\text{for all}~j < b_1~\text{or}~j > b_2.
\]
Thus, the last two conditions in \Cref{thm:identification} imply the
first two conditions in \Cref{thm:sufficient-adjustment-set}.
\end{proof}

One can easily mirror the above result for using the paternal haplotype $Z_j^f$ as an instrument variable. Furthermore, let $b_1'$ and $b_2'$ ($b_1' < j < b_2'$) be two heterozygous loci in the father's genome. Then it is easy to see that $Z_j = Z_j^m + Z_j^f$ is a valid instrument conditional on $(\bm
M_j^{mf}, \bm F_j^{mf}, \bm V^m_{\{b_1,b_2\}},\bm
V^f_{\{b_1',b_2'\}})$ if the last two conditions hold for the
union $\mathcal{A} = \{\min(b_1,
b_1')+1,\dotsc,\max(b_2,b_2')-1\}$.

Under the setting in \Cref{thm:identification}, we can partition
the offspring genome into mutually independent subsets by conditioning
on heterozygous parental genotypes. This partition is useful for
constructing independent p-values when we have multiple
instruments. Suppose we have a collection of genomic position
$\mathcal{B} = \{b_1, \ldots, b_k\}$ that will be conditioned on and
let $\mathcal{A}_k = \{b_{k-1}+1, \ldots, b_k-1 \}$ be the loci in
between (suppose $b_0 = 0$ and $b_{k+1} = p+1$). This indues the
following partition of the chromosome
\[\mathcal{J} = \mathcal{A}_1 \cup \{b_1\} \cup \mathcal{A}_2 \cup
  \{b_2\} \cup  \ldots \cup \mathcal{A}_k \cup \{b_k\} \cup
  \mathcal{A}_{k+1}.\]

\begin{proposition} \label{prop:independent-instruments}
Suppose $M_j^m \neq M_j^f$ for all $j \in \mathcal{B}$. Then, under
the first two assumptions in \Cref{thm:identification}, we have
\[
    Z_j^m \perp\mkern-9.5mu\perp Z_{j^{\prime}}^m \mid (\bm{M}_j^{mf}, \bm{M}_{j^{\prime}}^{mf}, \bm{V}^m_{\mathcal{B}}).
\]
for any $j \in \mathcal{A}_{l}$ and $j^{\prime} \in \mathcal{A}_{l^{\prime}}$ such that $l \neq l^{\prime}$.
\end{proposition}
\begin{proof}
  The proof follows from an almost identical argument to
  \Cref{thm:sufficient-adjustment-set}. The assumption that $\epsilon
  = 0$ means that $U_j^m$ is uniquely determined for all $j \in
  \mathcal{B}$ from $\bm{M}^{mf}_j$ and $Z^m_j$. Therefore the assumed
  Markovian structure implies that conditioning on
  $\bm{V}_{\mathcal{B}}^m$, along with the parental haplotypes
  $\bm{M}_j^{mf}$ and $\bm{M}_{j^{\prime}}^{mf}$, then induces the
  conditional independence.
\end{proof}

\subsection{Multiple instruments} \label{subsec:multiple-ivs}

\Cref{prop:independent-instruments} allows us to formalize the
intuition that genetic instruments across the genome can provide
independent evidence about the causal effect of the exposure, if the
right loci are conditioned on.
\begin{corollary} \label{corr:independent-tests}
$Z_j^m$ and $Z_{j^{\prime}}^m$ are independent valid instruments conditional on $(\bm{M}_j^{mf}, \bm{M}_{j^{\prime}}^{mf}, \bm{V}^m_{\mathcal{B}})$ if
\begin{enumerate}
\item The first two assumptions of \Cref{thm:identification} hold;
\item $\mathcal{A}_l \cap \mathcal{J}_d \neq 0$ and $\mathcal{A}_{l^{\prime}} \cap \mathcal{J}_d \neq 0$;
\item $\mathcal{A}_l \cap \mathcal{J}_y = 0$ and $\mathcal{A}_{l^{\prime}} \cap \mathcal{J}_y = 0$.
\end{enumerate}

\end{corollary}

\Cref{corr:independent-tests} says that any two instruments are valid
and independent if they lie within separate partitions and each
partition contains a causal variant of the exposure and does not
contain any pleiotropic variants (i.e. with a direct effect on $Y$ not through $D$). As a result of this corollary, we
can combine the p-values using standard procedures to test the
intersection or global null hypothesis
\parencite{bretz16_multip_compar_using_r}.

One such procedure is called Fisher's method \parencite{Fisher1925, Wang2019}. If $\{ p_1, p_2, \ldots, p_k \}$ are a collection of independent p-values then, when all of the corresponding null hypotheses are true (or a single shared null hypothesis is true),
\[
-2 \sum_{j = 1}^k \log(p_j) \sim \mathcal{X}_{2k}^2,
\]
where $\mathcal{X}_{2k}^2$ denotes the chi-squared distribution with $2k$ degrees of freedom. We use Fisher's method to aggregate our independent p-values in the applied example in \Cref{sec:applied-example}.

As some instruments may
violate the exclusion restriction, a more robust approach is to test
the partial conjunction of the null hypotheses
\parencite{Wang2019}. In practice, it may not be
possible to separate closely linked instruments into partitions
separated by a heterozygous variant, in which case the hypothesis
\eqref{eqn:hypothesis-adjusted-outcome} can be tested using $(Z_j^m, Z_{j^{\prime}}^m)$
jointly. \Cref{cor:multiple-instruments} in \Cref{sec:technical-proofs} derives the joint randomization distribution of a collection of instruments.

\section{Simulation} \label{sec:simulation}

\subsection{Setup} \label{sec:simulation-setup}

In this section we explore the properties of our almost exact test via
simulation. The set up of the simulation is described in detail in
\Cref{sec:simulation-description}. To summarize, we consider a null
effect of an exposure on an outcome (i.e. $\beta = 0$), both of which
have variance one, using 5 genetic instruments on different
chromosomes.  %
The instruments are non-causal markers for nearby causal
variants and there are also pleiotropic variants in linkage
disequilibrium with the instruments. From the above setup we simulate
a sample of 15,000 parent-offspring trios.

To make our setup
more tangible, \Cref{tab:counterfactual-simulation-data} shows the first 6
lines of observed and counterfactual data (in red) from the simulation for one of the instruments
and corresponding parental haplotypes. We can see that individual $4$
will provide almost no information for a test of the null hypothesis;
both of her parents are homozygous so there is no randomization in her
genotype outside of de novo mutations. Conversely, both of individual
$1$'s parents are heterozygous so she could receive both major
alleles, both minor alleles or one of each.

Suppose we wish to test the null hypothesis $H_0: \beta = -0.3$. Column $\tilde{Z}_i$ in \Cref{tab:counterfactual-simulation-data} shows a counterfactual draw of each individual's instrument conditional on the adjustment set given in \Cref{eqn:sim-adjustment-set} in \Cref{sec:simulation-description}, along with the adjusted outcome $Q_i(-0.3)$. Note that $\tilde{Z}_i$ is independent of $Q_i(-0.3)$ by construction so the null hypothesis is necessarily satisfied for this counterfactual. As expected individual $4$ has the same genotype in this counterfactual, however, individual $1$ now inherits both minor alleles. \Cref{fig:simulation-null-distribution} plots a distribution of 10,000 counterfactual test statistics drawn under the null hypothesis. The test statistic is the F-statistic from a regression of the adjusted outcome on the instruments. The bars highlighted in red are larger than the observed test statistic, such that the almost exact p-value is around 0.13.

\begin{table}[!ht]
   \caption{First 6 lines of observed data from the simulation}
   \begin{center}
     \begin{tabular}{cccccccccc}
       \toprule
       $i$ & $Z_i$ & \textcolor{red}{$\tilde{Z}_i$} & $M_i^m$ & $M_i^f$ & $F_i^m$ & $F_i^f$ & $D_i$ & $Y_i$ & $Q_i(-0.3)$ \\
       \midrule
       1 & 1 & \textcolor{red}{2} & 1 & 0 & 1 & 0 & 1.11 & 0.73 & 1.06 \\
       2 & 0 & \textcolor{red}{1} & 1 & 0 & 0 & 0 & 0.83 & -0.52 & 0.77 \\
       3 & 1 & \textcolor{red}{1} & 1 & 0 & 0 & 0 & 0.94 & 0.31 & 0.59 \\
       4 & 0 & \textcolor{red}{0} & 0 & 0 & 0 & 0 & 1.43 & 3.30 & 3.73 \\
       5 & 0 & \textcolor{red}{0} & 0 & 0 & 0 & 0 & 0.15 & 1.34 & 1.38 \\
       6 & 0 & \textcolor{red}{0} & 0 & 0 & 0 & 0 & -0.14 & 1.60 & 1.56 \\
       \bottomrule
     \end{tabular}
     \label{tab:counterfactual-simulation-data}
   \end{center}
 \end{table}

 \begin{figure}[!ht]
   \begin{center}
     \caption{Histogram of 10,000 test statistics under the exact null hypothesis $H_0: \beta = -0.3$}
     \includegraphics[scale=0.65]{null_dist.pdf}
     \label{fig:simulation-null-distribution}
   \end{center}
 \end{figure}

 \subsection{Power} \label{sec:simulation-test-statistics}
In this section we simulate the power of our almost
exact test using a correct adjustment set (see
\Cref{eqn:sim-adjustment-set} in
\Cref{sec:simulation-description}). As the haplotypes are simulated
according to Haldane's meiosis model, the randomization test should be
exact. This is verified by the near-uniform distributions of the
p-values under the correct $\beta = 0$ in the left panels of
\Cref{fig:p-value-histogram}.

The histograms on the right side of \Cref{fig:p-value-histogram}
depict the distribution of p-values under an alternative hypothesis
$H_1: \beta = 0.5$. The power to reject this hypothesis
varies significantly across the choices of test
statistic. The simple $F$-statistic based on a linear regression of
the adjusted outcome on the instruments (test statistic 1) has almost
no power, while the test statistic obtained from the same model but with
the propensity score included as a clever covariate (test statistic 2)
has a reasonable power of about 0.52.

\Cref{fig:power-curves} expands upon the previous figure by plotting a
power curve for test statistic 1 and 2. We can see that test statistic
1 has power almost equal to $0$ between $\beta_0 = 0$ and $\beta_0 =
1$. This occurs because the simple two-stage least squares estimator unconditional on the adjustment set is upward biased, with an Anderson-Rubin 95\% confidence interval of 0.64--0.89. We have minimal power to reject null hypotheses in that region unless we condition on the confounders in the test statistic, because the resampled instruments retain their correlation with the confounders.

Test statistic 2, which conditions on the confounders via a clever covariate, has a power curve that is centred
on the true null $\beta_0 = 0$ and has significantly improved power in
the region between $\beta_0 = 0$ and $\beta_0 = 1$. However, it is
interesting to note that using test statistic 2 is not always more
powerful than test statistic 1.

 \begin{figure}
   \centering
   \caption{Histograms of 1,000 p-values for several null hypotheses
     and test statistics. Test statistic 1 is the F-statistic from a
     linear regression of the adjusted outcome on the
     instruments. Test statistic 2 is similar but
     includes the propensity scores for each instrument as
     covariates. Test statistic 3 includes only the parental genotypes for
     each instrument as covariates.} \label{fig:p-value-histogram}
   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n1a1.pdf}
     \caption{$H_0: \beta = 0$ and test statistic 1}
     \label{fig:null-1-test-statistic-1}
   \end{subfigure}
   \hspace{5mm}
   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n2a1.pdf}
     \caption{$H_0: \beta = 0.5$ and test statistic 1}
     \label{fig:null-2-test-statistic-1}
   \end{subfigure}%

   \par\bigskip

   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n1a2.pdf}
     \caption{$H_0: \beta = 0$ and test statistic 2}
     \label{fig:null-1-test-statistic-2}
   \end{subfigure}
   \hspace{5mm}
   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n2a2.pdf}
     \caption{$H_0: \beta = 0.5$ and test statistic 2}
     \label{fig:null-2-test-statistic-2}
   \end{subfigure}%

   \par\bigskip

   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n1a3.pdf}
     \caption{$H_0: \beta = 0$ and test statistic 3}
     \label{fig:null-1-test-statistic-3}
   \end{subfigure}
   \hspace{5mm}
   \begin{subfigure}[b]{0.45\textwidth}
     \centering
     \includegraphics[width=\textwidth]{images/pvalue_correct_n2a3.pdf}
     \caption{$H_0: \beta = 0.5$ and test statistic 3}
     \label{fig:null-2-test-statistic-3}
   \end{subfigure}%
 \end{figure}

  \begin{figure}[!ht]
   \begin{center}
     \caption{Power curves for two choices of test statistic. Test statistic 1 is the F-statistic from a naive regression of the adjusted outcome on the instruments. Test statistic 2 is similar but includes the propensity scores for each instrument as covariates. Each point on the figure is the rejection frequency over 1,000 replications.}
     \includegraphics[scale=0.7]{images/power_curves.pdf}
     \label{fig:power-curves}
   \end{center}
 \end{figure}

 %
 %

 \section{Applied example} \label{sec:applied-example}
 \subsection{Preliminaries} \label{sec:applied-example-preliminaries}
 In this section we illustrate our approach using a negative control and a positive control. The negative control is the effect of child's BMI at age 7 on mother's BMI pre-pregnancy. Dynastic effects could induce a spurious correlation between child's BMI-associated variants and their mother's BMI pre-pregnancy. This opens the backdoor path seen in \Cref{fig:dynasticeffects}. Closing this backdoor path is crucial for reliable causal inference. The positive control is the effect of child's BMI at age 7 on itself, plus some mean-zero noise. We vary the proportion of the outcome that is attributable to noise to assess the power of our test.

 Our data consist of 6,222 mother-child duos from the Avon Longitudinal Study of Parents and Children (ALSPAC). ALSPAC is a longitudinal cohort initially comprising pregnant women resident in Avon, UK with expected dates of delivery from 1 April 1991 to 31 December 1992. The initial sample consisted of 14,676 fetuses, resulting in 14,062 live births and 13,988 children who were alive at 1 year of age. In subsequent years, mothers, children and occasionally partners attended several waves of questionnaires and clinic visits, including genotyping. For a more thorough cohort description, see \cite{Boyd2013} and \cite{Fraser2013}. Please note that the study website contains details of all the data that is available through a fully searchable data dictionary and variable search tool (\url{https://www.bristol.ac.uk/alspac/researchers/our-data/}).

 Our instruments are selected from the genome-wide association study (GWAS) of \cite{Vogelezang2020}, which identifies 25 genetic variants for childhood BMI, including 2 novel loci located close to \emph{NEDD4L} and \emph{SLC45A3}. Of the genome-wide significant variants in the discovery sample, we select 11 with a p-value of less than $0.001$ in the replication sample. ALSPAC is included in the discovery sample, so independent replication is important for avoiding spurious associations with the exposure. Two of our instruments, rs571312 and rs76227980, are located close together near \emph{MC4R} and need to be tested jointly. We exclude rs62107261 because it is not contained in the 1000 Genomes genetic map file. Around each instrument, we condition on all variants which are more than 500 kilobases away.

  \subsection{Data processing} \label{sec:applied-example-data-processing}

We use ALSPAC genotype data generated using the Illumina HumanHap550 chip (for children) and Illumina human660W chip (for mothers) and imputed to the 1000 Genomes reference panel. We remove SNPs with missingness of more than 5\% and minor allele frequency of less than 1\%. Haplotypes are phased using the \texttt{SHAPEIT2} software with the \texttt{duoHMM} flag, which ensures that phased haplotypes are consistent with known pedigrees in the sample. We obtain recombination probabilities from the 1000 Genomes genetic map file on Genome Reference Consortium Human Build 37.

 \subsection{Results} \label{sec:applied-example-results}

 \Cref{tab:negative-control-results} shows the negative control results and \Cref{tab:positive-control-results} shows the positive control results across all instruments. The last row of each table shows the p-value from Fisher's method aggregated across all independent p-values. The aggregated p-value for the negative control is 0.21, indicating little evidence against the null. The aggregated p-values for the positive control range from 0.03 (when 10\% of the simulated outcome is noise) to 0.16 (when 50\% of the simulated outcome is noise). This is weak evidence against the null, resulting from insufficiently strong instruments.

  \begin{table}[!ht]
   \caption{Results from the ALSPAC negative control example.}
   \begin{center}
     \begin{tabular}{lllc}
       \toprule
       Instrument (rsID) & Chromosome & Proximal gene & P-value \\
       \midrule
       rs11676272 & 2 & \emph{ADCY3} & 0.45 \\
       rs7138803 & 12 & \emph{BCDIN3D} & 0.55 \\
       rs939584 & 2 & \emph{TMEM18} & 0.39 \\
       rs17817449 & 16 & \emph{FTO} & 0.06 \\
       rs12042908 & 1 & \emph{TNNI3K} & 0.35 \\
       rs543874 & 1 & \emph{SEC16B} & 0.07 \\
       rs56133711 & 11 & \emph{BDNF} & 0.59 \\
       rs571312, rs76227980 & 18 & \emph{MC4R} & 0.48 \\
       rs12641981 & 4 & \emph{GNPDA2} & 0.62 \\
       rs1094647 & 1 & \emph{SLC45A3} & 0.19 \\
       \midrule
       \multicolumn{3}{l}{Fisher's method} & 0.21 \\
       \bottomrule
     \end{tabular}
     \label{tab:negative-control-results}
   \end{center}
 \end{table}

   \begin{table}[!ht]
   \caption{Results from the ALSPAC positive control example}
   \begin{center}
     \begin{tabular}{lllccc}
       \toprule
       Instrument (rsID) & Chromosome & Proximal gene &  \multicolumn{3}{c}{P-value for noise of} \\
       & & & 10\% & 20\% & 50\% \\
       \midrule
       rs11676272 & 2 & \emph{ADCY3} & 0.01 & 0.01 & 0.01 \\
       rs7138803 & 12 & \emph{BCDIN3D} & 0.01 & 0.01 & 0.01 \\
       rs939584 & 2 & \emph{TMEM18} & 0.98 & 0.95 & 0.88 \\
       rs17817449 & 16 & \emph{FTO} & 0.33 & 0.35 & 0.44 \\
       rs12042908 & 1 & \emph{TNNI3K} & 0.77 & 0.79 & 0.85 \\
       rs543874 & 1 & \emph{SEC16B} & 0.48 & 0.64 & 0.92 \\
       rs56133711 & 11 & \emph{BDNF} & 0.12 & 0.14 & 0.25 \\
       rs571312, rs76227980 & 18 & \emph{MC4R} & 0.31 & 0.39 & 0.63 \\
       rs12641981 & 4 & \emph{GNPDA2} & 0.49 & 0.56 & 0.76 \\
       rs1094647 & 1 & \emph{SLC45A3} & 0.23 & 0.25 & 0.35 \\
       \midrule
       \multicolumn{3}{l}{Fisher's method} & 0.03 & 0.05 & 0.16 \\
       \bottomrule
     \end{tabular}
     \label{tab:positive-control-results}
   \end{center}
 \end{table}

 We can also compare the results in Tables \ref{tab:negative-control-results} and \ref{tab:positive-control-results} with a typical two-stage least squares (2SLS) regression using the same offspring haplotypes as instruments, unconditional on parental or other offspring haplotypes. For the negative control, the p-value from Fisher's method is 0.02, indicating some evidence against the null. This is expected, given that the backdoor paths remain unblocked. For the positive control, the p-values from Fisher's method range from less than $10^{-20}$ (when 10\% of the simulated outcome is noise) to $4.5 \times 10^{-11}$ (when 50\% of the simulated outcome is noise). This indicates that the unconditional analysis has significantly more power to detect non-zero effects compared to our ``almost exact'' test.  We discuss potential reasons for, and implications of, this low power in \Cref{sec:discussion}

 \section{Discussion} \label{sec:discussion}

Our test represents an almost exact approach to within-family MR, however, \Cref{sec:applied-example} demonstrates that power may be limited relative to typical Mendelian randomization analyses in unrelated individuals. Since our test can leverage the precise amount of power available in a single meiosis, this suggests that Mendelian randomization in unrelated individuals is drawing power from elsewhere, most likely many meioses across multiple generations. For example, an offspring with parents who are homozygous for the non-effect allele offers no power in our test, since their genotype will not vary across meioses. However, if we assume that genotypes are randomly distributed at the population level (as MR in unrelated individuals must), that same offspring can act as a comparator for individuals with the effect allele. \cite{Brumpton2020} corroborate this loss of power for their within-family method, but do not elaborate on the broader implications for how Mendelian randomization is typically justified. It would be valuable for the MR literature to discuss the extent to which Mendelian inheritance across multiple generations is driving the power behind existing results.

We must also return to the problem of transmission ratio distortion (TRD) discussed in \Cref{sec:genetic-preliminaries}. TRD violates the assumptions of our meiosis model that alleles are (unconditionally) passed from parents to offspring at the Mendelian rate of 50\%. We could represent TRD in our causal model in \Cref{fig:fammr_dag} via an arrow from the gametes $(\bm{Z}^m, \bm{Z}^f)$ to the mating indicator $S$. This indicates that the gametes themselves influence survival of their corresponding zygote to term. If our putative instrument $Z_1^m$ is in linkage with any variant exhibiting TRD, then this invalidates it as an instrument. Suppose $Z_3^m$ exhibits TRD, then this opens collider paths via the parental phenotypes $C^m$ and $C^f$, for example, $Y(d) \leftarrow C^m \rightarrow \boxed{S} \leftarrow Z_3^m \leftarrow \bm{U}^m \rightarrow Z_1^m$. The intuition is that parental phenotypes related to the likelihood of mating become associated with offspring variants related to the likelihood of offspring survival. Within our causal model, this pathway can be closed by conditioning on $Z_3^m$, with unconditioned variants obeying the meiosis model. If any unconditioned variants exhibit TRD, then this bias will remain and our meiosis model will incorrectly describe the inheritance patterns of any linked variants, resulting in an erroneous randomization distribution. Expanding resources of parent-offspring data may allow us to test the prevalence of transmission ratio distortion, which will help to inform the reasonableness of maintaining Mendel's First Law in our meiosis and fertilization model.

 \section{Acknowledgements} \label{sec:acknowledgements}

The authors thank Kate Tilling, Rachael A Hughes, Jack Bowden, Gibran Hemani, Neil M Davies, Ben Brumpton, and Nianqiao Ju for their helpful feedback. In addition, the authors are extremely grateful to all the families who took part in the ALSPAC cohort, the midwives for their help in recruiting them, and the whole ALSPAC team, which includes interviewers, computer and laboratory technicians, clerical workers, research scientists, volunteers, managers, receptionists and nurses. Ethical approval for our applied example was obtained from the ALSPAC Ethics and Law Committee and the Local Research Ethics Committees. The UK Medical Research Council and Wellcome (grant number 217065/Z/19/Z) and the University of Bristol provide core support for ALSPAC. GWAS data was generated by Sample Logistics and Genotyping Facilities at Wellcome Sanger Institute and LabCorp (Laboratory Corporation of America) using support from 23andMe. This publication is the work of the authors who will serve as guarantors for the contents of this paper. This research was supported in part by the Wellcome Trust (grant number 220067/Z/20/Z) and EPSRC (grant number EP/V049968/1). For the purpose of Open Access, the authors have applied a CC BY public copyright licence to any Author Accepted Manuscript version arising from this submission.

\printbibliography