-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathms.Rnw
2087 lines (1887 loc) · 108 KB
/
ms.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[10pt,leqno,final]{amsart}
\input{ms_header}
\title[Exact Phylodynamic Likelihood]{Exact Phylodynamic Likelihood\\ via Structured Markov Genealogy Processes}
\author[King]{Aaron~A.~King}
\address{
A.~A.~King,
Department of Ecology \& Evolutionary~Biology,
Center for the Study of Complex~Systems, and
Department of Mathematics,
University of Michigan,
Ann~Arbor, MI~48109~USA
\emph{and} Santa~Fe~Institute,
1399 Hyde~Park~Road,
Santa~Fe, NM~87501~USA
}
\email{kingaa@umich.edu}
\urladdr{\href{https://kinglab.eeb.lsa.umich.edu/}{https://kinglab.eeb.lsa.umich.edu/}}
\author[Lin]{Qianying~Lin}
\address{
Q.-Y.~Lin,
Theoretical Biology and Biophysics,
Los~Alamos National Laboratory,
Los~Alamos, NM~87545~USA
}
\author[Ionides]{Edward~L.~Ionides}
\address{
E.~L.~Ionides,
Department of Statistics,
University of Michigan,
Ann~Arbor, MI~48109~USA
}
\date{\today}
\hypersetup{pdftitle={Exact Phylodynamic Likelihood via Structured Markov Genealogy Processes}}
\hypersetup{pdfauthor={A.A. King, Q.-Y. Lin, E.L. Ionides}}
\hypersetup{urlcolor=blue,citecolor=blue,linkcolor=blue,filecolor=blue}
<<prefix,include=FALSE,cache=FALSE,purl=FALSE>>=
prefix <- "sgp"
source("setup.R")
@
<<packages,include=FALSE,cache=FALSE>>=
library(tidyverse)
library(ggtree)
library(pomp)
library(cowplot)
library(viridis)
library(phylopomp)
stopifnot(getRversion() >= "4.4")
stopifnot(packageVersion("pomp")>="6.1")
stopifnot(packageVersion("phylopomp")>="0.14.8")
theme_set(theme_bw(base_family="serif"))
options(
width=150,
keep.source=TRUE,
encoding="UTF-8",
stringsAsFactors=FALSE,
dplyr.summarise.inform=FALSE,
pomp_archive_dir="results"
)
set.seed(1159254136)
@
\begin{document}
\begin{abstract}
We consider genealogies arising from a Markov population process in which individuals are categorized into a discrete collection of compartments, with the requirement that individuals within the same compartment are statistically exchangeable.
When equipped with a sampling process, each such population process induces a time-evolving tree-valued process defined as the genealogy of all sampled individuals.
We provide a construction of this genealogy process and derive exact expressions for the likelihood of an observed genealogy in terms of filter equations.
These filter equations can be numerically solved using standard Monte Carlo integration methods.
Thus, we obtain statistically efficient likelihood-based inference for essentially arbitrary compartment models based on an observed genealogy of individuals sampled from the population.
\end{abstract}
\maketitle
\section{Introduction}
When the genome of an infectious agent accumulates mutations on timescales similar to those of transmission and infection progression, the resulting pattern of differences among genomes contains information on the history of the pathogen's passage through individual hosts and the host population.
As \citet{Grenfell2004} observed, one can extract this information to gain insight into the structure and dynamics of the host-pathogen system.
In particular, one can formalize mathematical models of transmission, estimate their parameters, and compare their ability to explain data, following standard statistical paradigms.
This is known as \emph{phylodynamic} inference.
\citet{Alizon2024} gives a good review of the history of the subject.
The most common approach to phylodynamic inference rests upon a mathematical linkage between the tree-like \emph{genealogy} or \emph{phylogeny} that expresses the relationships of shared ancestry among sampled genomes and a model of the dynamics of the transmission system.
Various linkages are possible, but because it is maximally efficient (\ie loses the least information), it is desirable to be able to compute the likelihood function for models of interest.
This is simply the probability density of a given genealogy conditional on a given model, viewed as a function of the parameters of that model.
%% Include other data, $Y$, in the expression?
In particular, if $S$ is a set of genome sequences, $\Phi$ a genealogical tree relating these sequences, $E$ a model of sequence evolution, and $D$ a dynamic transmission model, then the likelihood is
\begin{equation*}
\lik(D,E) = f(S|D,E) = \int{f(S|\Phi,E)\,f(\Phi|D)\,\dd{\Phi}},
\end{equation*}
where the integral is taken over all possible genealogies and we somewhat loosely use the symbol $f$ for the various distinct probability densities, the nature of each of which is clear from its arguments.
In this expression, $f(S|\Phi,E)$ is typically the \citet{Felsenstein2004} phylogenetic likelihood.
The function $f(\Phi|D)$, which links the phylogeny to the dynamic model, may be termed the \emph{phylodynamic likelihood}.
In the Bayesian context, this same function is sometimes referred to as a \emph{tree prior} \citep{Moeller2018,Volz2018}.
The computation of this function has remained out of reach, except in several special cases.
This paper presents theory that enables its computation for a very broad range of dynamic models.
%% Phylodynamic inference rests upon mathematical linkage between mathematical models of disease transmission at the population level and genome-sequence data collected from individual infected hosts.
%% The tightest possible such linkage is effected by a computable likelihood function.
%% The tree-like \emph{genealogy} or \emph{phylogeny} that expresses the relationships of shared ancestry among the sequences.
%% In particular, if one can determine the likelihood of any given genealogy given a model and also the likelihood of the data given a genealogy, then the likelihood of the data given the model is obtained by summing over the space of genealogies.
Existing approaches to the phylodynamic likelihood have been based on one of two mathematical idealizations.
The first is the \citet{Kingman1982a} coalescent, by which likelihood of a given genealogy is computed using a reverse-time argument.
This computation provides the exact likelihood for a genealogy resulting from a particular, constant population-size, dynamic model \citep[the Moran model, \eg][]{Moran1958,Kingman1982b,Moehle2000}.
Extensions of this approach develop approximate likelihoods for the case when the population size varies as a function of time \citep{Griffiths1994,Drummond2005} or according to an SIR process \citep{Volz2009a,Rasmussen2011}, as long as the population size is large and the sample-fraction remains negligible.
The second idealization is the linear birth-death process, for which exact expressions for the likelihood are available \citep{Stadler2010}.
Linearity in this context amounts to the assumption that distinct lineages do not interact:
it is the resulting self-similarity of genealogies that renders the likelihood analytically tractable.
Extensions of this approach develop approximations via linearization of nonlinear processes or restriction to scenarios in which population growth is nearly linear \citep[\eg][]{MacPherson2021}.
Although the tractability of these approaches makes them attractive, concern naturally arises as to validity of the approximations in specific cases, the biases introduced by them, and the amount of information in data left unutilized by these approximate methods.
For this reason, there is interest in improved phylodynamic inference techniques.
%% Factorization of problem into two subproblems.
%% Problems with this approach \citep{Smith2017}.
What would an ideal phylodynamic inference method look like?
First, it would afford exact computation of the phylodynamic likelihood, so that comparisons among parameterizations and models could be made on a sound basis.
Second, because nonlinearity, nonstationarity, noise, and measurement error are prominent and ubiquitous in epidemiology, it would accommodate nonlinear, time-inhomogeneous, stochastic transmission models.
Third, because many of the most scientifically important uncertainties concern heterogeneities in transmission rates and the susceptibility, behavior, age, and location of hosts, it would accommodate host populations structured by these factors.
While some structuring factors (\eg age, spatial location) are most naturally expressed in terms of continuous variables, discretely structured models have repeatedly proved their value in epidemiology.
In particular, compartmental models are extremely flexible and have often been used as approximations when continuous structure leads to uncomfortably high model dimension.
Finally, because there is typically uncertainty not only in the parameters, but also in the structure, of a host-pathogen system, an improved phylodynamic inference methodology would place minimal restrictions on the form of the models that it can accommodate.
This paper demonstrates how these desiderata can be achieved---at least for models with discrete structure---including arbitrary nonlinear compartmental models.
Of course, practical considerations play an important role as well.
In practice, data availability typically places strong limits on the degree of model complexity that can be supported by data.
In addition, computational expense typically grows with model complexity and this can also limit the utility of otherwise attractive models and inference methods.
Nevertheless, in the present paper we confine ourselves to theoretical considerations.
The results we present could form the basis for a variety of distinct algorithms the relative value of which will depend on the questions asked, models proposed, and data available, and in any case remains to be seen.
Moreover, although the theory we present is valid for models with even a countably infinite number of compartments, lack of data and computational resources will in practice require that the models that can effectively be employed may be much simpler than desired.
To connect a model at the level of a population with genealogies based on samples taken from individual hosts, it is necessary to make assumptions about the individuals in the population.
The simplest such assumption is that the individuals that are identical with respect to the population dynamics are indeed statistically identical.
That is, that they are \emph{exchangeable}.
In a compartmental model, this is tantamount to the assumption that the residence times of the individuals within each compartment are identically distributed, though not independent.
Although exchangeability is indeed an additional assumption, it is so natural that it is frequently unrecognized as such, and one often reads statements to the effect that exchangeability of individuals is a consequence of the Markovian assumption.
Nonetheless, since it adds minimal additional structure, it is the natural assumption, and the one we will make in this paper.
In the following, we take as our starting point a transmission model in the form of a discretely structured, Markov process.
We show how such a process uniquely induces each of several stochastic processes in the space of genealogies.
We go on to derive expressions for the exact likelihoods of these genealogies.
Code sufficient for the reproduction of all the results presented in this paper are freely available for download at \url{https://github.com/kingaa/structured-genealogy-process-paper}.
An archival version of these will be stored on Zotero upon publication of a peer-reviewed version of this paper.
The open-source \pkg{R} package \pkg{phylopomp} (\url{https://github.com/kingaa/phylopomp}) implements the simulation and likelihood-computation algorithms employed here.
%% In particular, while the constructions of \citet{Etheridge2019} can in principle accommodate.
%% For structured but deterministic models, approach of \citet{Volz2012,Rasmussen2014a}, based on approximation as birth-death processes:
%% approximation no longer needed.
%% Because there is commonly broad uncertainty regarding the structure of the transmission process, for example due to heterogeneities in transmission rates and susceptibilities, complex behavior patterns, etc., methods that have the plug-and-play property are particularly useful.
%% Such techniques for inference based on time series are well understood and widely used.
%% When the data lie in some Euclidean space, they can commonly be modeled as draws from some error distribution conditional on the latent state of the transmission process.
%% However, when the data are genealogies (also called phylogenies) representing the relationships of shared ancestry among genomic samples, the data-space is non-Euclidean and the appropriate models connecting the data to the latent state are non-trivial.
%% Modeling of the sampling process.
%% Extension of previous results \citep{King2022}.
%% Broader class of state-spaces.
%% Accommodating discrete structure.
%% In an \emph{unstructured} Markov population process, every lineage is exactly like every other.
%% \citet{King2022} showed how every such process induces an unstructured Markov genealogy process.
%% Here, our aim is to expand the theory considerably by allowing our population of lineages to have discrete structure.
%% Classes of Markov processes.
%% Utility and flexibility of Markov assumptions.
%% Population process induces Markov history and genealogy processes.
%% Using these, we derive equations for the likelihood of a genealogy conditional on the history.
%% We then integrate out the history to obtain nonlinear filter equations, the solution of which yields the likelihood.
%% These readily lend themselves to a family of Sequential Monte Carlo algorithms for computing the likelihood.
%% We demonstrate with several examples.
\section{Mathematical preliminaries}
\subsection{Notation}
Throughout the paper, we will adopt the convention that a bold-face symbol (\eg $\Xr$), denotes a random element.
We will be concerned with a variety of stochastic processes, in both discrete and continuous time.
In both cases, we will use a subscript to indicate the time parameter: \eg $\Xr_t$ or $\Gr_k$, where $t$ takes values in the non-negative reals $\Rp$ and $k$ in the non-negative integers $\Zp$.
In the case of continuous-time processes, we will assume that sample paths are \cadlag\ \ie right-continuous with left limits.
We will frequently need to refer to the left-limit of such a process.
Accordingly, if $\Phir_t$ is a \cadlag\ random process, we define
\begin{equation*}
\Phirt_t\colonequals
\begin{cases}
\displaystyle\lim_{s\,\uparrow\,{t}}\;\Phir_{s}, & t>0,\\[2ex]
\Phir_0, & t=0.\\
\end{cases}
\end{equation*}
Note that $\Phirt_t$ is thus left-continuous with right limits.
If $\Phir_t$, $t\in\Rp$ is a pure jump process, knowledge of its sample path is equivalent to knowledge of the number, $\Kr_t$, of jumps it has taken as of time $t$, the jump times $\Trh_k$, and the embedded chain $\Phirh^{}_k\coloneq{\Phir_{\Trh^{}_k}}$, $k=0,\dots,\Kr^{}_t$.
In particular, if we adopt the convention that $\Trh_0=0$ and $\Trh_{\Kr_t+1}=t$, then
$\Phir_t=\Phirh_k$ for $t\in\halfopen{\Trh_k,\Trh_{k+1}}$, $k=0,\dots,\Kr_t$.
\subsection{Population process}
We are motivated by the desire for exact phylodynamic inference methods for as wide a class of epidemiological models as possible.
In particular, we would like to be able to formulate and parameterize an arbitrary compartmental model and to quantify its ability to explain data using likelihood.
\Cref{fig:example_models} depicts a few such models in order to give a sense of the kinds of complexities that can arise.
Of course, with the ability to entertain models with countably many compartments, much greater complexity is possible.
In particular, one can model not only complex infection progression, but also strain structure, behavioral structure, age structure, and spatial structure using compartmental models.
As is well known, one can discretize continuous structure-variables and employ the linear chain trick to accommodate non-exponential residence times.
While the utility of these approximations will vary, a very wide range of model assumptions lie within the scope of the theory presented here.
\begin{figure}
\input{figs/example_models}
\caption{
Examples of discretely-structured population models.
Demes are shaded.
Compartments containing infectious hosts are outlined in green.
Curved green lines connect transmission rates with the compartments whose occupancies control their modulation;
each such connection gives rise to a nonlinearity in the model.
\textbf{(A)} An SEIRS model.
Susceptible individuals ($\lab{S}$), once infected, enter a transient incubation phase ($\lab{E}$) before they become infectious ($\lab{I}$).
Upon recovery ($\lab{R}$), individuals experience immunity from reinfection.
If this immunity wanes, they re-enter the susceptible compartment.
Pathogen lineages are to be found in hosts within the $\lab{E}$ and $\lab{I}$ compartments only.
Accordingly, there are two demes: $\Demes=\Set{\lab{E},\lab{I}}$.
If there is exactly one lineage per host, then the occupancy, $n(\Xr_t)=(n_{\lab{E}}(\Xr_t),n_{\lab{I}}(\Xr_t))$, is the integer 2-vector giving the numbers of hosts in the respective compartments.
See \cref{sec:demes} for definition and discussion of demes and deme occupancy.
\textbf{(B)} In this four-deme model, two distinct pathogen strains compete for susceptibles.
\textbf{(C)} A three-deme model according to which, after an incubation period, hosts may develop asymptomatic infection ($\lab{I_A}$).
If they do not recover, symptomatically infected hosts ($\lab{I_S}$) can progress to hospitalization ($\lab{H}$) and death ($\lab{D}$).
\textbf{(D)} A three-deme model with heterogeneity in transmission behavior.
Contagious individuals move randomly between low-transmission ($\lab{I_L}$) and high-transmission ($\lab{I_H}$) behaviors.
\label{fig:example_models}
}
\end{figure}
We will assume that our population process is a time-inhomogeneous Markov jump process, $\Xr_t$, $t\in\Rp$, taking values in some space $\Xspace$.
In earlier work \citep{King2022}, we limited ourselves to the case $\Xspace=\mathbb{Z}^d$, but here we assume only that $\Xspace$ is a complete metric measure space with a countable dense subset.
The population process is completely specified by its initial-state density, $p_0$, and its transition rates $\alpha$.
In particular, we suppose that
\begin{equation}
\label{eq:ic}
\Prob{\Xr_0\in\mathcal{E}}=\int_{\mathcal{E}}{p_0(x)\,\dd{x}}
\end{equation}
for all measurable sets $\mathcal{E}\subseteq\Xspace$.
For any $t\in\Rp$, $x,x'\in\Xspace$, we think of the quantity $\alpha(t,x,x')$ as the instantaneous hazard of a jump from $x$ to $x'$.
More precisely, the transition rates have the following properties:
\begin{equation*}
\begin{gathered}
\alpha(t,x,x')\ge{0}, \qquad \int_{\Xspace}{\alpha(t,x,x')\,\dd{x'}}<\infty,\\
\end{gathered}
\end{equation*}
for all $t\in\Rp$ and $x,x'\in\Xspace$ and that, as a function of time, $\alpha$ is continuous almost everywhere.
Henceforth, we understand that integrals are taken over all of $\Xspace$ unless otherwise specified.
Let $\Kr_t$ be the number of jumps that $\Xr$ has taken by time $t$.
We assume that $\Kr_t$ is a simple counting process so that
\begin{equation*}
\begin{gathered}
\CondProb{\Kr_{t+\Delta}=n+1}{\Kr_{t}=n}=\Delta\,\int{\alpha(t,x,x')\,\dd{x'}}+o(\Delta),\\
\CondProb{\Kr_{t+\Delta}>n+1}{\Kr_{t}=n}=o(\Delta),\\
\CondProb{\Xr_{t+\Delta}\in\mathcal{E}}{\Xr_{t}=x, \Kr_{t+\Delta}-\Kr_{t}=1}=\frac{\int_{\mathcal{E}}{\alpha(t,x,x')\,\dd{x'}}}{\int{\alpha(t,x,x')\,\dd{x'}}}+o(\Delta).
\end{gathered}
\end{equation*}
We further assume that $\alpha(t,x,x')$ is \cadlag\ as a function of time for all $x,x'\in{\Xspace}$ and that the number of jumps that occur in a finite time-interval is finite, \ie $\Prob{\Kr_t<\infty}=1$ for all $t$.
\subsection{Kolmogorov forward equation}
The above may be compactly summarized by stating that if $v(t,x)$ satisfies the Kolmogorov forward equation (KFE),
\begin{equation}
\label{eq:kfe}
\frac{\partial{v}}{\partial{t}}(t,x)
=\int\!{v(t,x')\,\alpha(t,x',x)\,\dd{x'}}
-\int\!{v(t,x)\,\alpha(t,x,x')\,\dd{x'}},
\end{equation}
and if, moreover, $v(0,x) = p_0(x)$,
then $\int_{\mathcal{E}}\!{v(t,x)\,\dd{x}}=\Prob{\Xr_t\in\mathcal{E}}$ for every measurable $\mathcal{E}\subseteq{\Xspace}$.
\Cref{eq:kfe} is sometimes called the \emph{master equation} for $\Xr_t$.
\subsection{Inclusion of jumps at deterministic times}
For modeling purposes, it is sometimes desirable to insist that certain events occur at known times.
For example, if samples are collected at specific times in such a way that the timing itself conveys no information about the process, one might wish to condition on the sampling time.
We can expand the class of population models to allow for this as follows.
Suppose that $S=\Set{s_1,s_2,\dots,}\subset\Zp$ is a sequence of event times.
Let us postulate that, at each of these times, an event occurs at which $\Xr_t$ jumps according to a given probability kernel $\pi$.
In particular, for any state $x\in\Xspace$ and measurable $\mathcal{E}\subset\Xspace$,
$\pi(s_i,x,\mathcal{E})$ is the probability that the jump at time $s_i$ is to $\mathcal{E}$, conditional on the state just before the jump being $x$.
With this notation, the KFE for the process becomes
\begin{align}
\label{eq:kfe-reg}
\frac{\partial{v}}{\partial{t}}(t,x)
&=\int\!{v(t,x')\,\alpha(t,x',x)\,\dd{x'}}
-\int\!{v(t,x)\,\alpha(t,x,x')\,\dd{x'}},
&t\notin{S},\\
\label{eq:kfe-sing}
v(t,x)\,\dd{x}
&=\int\!{\leftlim{v}(t,x')\,\pi(t,x',\dd{x})\,\dd{x'}},
&t\in{S}.
\end{align}
Note that the \cref{eq:kfe-reg} is identical to \cref{eq:kfe};
we call this the \emph{regular part} of the KFE.
We refer to \cref{eq:kfe-sing} as the \emph{singular part} of the KFE.
As a matter of notation, one can represent \cref{eq:kfe-reg,eq:kfe-sing} as a single equation in the form of \cref{eq:kfe}.
In particular, if in \cref{eq:kfe} we make the substitution
\begin{equation*}
\alpha(t,x,x')\mapsto\alpha(t,x,x')+\sum_{s\in{S}}{\delta(t,s)\,\frac{\dd{\pi}}{\dd{x'}}(t,x,x')},
\end{equation*}
we obtain an equation which we can view as shorthand for \cref{eq:kfe-reg,eq:kfe-sing}.
Here, $\delta(t,s)$ is a Dirac delta function and $\dd{\pi}/\dd{x'}$ denotes the density (\ie Radon-Nikodym derivative) of $\pi$ with respect to the measure on $\Xspace$.
%% To be even more parsimonious, we can refer to \cref{eq:kfe-reg,eq:kfe-sing} as the $(\alpha,\pi,S)$ KFE.
\subsection{Jump marks}
%% Another perspective on the Markov processes is to be had from its Markov state transition diagram (\cref{fig:markov_state}).
\begin{figure}
\input{figs/markov_diagram}
\end{figure}
It will be useful to divide the jumps of the population process $\Xr_t$ into distinct categories, which differ with respect to the changes they induce in a genealogy.
For this purpose, we let $\Jumps$ be a countable set of jump \emph{marks} such that
\begin{equation*}
\alpha(t,x,x')=\sum_{u\in\Jumps}{\alpha_u(t,x,x')}.
\end{equation*}
\Cref{fig:markov_state} shows an example for which $\Jumps$ has five elements.
In the following, sums over $u$ are to be taken over the whole of $\Jumps$ unless otherwise indicated.
Let us define the \emph{jump mark} process, $\Ur_t$, to be the mark of the latest jump as of time $t$.
As usual, we take the sample paths of $\Ur_t$ to be \cadlag.
Observe that, though $\Xr_t$ and $(\Xr_t,\Ur_t)$ are Markov processes, $\Ur_t$ is not.
\subsection{Demes and deme occupancy}
\label{sec:demes}
Our first goal in this paper is to show how a given population process induces a unique stochastic process on the space of genealogies.
At each time, this genealogy will represent the relationships of shared ancestry among a population of lineages extant at that time.
To accommodate the structure of the population, this population of lineages will itself be subdivided into discrete categories.
In particular, we suppose that there are a countable set of subpopulations, within each of which individual lineages are exchangeable.
We call these subpopulations \emph{demes}, and use the symbol $\Demes$ to denote an index set for them.
\Cref{fig:example_models} illustrates this concept in the context of several compartmental models.
We define the \emph{deme occupancy} function $n:\Demes\times\Xspace\to\Zp$ so that
for $i\in\Demes$, $x\in\Xspace$, $n_i(x)$ is the number of lineages in deme $i$ when the population is in state $x$.
\subsection{Examples}
The class of population models to which the theory presented here applies is very broad indeed.
In particular, it encompasses the entire class of compartmental models with time-dependent flow rates.
Here, to give a sense of this breadth, we briefly describe a few models of interest.
\Cref{sec:app-examples} works out the theory for each of these examples.
\paragraph{SIRS model}
\citet{King2022} worked out formulas for the exact likelihood of a genealogy induced by an SIRS model.
The theory developed in this paper applies, but since there is only one deme in this model, this is a simple case.
\paragraph{SEIRS model}
A simple, yet interesting, model with more than one deme is the SEIRS model (\cref{fig:example_models}A).
The state space is $\Zp^4$, with the state $x=(S,E,I,R)$ defined by the numbers of hosts in each of the four compartments.
It has two demes: $\Demes=\Set{\lab{E},\lab{I}}$.
The deme occupancy function in this case is $n(x)=(E,I)$.
Note that the terms associated with sampling cancel each other in the KFE, since, in this model, sampling has no effect on the state.
\paragraph{Two-strain competition model}
A simple model for the competition of two strains for susceptible hosts is depicted in \cref{fig:example_models}B.
In this model, the state vector consists of seven numbers: $x=(S,E_1,E_2,I_1,I_2,R_1,R_2)$.
There are four demes ($\Demes=\Set{\lab{E}_1,\lab{E}_2,\lab{I}_1,\lab{I}_2}$) and the occupancy function is $n(x)=(E_1,E_2,I_1,I_2)$.
\paragraph{Superspreading model}
\Cref{fig:example_models}D depicts a model of superspreading.
There are three demes ($\Demes=\Set{\lab{E},\lab{I_L},\lab{I_H}}$).
\paragraph{Linear birth-death model}
The linear birth-death process, a mainstay of existing phylodynamic methods, is a special case of the theory presented here.
For this process, we have $\Xspace=\Zp$ and there is a single deme.
$\Xr_t$ represents the size of a population and $n(X_t)=X_t$.
\paragraph{Moran model and the Kingman coalescent}
The \citet{Kingman1982a} coalescent is another workhorse in existing phylodynamic approaches.
It is the ancestral process for the Moran model, in which a fixed population of $n$ lineages experiences events at times distributed according to a rate-$\mu$ Poisson process.
At each such event, an individual lineage selected uniformly at random dies and is replaced by the offspring of a second randomly selected lineage.
\subsection{History}
Consider the Markov process $(\Xr_t,\Ur_t)$.
We define its \emph{history process}, $\Hr_t$, to be the restriction of the random function $s\mapsto(\Xr_s,\Ur_s)$ to the interval $[0,t]$.
Note that $\Hr_t$ is itself trivially a Markov process, since it contains its own history.
Alternatively, one can think of $\Hr_t$ as consisting of the sequence
$\left(\left(\Trh_k,\Xrh_k,\Urh_k\right)\right)_{k=0}^{\Kr_t}$.
In particular, conditional on $\Hr_t$, both $\Xr_t$ and $\Ur_t$ are deterministic, as are $\Kr_t$, the embedded chains, $\Xrh_k$, $\Urh_k$, and the point process of event times $\Trh_k$.
The probability measure on the space of histories can be expressed in terms of these:
\begin{mathsize}{9pt}{10pt}
\begin{equation}
\label{eq:Hdens}
\Prob{\dd{\H_t}}
=p_{0}(\Xh_{0})\,\dd{\Xh_0}\,
\prod_{k=1}^{K_{t}}{\alpha_{\Uh_k}\!\!\left(\Th_k,\Xh_{k-1},\Xh_{k}\right)\,\dd{\Xh_k}\,\dd{\Th_k}}
\,\exp{\left(-\sum_{k=0}^{K_t}{\int_{\Th_{k}}^{\Th_{k+1}}{\sum_{u}{\int{\alpha_{u}(t',\Xh_{k},x')\,\dd{x'}}}}\,\dd{t'}}\right)},
\end{equation}
\end{mathsize}%
where again, by convention, $\Th^{}_0=0$ and $\Th^{}_{K^{}_t+1}=t$.
If $\H$ is such a history, we define $\time(\H)$ to be the right endpoint of its domain and use the notation $\event{\H}\coloneq\Set{\Th^{}_1,\dots,\Th^{}_{\K_t}}\subset{[0,\time(\H)]}$ to denote the set of its jump times.
\subsection{Genealogies}
\label{sec:genealogy}
\begin{figure}
\begin{center}
<<geneal,fig.dim=c(4,2),out.width="50%">>=
simulate(
"SEIR",
Beta=3,sigma=0.5,gamma=0.2,psi=0.3,omega=0.5,
S0=15,E0=1,I0=2,R0=0,
time=10
) |>
freeze(seed=382490723) -> x
pal <- c("#00274CFF","#FFCB05FF")
x |> plot(points=TRUE,prune=FALSE,obscure=FALSE,palette=pal)+
geom_vline(xintercept=10,linewidth=0.2,color="black")
@
\end{center}
\caption{
A genealogy, $G$, specifies the relationships of shared ancestry (via its tree-structure) and deme occupancy histories (via the coloring of its branches) of a set of lineages extant at some time $\time(G)$, as well as some samples gathered at earlier times.
Here, $\time(G)=10$ and there are two demes, $\Demes=\Set{\func{blue},\func{yellow}}$.
Tip nodes, denoting extant lineages, are shown as black dots;
sample nodes are shown as blue dots;
internal nodes are indicated in green.
Note that internal nodes occur not only at branch-points, but also inline (\ie along branches).
Wherever a lineage moves from one deme (color) to another, an internal node occurs;
the converse does not necessarily hold.
\label{fig:geneal}
}
\end{figure}
A \emph{genealogy}, $G$, encapsulates the relationships of shared ancestry among a set of lineages that are extant at some time $\time(G)\in\Rp$ and perhaps a set of samples collected at earlier times (\cref{fig:geneal}).
A genealogy has a tree- or forest-like structure, with four distinct kinds of nodes:
\begin{inparaenum}[(i)]
\item \emph{tip nodes}, which represent labeled extant lineages;
\item \emph{internal nodes}, which represent events at which lineages diverged and/or moved from one deme to another;
\item \emph{sample nodes}, which represent labeled samples; and
\item \emph{root nodes}, at the base of each tree.
\end{inparaenum}
Each node $a$ is associated with a specific time, $\time(a)$.
In particular, if $a$ is a tip node in $G$, then $\time(a)=\time(G)$;
if $a$ is a sample node, then $\time(a)\le{\time(G)}$ is the time at which the sample was taken.
Moreover, if node $a$ is ancestral to node $a'$, then $\time(a)\le{\time(a')}$ and $\time(a')-\time(a)$ is the distance between $a$ and $a'$ along the genealogy.
Without loss of generality we assume that $\time(a)=0$ for all root nodes $a$.
We let $\event{G}$ denote the set of all internal and sample node-times of the genealogy $G$;
we refer to these as \emph{genealogical event times}.
Importantly, a genealogy informs us not only about the shared ancestry of any pair of lineages, but also about where in the set of demes any given lineage was at all times.
Accordingly, we can visualize a genealogy as a tree, the nodes and edges of which are painted with a distinct color for each deme (\cref{fig:geneal}).
Note that a genealogy will in general have \emph{branch-point nodes}, \ie internal nodes with more than one descendant, but may also have internal nodes with only one descendant.
We refer to such nodes as \emph{inline nodes}.
These occur whenever the color changes along a branch, but can also occur without a color-change.
Formally, we define a genealogy, $G$, to be a triple, $(T,Z,Y)$, where $T=\time(G)\in\Rp$ is the \emph{genealogy time}, $Z$ specifies the genealogy's \emph{tree structure}, and $Y$ gives the \emph{coloring}.
In particular, let $\leaves$ be a countable set of labels and let $\part(\leaves)$ be the set of all collections of finite, mutually-disjoint subsets of $\leaves$.
That is, an element $z\in{\part(\leaves)}$ is a partition of the finite set $\bigcup{z}\subseteq\leaves$.
Partition \emph{fineness} defines a partial order on $\part(\leaves)$.
Specifically, for $z,z'\in{\part(\leaves)}$, we say $z\preceq{z'}$ if and only if for every $b'\in{z'}$ there is $b\in{z}$ such that $b\supseteq{b'}$.
The tree structure of $G$ is defined by a \cadlag\ map $Z:[0,T]\to\part(\leaves)$ that is monotone in the sense that $t_1\le{t_2}$ implies $Z_{t_1}\preceq{Z_{t_2}}$.
An element $b\in{Z_t}$ is a set of labels;
it represents the branch of the tree that bears the corresponding lineages.
We use the notation $\event{Z}$ to denote the set of times at which $Z$ is discontinuous.
Note that $\event{Z}$ includes the times of all tip, sample, and branch-point nodes, but excludes inline and root nodes.
Therefore, $\event{Z}\subseteq{\event{G}}$.
The third element of $G$ specifies the coloring of branches and locations of tip, sample, and internal nodes (including inline nodes).
Mathematically, if $G=(T,Z,Y)$, then $Y$ is a \cadlag\ function that maps each point on the genealogy to a deme and a non-negative integer.
In particular, if $t\in[0,T]$ and $a$ is the label of any tip or sample node,
$Y_t(a)=(Y_t^{\lab{d}}(a),Y_t^{\lab{m}}(a))\in\Demes\times\Zp$, where $Y_t^{\lab{d}}(a)$ is the deme in which the lineage of $a$ is located at time $t$ and $Y_t^{\lab{m}}(a)$ is the number of internal or sample nodes encountered along the lineage of $a$ in going from time $0$ to time $t$.
In particular, $Y_t^{\lab{m}}(a)$ is a simple counting process, with $Y_0^{\lab{m}}(a)=0$ for all $a$.
Since $a,a'\in{b}\in{Z_t}$ implies $Y_t(a)=Y_t(a')$, one can equally well think of $Y_t$ as a map $Z_t\to\Demes\times\Zp$.
Given a tree $Z$, we let $\func{Y}(Z)$ denote the set of colorings $Y$ that are compatible with $Z$.
We moreover define $\func{Y}_t(Z)\coloneq\CondSet{Y_t}{Y\in{\func{Y}(Z)}}$.
Formally speaking, $\func{Y}(Z)$ is a fiber bundle over $Z$, each $\func{Y}_t(Z)$ being a fiber.
It will sometimes be convenient to make use of notation whereby a genealogy $G=(\time(G),G^{\lab{Z}},G^{\lab{Y}})$.
\subsection{Binomial ratio}
\label{sec:binomial_ratio}
For $n,r,\ell,s\in{\Zp^\Demes}$, define the \emph{binomial ratio}
\begin{equation*}
\BinRatio{n}{\ell}{r}{s}\colonequals
\begin{cases}
\frac{\displaystyle\prod_{i\in\Demes}{\binom{n_i-\ell_i}{r_i-s_i}}}%
{\displaystyle\prod_{i\in\Demes}{\binom{n_i}{r_i}}},
& \text{if}\ \forall i\ n_i\ge{\Set{\ell_i,r_i}}\ge{s_i}\ge{0},\\[7ex]
0, & \text{otherwise}.
\end{cases}
\end{equation*}
Observe that $\BinRatio{n}{\ell}{r}{s}\in{[0,1]}$.
Moreover, in consequence of the Chu-Vandermonde identity, we have
\begin{equation*}
\sum_{s\in\Zp^{\Demes}}\BinRatio{n}{\ell}{r}{s}\binom{\ell}{s}=1,
\end{equation*}
whenever $n_i\ge{\Set{\ell_i,r_i}}\ge{0}$ for all $i$.
\section{The induced genealogy process}
\subsection{Event types}
\label{sec:event_types}
We now show how a given population process naturally induces a process in the space of genealogies.
Specifically, at each jump in the population process, a corresponding change occurs in the genealogy, according to whether lineages branch, die, move between demes, or are sampled.
For this purpose, there are five distinct \emph{pure types} of events:
\begin{compactenum}[(a)]
\item \emph{Birth-type events} result in the branching of one or more new lineages, each from some existing lineage.
Examples of birth-type events include transmission events, speciations, and actual births.
Importantly, we assume that all new lineages arising from a birth event share the same parent and that at most one birth event occurs at a time, almost surely.
\item \emph{Death-type events} result in the extinction of one or more lineages.
Examples include recovery from infection, death of a host, and species extinctions.
We allow for the possibility that multiple lineages die simultaneously.
\item \emph{Migration-type events} result in the movement of a lineage from one deme to another.
Spatial movements, changes in host age or behavior, and progression of an infection can all be represented as migration-type events.
We permit multiple lineages to move simultaneously.
\item \emph{Sample-type events} result in the collection of a sample from a lineage.
We allow for the possibility that multiple samples are collected simultaneously, though we require that, in this case, each extant lineage is sampled at most once.
\item \emph{Neutral-type events} result in no change to any of the lineages.
\end{compactenum}
\Cref{fig:markov_state} depicts an example with jumps of all five pure types.
It is not necessary that an event be of a pure type;
\emph{compound events} partake of more than one type.
For example, a sample/death-type event, in which a lineage is simultaneously sampled and removed, has been employed \citep{Leventhal2014}, as have birth/death events in which one lineage reproduces at the same moment that another dies (\eg the \citet{Moran1958} process).
The theory presented here places few restrictions on the complexity of the events that can occur by combining events of the various pure types.
%% Because different kinds of events may differ not only in the number of offspring they engender, but also in the number of parent lineages, and the distribution of offspring among parents and demes, there is implicitly a deterministic indicator function $Q_u$, for $u\in\Jumps$, (described below) that captures these properties.
\subsection{Genealogy process}
We now show how a given population process induces a stochastic process, $\Gr_t$, on the space of genealogies.
In the case of unstructured population processes (\ie those having a single deme), \citet{King2022} gave a related construction that is equivalent to the one presented here.
\begin{figure}
\input{figs/event_types}
\caption{
Event types differ by their effects on the genealogy.
This can be seen by examining the local structure of the genealogy in the neighborhood of a jump.
\textbf{(A)} A birth-type jump results in the branching of one or more child lineages from the parent.
There can be only one parent, though the demes of the child lineages may differ from that of their parent.
Here, a parent of the blue deme sires one child lineage in each of the blue and yellow demes.
The \emph{production} of an event is an integer vector, with one entry for each deme.
The production of this event is therefore $r=(r_{\lab{blue}},r_{\lab{yellow}})=(2,1)$.
The \emph{deme occupancy} of an event is the number of lineages in each deme just to the right of the event.
The deme occupancy at this event is therefore $n=(n_{\lab{blue}},n_{\lab{yellow}})=(3,5)$.
\textbf{(B)} A death-type event causes the extinction of a lineage.
Since internal nodes without children are recursively removed, the affected branch is dropped.
The production of this event is $r=(0,0)$ and the deme occupancy is $n=(3,4)$.
\textbf{(C)} A migration-type event results in the movement of one or more lineages from one deme to another.
Here, one lineage moves from the yellow to the blue deme.
The production of this event is $r=(1,0)$, \ie the production is 1 for the blue deme and 0 for the yellow.
The deme occupancy is $n=(6,2)$.
\textbf{(D)} In a sample-type event, one or more sample nodes (blue circles) are inserted.
Here, there are two samples, one in each of the blue and yellow demes.
Accordingly, $r=(1,1)$ and $n=(2,6)$.
\textbf{(E)} A neutral-type event has no effect on the genealogy and zero production in all demes: $r=(0,0)$, $n=(5,3)$.
\textbf{(F)} The theory presented here allows for compound events.
As an example, here a birth/death-type event occurs, wherein one yellow lineage is extinguished and a blue lineage simultaneously sires a blue child.
For this event, we have $r=(2,0)$ and $n=(6,2)$.
\textbf{(G)} Here, a compound sample/death-type event with $r=(0,0)$ and $n=(2,5)$ occurs.
A blue lineage is sampled and simultaneously extinguished.
Note that recursive removal does not occur, since sample nodes are never removed.
\textbf{(H)} A compound birth/migration-type event with $r=(4,0)$ and $n=(6,2)$.
\label{fig:event_types}
}
\end{figure}
At each jump in the population process, a change is made to the genealogy, according to the mark, $u$, of the jump (\cref{fig:event_types}).
In particular:
\begin{compactenum}[(a)]
\item
If $u$ is of birth-type (\cref{fig:event_types}A), it results in the creation of one new internal node, call it $b$.
A tip node, $a$, of the appropriate deme is chosen with uniform probability from among those present and $b$ is inserted so that its ancestor is that of $a$, while $a$ takes $b$ as its ancestor.
One new tip node, of the appropriate deme, is created for each of the children, all of which take $b$ as their immediate ancestor.
\item
If $u$ is of death-type (\cref{fig:event_types}B), one or more tip nodes of the appropriate demes are selected with uniform probability from among those present.
These are deleted.
Next, internal nodes without children are recursively removed.
Sample nodes are never removed.
\item
At a migration-type event (\cref{fig:event_types}C), the appropriate number of migrating lineages are selected at random with uniform probability, from among those present in the appropriate demes.
For each selected lineage, one new branch node is inserted between the selected tip node and its ancestor.
The color of the descendant branch changes accordingly.
\item
At a sample-type event (\cref{fig:event_types}D), the appropriate number of sampled lineages are selected at random from among the tip nodes, with uniform probability according to deme.
One new sample node is introduced for each selected lineage:
each is inserted between a selected tip nodes and its ancestor.
\item
At a neutral-type event (\cref{fig:event_types}E), no change is made to the genealogy.
\item
Finally, events of compound type (\eg \cref{fig:event_types}F--H) are accommodated by combining the foregoing rules.
\end{compactenum}
In each of these events, the new node or nodes that are introduced have node-times equal to the time of the jump.
\subsubsection{Emergent lineages and production}
\label{sec:production}
The lineages which descend from an inserted node are said to \emph{emerge} from the event.
Thus, after a birth-type event, the emerging lineages include all the new offspring as well as the parent.
Likewise, at pure migration- or sample-type events, each migrating or sampled lineage emerges from the event.
At pure death-type events, no lineages emerge.
In general, at an event of mark $u$, there are $r^u_i$ emergent lineages in deme $i$.
We require that $r^u_i$ be a constant, for each $u$ and $i$.
Thus there is a function $r:\Jumps\times\Demes\to\Zp$, such that $r^u_i$ lineages of deme $i$ emerge from each event of mark $u$.
Since, in applications, one is free to expand the set of jump-marks $\Jumps$ as needed, this is not a restriction on the models that the theory can accommodate.
We say $r^u\coloneq{(r^u_i)_{i\in\Demes}}$ is the \emph{production} of an event of mark $u$.
Note that the lineages that die as a result of an event do not count in the production but that a parent lineage that survives the event does count.
\subsubsection{Conditional independence and exchangeability}
Application of these rules at each jump of $\Xr_t$ constructs a chain of genealogies $\Grh_k$.
In particular, at each jump-time $\Trh_k$, the genealogy $\Grh_{k-1}$ is modified according to the jump-mark $\Urh_k$ to yield $\Grh_k$.
We view $\Grh_k$ as the embedded chain of the continuous-time genealogy process $\Gr_t$.
It is very important to note that, conditional on $(\Xrh_k,\Urh_k)$, the number of parents and number of offspring in each deme is determined and the random choice of which lineages die, migrate, are sampled, or sire offspring is independent of these choices at any other times and independent of $(\Xrh_j,\Urh_j)$ for all $j\ne{k}$.
Moreover, by assumption, the lineages within each deme are exchangeable:
any lineage within a deme is as likely as any other lineage in that deme to be selected as a parent or for death, sampling, or migration.
Finally, note that $\Gr_t$ does not have the Markov property, though $(\Xr_t,\Ur_t,\Gr_t)$ and $(\Xr_t,\Gr_t)$ do.
Observe in passing that, if instead of dropping tip nodes at death events we were to retain them as we do samples, the resulting genealogy---which we might call the ``complete'' genealogy---would have the Markov property.
\subsection{Pruned and obscured genealogies}
\begin{figure}
<<upo,fig.dim=c(4,6),out.width="50%">>=
simulate(
"SEIR",
Beta=1,sigma=0.5,gamma=0.1,psi=0.4,omega=0.1,
S0=10,E0=1,I0=1,R0=0,
time=10
) |>
freeze(seed=522390503) -> x
pal <- c("#00274CFF","#FFCB05FF")
plot_grid(
A=x |>
plot(
points=TRUE,prune=FALSE,obscure=FALSE,
ladderize=FALSE,palette=pal
)+
geom_vline(xintercept=10,linewidth=0.2,color="black"),
B=x |>
plot(
points=TRUE,prune=TRUE,obscure=FALSE,
ladderize=FALSE,palette=pal
)+
geom_vline(xintercept=10,linewidth=0.2,color="black"),
C=x |>
plot(
points=TRUE,prune=TRUE,obscure=TRUE,
ladderize=FALSE,palette="#B3B3B3FF"
)+
geom_vline(xintercept=10,linewidth=0.2,color="black"),
ncol=1,
align="hv",axis="tblr",
labels="AUTO"
)
@
\caption{
Unpruned, pruned, and obscured genealogies from a single realization of the genealogy process induced by the SEIRS model depicted in \cref{fig:example_models,fig:markov_state}.
\textbf{(A)} A realization of the unpruned genealogy process $\Gr_t$ is shown at $t=10$.
Tip nodes, corresponding to lineages alive at time $t=10$ are indicated with black points.
Blue points represent samples;
green points, internal nodes.
Branches are colored according to the deme in which the corresponding lineage resided at that point in time:
blue denotes $\lab{E}$ and yellow, $\lab{I}$.
\textbf{(B)} The genealogy is \emph{pruned} by deleting all tip nodes and then recursively pruning away childless internal nodes.
Sample nodes are never removed.
\textbf{(C)} A pruned genealogy is \emph{obscured} by effacing all deme information from lineage histories:
the colors are erased, as are all inline nodes.
See the text (\cref{sec:genealogy,sec:pruning,sec:obscuration}) for more detail.
\label{fig:upo}
}
\end{figure}
The process just described yields a genealogy that relates all extant members of the population, and all samples.
Moreover, it details each lineage's complete history of movement through the various demes.
However, the data we ultimately wish to analyze will be based only on samples.
Nor, in general, will the histories of deme occupancy be observable.
A generative model must account for this loss of information.
We therefore now describe how genealogies are \emph{pruned} to yield sample-only genealogies and then \emph{obscured} via the erasure of color from their branches (\cref{fig:upo}).
\subsubsection{Pruned genealogy}
\label{sec:pruning}
Given a genealogy $G$, one obtains the \emph{pruned genealogy}, $P=\prune(G)$ by first dropping every tip node and then recursively dropping every childless internal node (\cref{fig:upo}A--B).
In a pruned genealogy only internal and sample nodes remain, and sample nodes are found at all of the leaves and possibly some of the interior nodes of the genealogy.
Observe that a pruned genealogy is a colored genealogy:
it retains information about where among the demes each of its lineages was through time (\cref{fig:upo}B).
Note also that a pruned genealogy $P$ is characterized by its time, $\time(P)$ and the functions $P^{\lab{Y}}$ and $P^{\lab{Z}}$ just as an unpruned genealogy is.
Finally, observe that, since it contains within itself all of its past history, the pruned genealogy process $\Pr_t=\prune(\Gr_t)$ is Markov, even though the unpruned genealogy process, $\Gr_t$, is not.
\subsubsection{Lineage count and saturation}
\label{sec:ells}
In the following, we will find that we need to count the deme-specific numbers of lineages present in a given pruned genealogy at a given time.
Accordingly, suppose $P=(T,Z,Y)$ is a pruned genealogy and suppose $t\in[0,T]$.
Let $\ell_i$ denote the number of lineages in deme $i$ at time $t$ and $\ell\coloneq(\ell_i)_{i\in\Demes}\in\Zp^{\Demes}$.
Clearly, $\ell$ depends only $Y_t$.
Therefore, we can define $\ell$ as a function such that, whenever $P=(T,Z,Y)$ is a pruned genealogy, $\ell(Y_t)$ is the vector of deme-specific lineage counts at time $t$.
We refer to $\ell$ as the \emph{lineage-count} function (cf.~\cref{fig:ells}).
We will also have occasion to refer to the deme-specific number of lineages emerging from a given event.
In particular, given a node time $t$ in a pruned genealogy $P=(T,Y,Z)$, the number $s_i$ of lineages of deme $i$ emerging from all nodes with time $t$ is well defined and we can write $s\coloneq\left(s_i\right)_{i\in\Demes}$.
Like the lineage-count function, $s$ depends only on the local structure of $\P$.
However, $s$ depends not only on $Y_t$, but also on $\leftlim{Y}_t$.
Thus, we can define the \emph{saturation} function such that, whenever $P=(T,Y,Z)$ is a pruned genealogy, $s(\leftlim{Y}_t,Y_t)$ is the integer vector of deme-specific numbers of emerging lineages at time $t$.
\Cref{fig:ells} illustrates.
\begin{figure}
\input{figs/ells}
\caption{
\textbf{Lineage count and saturation.}
Each panel shows the neighborhood of a single event in the unpruned genealogy (top row) and the corresponding pruned genealogy (bottom row).
Pruning consists of the removal of all branches that are not ancestral to some sample.
In the bottom row of panels, pruned branches are indicated using broken lines.
\textbf{(A)} A birth-type event with production $r=(r_{\lab{blue}},r_{\lab{yellow}})=(1,1)$ occurs.
\textbf{(B)} Suppose that pruning results in the removal of the dashed lineages.
Then the lineage count at this event-time is $\ell=(\ell_{\lab{blue}},\ell_{\lab{yellow}})=(2,2)$.
The saturation is $s=(0,1)$ since only a single, yellow lineage emerges from the event.
\textbf{(C)} A migration-type event with production $r=(0,1)$ occurs.
\textbf{(D)} After pruning, $\ell=(2,2)$ and $s=(0,1)$.
\textbf{(E)} A sample-type event occurs in which two blue lineages are sampled (production $r=(2,0)$).
\textbf{(F)} After pruning, $\ell=(2,2)$ and $s=(1,0)$.
Observe that in panels B and D, the local structures of the pruned genealogies are identical, though they arise from events of different type.
\label{fig:ells}
}
\end{figure}
\subsubsection{Compatibility}
\label{sec:compatibility}
Suppose $P$ is a pruned genealogy, with $\time(P)=T$ and $t\in\event{P}$.
The local structure of $P$ at $t$ is, in general, compatible with only a subset of the possible jumps $\Jumps$.
For example, if the event in $P$ at $t$ is a branch node or a sample node, then it is compatible only with birth-type or sample-type jumps, respectively.
Similarly, if the node in $P$ at time $t$ is one at which a lineage moves from deme $i$ to deme $i'$, then $u$ must be either of $i\to{i'}$ migration type or of a birth type with parent in $i$ and $r^u_{i'}>0$.
To succinctly accommodate all possibilities, let us introduce the indicator function $Q$ such that $Q=1$ if the local genealogy structure---which is captured by the values of $P^{\lab{Y}}$ just before and after $t$---is compatible with an event of type $u$ and $Q=0$ otherwise.
That is, $Q_u(y,y')=1$ if and only if
there is a feasible genealogy, $\G=(\T,\Z,\Y)$, and history, $\H$,
and a $t\in{[0,\T]}$ such that,
given $\Gr_\T=\G$ and $\Hr_\T=\H$,
we have $\U_t=u$, $\Yt_t=y$, and $\Y_t=y'$.
We refer to $Q$ as the \emph{compatibility indicator}.
\subsubsection{Obscured genealogy}
\label{sec:obscuration}
The \emph{obscured genealogy} is obtained by discarding all information about demes and events not visible from the topology of the tree alone (\cref{fig:upo}B--C).
In particular, if $P=(T,Z,Y)$ is a pruned genealogy, we write $\obs(P)=(T,Z)$ to denote the obscured genealogy.
\section{Results}
\subsection{Likelihood for pruned genealogies}
Our first result will be an expression for the likelihood of a given pruned genealogy given the history of the population process.
\begin{thm}\label{thm:pruned_lik}
Suppose $\P=(\T,\Z,\Y)$ is a given pruned genealogy.
Define
\begin{equation}\label{eq:phidef}
\phi^{}_u(x,y,y')\coloneq\BinRatio{n(x)}{\ell(y')}{r^{u}}{s(y,y')}\,Q_{u}(y,y'),
\end{equation}
where $n$ is the deme occupancy (\cref{sec:demes}), $r^u$ is the production (\cref{sec:production}), $\ell$ and $s$ are the lineage-count and saturation functions, respectively (\cref{sec:ells}), $Q$ is the compatibility indicator (\cref{sec:compatibility}), and the binomial ratio is as defined in \cref{sec:binomial_ratio}.
Then
\begin{equation*}
\CondProb{\Pr_\T=\P}{\Hr_\T=\H}=\Indicator{\event{\H}\supseteq{\event{\P}}}\,\prod_{t\in\event{\H}}{\phi^{}_{\U_t}\!(\X_t,\Yt_t,\Y_t)}.
\end{equation*}
\end{thm}
\begin{proof}
If $\event{\H}\nsupseteq\event{\P}$, then $\H$ and $\P$ are incompatible and $\CondProb{\Pr_\T=\P}{\Hr_\T=\H}=0$.
Similarly, if any event of $\H$ is incompatible with the local structure of $\P$ in the sense of \cref{sec:compatibility}, then $\CondProb{\Pr_\T=\P}{\Hr_\T=\H}=0$.
Let us therefore suppose that neither of these conditions hold.
Conditional on $\Hr_\T=\H$, at each time $t\in\event{\H}$, a jump of mark $\U_t$ occurred, with a production of $r^{\U_t}=(r_i)_{i\in\Demes}$, resulting in a deme-occupancy of $n(\X_t)=(n_i)_{i\in\Demes}$.
In $\P$, at time $t$, there are $\ell_i=\ell_i(\Y_t)$ lineages in deme $i$, of which $s_i=s_i(\Yt_t,\Y_t)$ are emergent.
By assumption, at each genealogical event, lineages within a deme are exchangeable:
each has an identical probability of being involved.
This exchangeability implies that each lineage present in a deme at time $t$ was equally likely to have been one of the emergent lineages.
In particular, at time $t$, the probability that $s_i$ of the $\ell_i$ deme-$i$ lineages were among the $r_i$ of $n_i$ lineages emergent in the unpruned genealogy process is the same as the probability that, upon drawing $\ell_i$ balls without replacement from an urn containing $r_i$ red balls and $n_i-r_i$ black balls, exactly $s_i$ of the drawn balls are red, namely
\begin{equation*}
\frac{\binom{n_i-\ell_i}{r_i-s_i}\,\binom{\ell_i}{s_i}}{\binom{n_i}{r_i}}.
\end{equation*}
Because our lineages are labeled, each of the $\tbinom{\ell_i}{s_i}$ equally probable sets of $s_i$ lineages is distinct;
just one of these is the one present in $\P$.
Moreover, since, again conditional on $\Hr_\T=\H$, the identities of the lineages involved in a genealogical event are random and independent of the identities selected at all other events, we have established that
\begin{equation*}
\CondProb{\Pr_\T=\P}{\Hr_\T=\H}=\prod_{t\in\event{\H}}{\BinRatio{n(\X_t)}{\ell(\Y_t)}{r^{\U_t}}{s(\Yt_t,\Y_t)}}.
\end{equation*}
Returning to the possibility that $\H$ is incompatible with $\P$, since $\Prob{\Pr_\T=\P}=0$ if either any $Q^{}_{\U_t}=0$ or $\event{\P}\nsubseteq\event{\H}$, we obtain the result.
\end{proof}
Next, we show how the likelihood of a pruned genealogies, unconditional on the history, can be computed.
For this, we use the filter equation technology developed in \cref{sec:filter_eqns}.
In particular, the following theorem follows immediately from \cref{lemma:sing-filt}.
\begin{thm}
\label{thm:pruned_uncond}
Suppose that $\P=(\T,\Z,\Y)$ is a given pruned genealogy.
Suppose that $w=w(t,x)$ satisfies the initial condition $w(0,x)=p_0(x)$ and the filter equation
\begin{equation}
\begin{aligned}
\frac{\partial{w}}{\partial{t}}(t,x)=
&\sum_u{\int{w(t,x')\,\alpha_u(t,x',x)\,\phi^{}_u(x,\Yt_t,\Y_t)\,\dd{x'}}}
-\sum_u{\int{w(t,x)\,\alpha_u(t,x,x')\,\dd{x'}}},
&t\notin{\event{\P}},\\
w(t,x)=&\sum_u{\int{\wt(t,x')\,\alpha_u(t,x',x)\,\phi^{}_u(x,\Yt_t,\Y_t)\,\dd{x'}}},
&t\in{\event{\P}},
\end{aligned}
\end{equation}
where $\phi$ is defined in \cref{eq:phidef}.
Then the likelihood of $\P$ is
\begin{equation*}
\lik(\P)=\int{w(T,x)\,\dd{x}}.
\end{equation*}
\end{thm}
\subsection{Likelihood for obscured genealogies}
Our next result concerns the likelihood of a given obscured genealogy conditional on the history.
\begin{thm}\label{thm:obsc_lik}
Suppose that $(\T,\Z)$ is a given obscured genealogy.
Let $q$ and $\pi$ be probability kernels, such that
for all $x\in\Xspace$ and $y\in\func{Y}_0(\Z)$,
\begin{equation*}
\begin{gathered}
q(x,y)\ge{0},\qquad
\sum_{y\in\func{Y}_0(\Z)}{q(x,y)}=1,
\end{gathered}
\end{equation*}
and, for all $u\in\Jumps$, $t\in\Rp$, $x,x'\in\Xspace$, $y,y'\in\func{Y}_t(\Z)$,
\begin{equation*}
\begin{gathered}
\pi_u(t,x,x',y,y')\ge{0},\qquad
\sum_{y'\in\func{Y}_t(\Z)}{\pi_u(t,x,x',y,y')}=1.
\end{gathered}
\end{equation*}
Suppose moreover that $\pi_u(t,x,x',y,y')>0$ whenever $\alpha_u(t,x,x')\,Q_u(y,y')>0$
and that $q(x,y)>0$ whenever $\CondProb{\Pr_0^{\lab{Y}}=y}{\Xr_0=x}>0$.
Then there is a stochastic jump process $\yr_t$ with sample paths in $\func{Y}(\Z)$ such that $(\Xr_t,\Ur_t,\yr_t)$ is Markov and
\begin{equation*}
\CondProb{\Pr^{\lab{Z}}_\T=\Z}{\Hr_\T=\H}=
\Indicator{\event{\H}\supseteq\event{\Z}}\,\Expect{\frac{1}{q(X_0,\yr_0)}\,\prod_{t\in\event{\H}}{\frac{\phi^{}_{\U_t}(\X_t,\yrt_t,\yr_t)}{\pi_{\U_t}(t,\Xt_t,\X_t,\yrt_t,\yr_t)}}},
\end{equation*}
where $\phi$ is defined in \cref{eq:phidef} and
the expectation is taken over the sample paths of $\yr_t$.
\end{thm}
\begin{proof}
First, observe that, since $\obs$ is a deterministic operator,
\begin{equation}\label{eq:IS1}
\CondProb{\Pr^{\lab{Z}}_\T=\Z}{\Hr_\T=\H}=\CondExpect{\Indicator{\Pr^{\lab{Z}}_\T=\Z}}{\Hr_\T=\H}.
\end{equation}
Our strategy will be to evaluate \cref{eq:IS1} using importance sampling:
we will propose pruned genealogies compatible with $\Z$ as sample paths from a stochastic process driven by $\Xr_t$ and
evaluate the the expectation in \cref{eq:IS1} by summing over these paths.
Conditional on $\Hr_\T=\H$, the initial distribution $q$ and probability kernel $\pi$ generate a Markov chain, $\yrh_k$ such that
\begin{equation*}
\begin{gathered}
\CondProb{\yrh_0}{\Hr_\T=\H}=q(\X_0,\yrh_0),
\qquad
\CondProb{\yrh_k}{\yrh_{k-1},\Hr_\T=\H}=\pi_{\Uh_k}(\Th_k,\Xh_{k-1},\Xh_{k},\yrh_{k-1},\yrh_k).
\end{gathered}
\end{equation*}
The required process $\yr_t$ is the unique \cadlag\ process with event times $\Th_k$ and $\yrh_k$ as its embedded chain.
This construction of $\yr_t$ obviously guarantees that $\event{\H}\supseteq\event{\yr}\supseteq\event{\Z}$ and that $(\Xr_t,\Ur_t,\yr_t)$ is Markov.
Now, for $\y\in\func{Y}(\Z)$, let us define $C(\y)=(\T,\Z,\y)$.
Then, by construction, $\obs(C(\y))=(\T,\Z)$ and,
conversely, for every pruned genealogy $\P$ satisfying $\time(\P)=\T$ and $\P^{\lab{Z}}=\Z$, $C(\P^{\lab{Y}})=\P$.
Moreover, the conditions on the kernels $q$ and $\pi$ guarantee that, if $\CondProb{\Pr_\T=\P}{\Hr_\T=\H}>0$ and $\P^{\lab{Z}}=\Z$, then $\CondProb{\yr=\P^{\lab{Y}}}{\Hr_\T=\H}>0$.
We therefore have that
\begin{equation*}
\CondProb{\Pr^{\lab{Z}}_\T=\Z}{\Hr_\T=\H}=
\Expect{\frac{\CondProb{\Pr_\T=C(\yr)}{\Hr_\T=\H}}{\pi(\yr\vert\H)}},
\end{equation*}
the expectation being taken with respect to the random process $\yr$.
Here, by definition,
\begin{equation*}
\pi(\yr\vert\H)=q(\X_0,\yr_0)\,\prod_{t\in\event{\H}}{\pi_{\U_{t}}(t,\Xt_{t},\X_{t},\yrt_{t},\yr_{t})}.
\end{equation*}
The result then follows from \cref{thm:pruned_lik}.
\end{proof}
Note that, since $\func{Y}_t(\Z)$ is finite, it is permissible, for example, to choose $q$ and $\pi$ to be uniform.
The final result shows how to compute the likelihood of an obscured genealogy.
It is an immediate consequence of \cref{thm:obsc_lik,lemma:sing-filt}.
\begin{thm}
\label{thm:obsc_uncond}
Let $V=(\T,\Z)$ be a given obscured genealogy.
Then there are probability kernels $q$ and $\pi$ as in \cref{thm:obsc_lik} such that if
\begin{equation*}
\begin{gathered}
\beta_u(t,x,x',y,y')=\alpha_u(t,x,x')\,\pi_u(t,x,x',y,y'),\qquad
\varPsi_u(t,x,x',y,y')=\frac{\phi^{}_u(x',y,y')}{\pi_u(t,x,x',y,y')},
\end{gathered}
\end{equation*}
and if $w=w(t,x,y)$ satisfies
the initial condition $w(0,x,y)=p_0(x)\,\Indicator{q(x,y)>0}$
and the filter equation
\begin{equation*}
\begin{aligned}
&\frac{\partial{w}}{\partial{t}}=
\sum_{uy'}{\int{w(t,x',y')\,\beta_u(t,x',x,y',y)\,\varPsi_u(t,x',x,y',y)\,\dd{x'}}}
-\sum_{uy'}{\int{w(t,x,y)\,\beta_u(t,x,x',y,y')\,\dd{x'}}},
&t\notin{\event{\Z}},\\
&w(t,x,y)=\sum_{uy'}{\int{\wt(t,x',y')\,\beta_u(t,x',x,y',y)\,\varPsi_u(t,x',x,y',y)\,\dd{x'}}},
&t\in{\event{\Z}},
\end{aligned}
\end{equation*}
then the likelihood of $V$ is
\begin{equation*}
\lik(V)=\sum_y{\int{w(T,x,y)\,\dd{x}}}.
\end{equation*}
\end{thm}
\Cref{lemma:monte_carlo} shows how this can be computed via Sequential Monte Carlo.
\section{Discussion}
The theory presented here represents a strict generalization of the existing coalescent and birth-death process approaches to phylodynamic inference.
In \cref{sec:app-examples}, we demonstrate that both of the latter processes are special cases of the genealogical processes constructed here.
Importantly, because the theory allows computation of the likelihood via strictly forward-in-time computations, it permits consideration of models for which time-reversal arguments are not available.
Moreover, inasmuch as the formulae of \cref{thm:obsc_uncond} can be efficiently computed via sequential Monte Carlo, explicit expressions for transition probabilities are not needed:
it is sufficient to be able to simulate from the population process.
This feature of the algorithms---known as the \emph{plug-and-play property} \citep{He2010}---further expands the class of population models that can be confronted with data.
In particular, the theory gives us the freedom to choose models with many demes.
For deterministic population models, \citet{Volz2012} and \citet{Rasmussen2014a} showed how one could accommodate discrete population structure.
Their procedures involve solving a large number of differential equations backward in time, relying on the time-reversibility of deterministic dynamics.
In general, this time-reversibility is not a property of stochastic processes.
Some existing methods put rather severe limits on the form of the sampling model and, as \citet{Volz2014a} pointed out, misspecification of the sampling model can lead to large inferential biases.
With the theory presented here, essentially arbitrary specification of the sampling model is possible.
In particular, one can posit sampling at a rate which is an arbitrary function of time and state and include discrete sampling events as well.
It is also possible to condition on the existence of samples.
If Sequential Monte Carlo algorithms are used to compute the likelihoods of \cref{thm:obsc_uncond}, then it is straightforward to simultaneously assimilate information from both time-series and genealogical data.
One can therefore supplement traditional incidence, disease, or mortality time series with genealogical data in an inferential exercise.
A limitation of the theory is that the population models are assumed to be pure jump processes, which allows consideration of demographic stochasticity and environmental stochasticity modeled by jumps involving multiple individuals \citep{Breto2011}, but disallows stochastic processes with a diffusive component.
It should be possible to incorporate of the full range of Markovian environmental stochasticity via extension of this theory to population models containing both diffusion and jump components.
The price of the theory's flexibility is primarily computational.
When Sequential Monte Carlo is used to evaluate the likelihood in \cref{thm:obsc_uncond}, the computational effort scales linearly with the number of samples.
In its most straightforward implementation---using an event-driven algorithm \citep[\eg][]{Gillespie1977a}---it scales nonlinearly with population size in general.
However, stochastic simulation schemes are available that scale independently of population size \citep{Higham2008}.
On the other hand, the importance sampling underlying \cref{thm:obsc_uncond} will in general require effort that is exponential in the number of demes.
For models with many demes, therefore, approaches for ameliorating or circumventing this curse of dimensionality may be necessary.
Critically, the substantial freedom one has in the choice of the importance-sampling distribution $\pi$ can be exploited for this purpose.
In particular, since it is permissible to ``borrow information'' from the future by means of the importance sampling, there is hope for highly efficient algorithmic computation.
\section*{Acknowledgments}
This work was supported by grants from
the U.S. National Institutes of Health, (Grant \#1R01AI143852 to AAK, \#1U54GM111274 to AAK and ELI)
and a grant from the Interface program, jointly operated by the U.S. National Science Foundation and the National Institutes of Health (Grant \#1761603 to ELI and AAK).
QL acknowledges the support of the Michigan Institute for Data Science.
\bibliographystyle{preprint}
\bibliography{phylopomp}
\appendix
\setcounter{equation}{0}
\setcounter{figure}{0}
\setcounter{table}{0}
%%\setcounter{tcbcounter}{0}
\titleformat{\section}[hang]{\large\bfseries}{Appendix \periodafter\thesection}{2ex}{\periodafter}{}
\renewcommand{\theequation}{\thesection\arabic{equation}}
\renewcommand{\thefigure}{\thesection\arabic{figure}}
\renewcommand{\thetable}{\thesection\arabic{table}}
%%\renewcommand{\thetcbcounter}{\thesection\arabic{tcbcounter}}
\section{Filter equations}
\label{sec:filter_eqns}
The likelihoods that appear in \cref{thm:pruned_uncond,thm:obsc_uncond} are integrals over large sets of histories.
As such, explicit expressions for them are not available, and we require mathematical tools to allow us to manipulate these quantities and devise algorithms for their numerical solution.
The \emph{filter equations} we introduce here are suitable for these purposes, and we devote this appendix to exposing their essential properties.
This extremely convenient formalism has, to our knowledge, not been thoroughly exploited, though we note their resemblance to the constructions of \citet{Ogata1978}, \citet{Puri1986}, \citet{Kliemann1990}, and \citet{Giesecke2018}.
\begin{defn}
Let $\Xr_t$ be a continuous-time Markov process with KFE
\begin{mathsize}{9pt}{10pt}
\begin{equation}
\label{eq:kfe2}