Monday, November 2, 2026

What to watch for Election Night 2026

Here's what I am watching (all times are Pacific time, because that's my time zone):

4:00pm Florida

(1/2) FL-14 [AP] (redistricted from Harris +8 to Trump +11); if incumbent Representative Kathy Castor (Dem) wins re-election, this should indicate redistricting efforts Republicans pushed will not bear fruit

(2/2) FL-25 [AP] (redistricted from Harris +4 to Trump +9), most expensive in the nation. Among other things, this will tell us how far money talks in this election cycle.

4:00pm South Carolina Senate race [AP] If Republican incumbent Darline Graham loses, then it portends a bad night for Republicans.

4:30pm Ohio Senate race [AP] Democratic candidate (and former Senator) Sherrod Brown has a slight lead in the polls, but Ohio has been solidly red in the past several elections

5:00pm Texas Senate race (counts ballots faster than Ohio) [AP] this should tell us if the polls are alright or not: if Democratic challenger James Talarico wins, expect a wild night favoring Democrats

6:00pm Virginia (polls close at 4:00pm but tight races won't be called for two hours or so)

(1/3) VA-01 [AP] (Trump +5 seat) incumbent Republican; if Democrats flip this seat, then they are in for a very good night

(2/3) VA-05 [AP] (Trump +12 seat) incumbent Republican; if Democrats flip this seat, then they are in for a great night

(3/3) VA-02 [AP] (Trump +0.2, incumbent Republican Rep Jen Kiggans +3.8) could tell us if a strong Republican candidate could survive a Democratic wave; it is widely considered the "most competitive" race in the nation [according to the Cook Political Report]

???? Kentucky's 6th district [AP] (polls close at 3pm PT but takes a relaxed approach to counting ballots)

Monday, June 20, 2022

Introduction to Ecological Inference

Consider the election for some office the United States. The voters are organized into precincts. For the 2020 presidential election, there were a total of 176,933 precincts or equivalents (according to the United States Election Assistance Commission report). The voting age population in 2020 would be approximately 256,662,010 people (as reported in the Federal Register). We obtain an average of 1450.6 voting-age individuals per precinct.

Generic Puzzle: How did [candidate] perform with [demographic of voters] in [given election]?

Since voting data is private, it's impossible to figure this out with certainty. But there are a number of statistical tools we can use to answer the question. We will look at ecological inference today.

Puzzle 1: How many women voted for Biden (or Trump)? How many men voted for Biden (or Trump)?

There were approximately 132,408,924 women adults in 2020, and approximately 124,253,086 men adults. The FEC reports 158,383,403 votes were cast in the 2020 presidential election. That makes voter turnout approximately 66.20074%, but we do not know its composition in terms of men and women.

If we consider precinct $i$, we could write down a table of the fraction of the turnout who were women $\beta^{f}_{i}$, the fraction of the turnout who were men $\beta^{m}_{i}$, the proportion of the population of the precinct which are women $X_{i}$, and the voter turnout $T_{i}$ (as a fraction) in the following handy table:

Demographic Voted (fraction) Did not vote (fraction) Total
Women$\beta^{f}_{i}$$1-\beta^{f}_{i}$$X_{i}$
Men$\beta^{m}_{i}$$1-\beta^{m}_{i}$$1-X_{i}$
$T_{i}$$1-T_{i}$

We have the following useful identity \begin{equation}\tag{1} T_{i} = X_{i}\beta^{f}_{i} + (1 - X_{i})\beta^{m}_{i}. \end{equation} To convince ourselves of this, suppose we had $N_{i}$ adults in precinct $i$, $F_{i}$ of which are females, and that $V_{i}$ votes were case in the precinct, $V_{i}^{f}$ being cast by female voters. Then $\beta^{f}_{i}=V^{f}_{i}/F_{i}$ and $X_{i} = F_{i}/N_{i}$, multiplying through gives $\beta^{f}_{i}X_{i}=V^{f}_{i}/N_{i}$ the number of votes case by women relative to the precinct's population; when we combine it with $\beta^{m}_{i}(1 - X_{i}) = (V_{i} - V^{f}_{i})/N_{i}$, we recover $T_{i} = V_{i}/N_{i}$ the voter turnout as a fraction of the precinct's population. So far, so good? Good!

Now the name of the game is determine $\beta^{f}_{i}$ and $\beta^{m}_{i}$.

But this is an underdetermined system: we have 2 unknowns per precinct, and 1 equation per precinct. This is a fundamental weakness of ecological inference known as the Inderminacy problem. It's a serious problem, because we can "cook the books" to infer whatever we want. But let us try to soldier on, and see what we can determine.

Method of Bounds

For simplicity, I will be treating the entire United States as a single precinct. If you find this dodgy, well, the more sophisticated techniques of ecological inference stipulates worse, so buckle up.

We can place some bounds on $\beta^{f}$ (I'm dropping the index tracking precincts, since there's only one). If every man who could vote did vote, then we would have \begin{align} \frac{T - (1 - X)}{X} &= \frac{(V/N) - (N-F)/N}{F/N} \tag{2a} \\ &= \frac{V - (N-F)}{F}\leq\beta^{f}. \tag{2b} \end{align} The number of votes not cast by a man $V - (N-F)$ relative to the population of adult women $F$ would be the lower bound for female voter turnout. This works, provided $V-(N-F)\gt0$ (there are more votes than men). To handle the other case, we need \begin{equation}\tag{3} \max\left(\frac{T - (1 - X)}{X}, 0\right)\leq\beta^{f}. \end{equation} When working this out, we find the lower bound to be empirically \begin{equation}\tag{4} 0.32888\leq\beta^{f} \end{equation} at least 32.8% of voting-age females cast a ballot in 2020.

Likewise, we can derive an upperbound where only women cast ballots (which makes sense when $F\gt V$ there are more women than votes): \begin{equation}\tag{5} \min(T/X, 1) \geq\beta^{f}. \end{equation} Empirically, there were more votes than women, so \begin{equation}\tag{6} 0.3288\leq\beta^{f}\leq 1. \end{equation} This isn't terribly enlightening, somewhere between 32.8% and 100% of voting age females cast a ballot in 2020. (The bounds on male voter turnout is similarly between 31.9% and 100%.)

If we want something more, we need to supply additional constraints by hand. For example, the difference between voter turnout by sex is bounded by 10% empirically, so this would constrain the space of possibilities further. But we are now bringing in our own prior beliefs: the data doesn't tell us the difference between voter turnout is bounded by 10% empirically, I literally just made it up because it sounds plausible.

Had we precinct-level data, we could take a weighted average of these bounds to infer district-level turnout by sex. Perhaps we will work through state-level considerations using county-level data in a future post.

The other thing I should point out is that the interval \begin{equation}\tag{7} \beta^{f}\in\left[\max\left(\frac{T - (1 - X)}{X}, 0\right),\; \min(T/X, 1)\right] \end{equation} is a 100% confidence interval. This fact isn't really taken advantage of sufficiently, in my opinion, but taking advantage of it requires imposing our beliefs on the statistics, which allows us to conclude anything we want.

Goodman's Regression Approach

Another approach is to start with our first identity \begin{equation}\tag{1} T_{i} = X_{i}\beta^{f}_{i} + (1 - X_{i})\beta^{m}_{i}. \end{equation} We then regress $T_{i}$ against $X_{i}$. This will produce district-level estimates $B^{f}$ (and $B^{m}$) of the turnout by sex.

This is a linear regression, so a couple of caveats are worth noting:

  1. The estimates may produce unreasonable results, violating the deterministic bounds. In fact, you should expect the estimates to be biased (in the technical, statistical sense).
  2. There is an explicit assumption of constant covariance, which means the composition of a precinct does not affect voter turnout or voting behaviour. This may be reasonable superficially, but urban precincts tend to behave differently than rural precincts, and this could produce unreasonable results.

King's Approach

We can take some combination of the deterministic approach and Goodman's regression, to restrict values to $0\leq B^{f}\leq 1$ and likewise for men. That is to say, the coefficients (when plotted against each other) live in the unit square. (Or, for demographics with $n$-categories, like age, the unit $n$-cube.)

We transform the identity at the heart of Goodman's approach into the form: \begin{equation}\tag{8} \beta^{m}_{i} = \left(\frac{T_{i}}{1-X_{i}}\right) - \left(\frac{X_{i}}{1-X_{i}}\right)\beta^{f}_{i}. \end{equation} We can then plot a line in the unit square, since we know the $X_{i}$ and $T_{i}$, and this produces a distribution of possible values for the $\beta^{m}_{i}$ and $\beta^{f}_{i}$ parameters. In order for us to extract information, we need to make three statistical assumptions.

Probably the most severe assumption in this approach is the demand of spatial homogeneity: the conditional random variable $T_{i}|X_{i}$ are independent of observations. This sounds fine, but it stipulates rural voters behave indistinguishably from urban voters (and other demographics not considered behave indistinguishably from each other).

We tend to believe this is not the case (according to polling, election results, etc.). So we need to be careful about the domain of validity for King's regression.

The next assumption we need to make is that there are no cluster points. In other words, we will be using a bivariate truncated normal distribution (or if there are $n$ demographic categories, an $n$-variate truncated normal distribution).

The criticism for this assumption is that there's no reason to believe a truncated multivariate normal distribution is more appropriate than any other probability distribution on the unit cube. Arguably, it's not; Jaynes would argue we should use a entropy maximizing distribution, for example. There's merit to Jaynes's argument: we are imposing a subjective prior belief onto our statistical analysis by choosing some probability distribution. We need to appeal to some statistical principle, or prove the results are independent of prior, or...

The last assumption we need to make is that there is no a priori aggregation bias; i.e., $X_{i}$ is [mean] independent of $\beta^{f}_{i}$ and $\beta^{m}_{i}$.

I don't have much to say about this, because King developed another model which weakens this condition (and let's us measure violations of it).

When the deterministic bounds on the demographic category of interest is relatively tight, all results tend to coincide. But when the bounds are large (like our example with voter turnout by sex being anywhere between 30% to 100%), the conclusions drawn are largely model-dependent. This subtlety can lead to contradictory results.

Concluding Remarks

These three approaches constitute the "trunk" of ecological inference, from which we can form "branches" useful for whatever problem we're interested in. King really deserves credit for rejuvenating the tool, and a lot of modern work generalizes his approach.

But we should also realize there are many incredibly subtle (and easy to miss) opportunities for us to derive results which we were looking for ab initio. For this reason alone, it should be tested against other methods like Bayesian multilevel regression (with or without post-stratification), or even simpler methods when possible. It's easy to shoot yourself in the foot with ecological inference, and it's eager to do it, too.

Again, it is worth stressing: inferences drawn from ecological inference are either obvious or model-dependent. It's easy to impose your pre-existing beliefs onto the model without realizing it. You really shouldn't be using this for election analysis.

Sunday, May 16, 2021

Review: Kalman Filtered Senate Polls

Previously, we discussed Kalman filtering the polls. We will examine how well such a filter performed in the 2020 US Senate races.

Implementation Details

The basic details of the Kalman filter may be found in the previous blog post, here I just review some of the decisions I've made when implementing it in practice:

Polling Date. We treat the date for a poll as the midpoint between its start and end dates. To be clear, we are truncating timestamps to dates.

Polls are 4-vectors. We treat a poll as giving 4 data points: the percentage support for the Democratic candidate, the Republican candidate, all third-party candidates, and the undecided voters.

Third Parties. I treated all third parties as a single candidate. For polls which do not ask about third-party voters, we treat them as the margin of error.

Pooling the Polls. Following Jackman's "Pooling the Polls", we take a precision-weighted average of polls concluding on the same day. This amounts to, for a single poll released on a given end date, renaming the variables and computing the covariance and precision matrices. For multiple polls, this amounts to taking the covariance matrix, inverting it to obtain the precision matrix, multiplying the associated polling result as a 4-vector, weighting the result by the polling size, then multipling the resulting sum by the matrix inverse of the sum of precision matrices. This gives us the "effective responses" for each candidate.

Undecided voters. If a poll ignores undecided voters, we similarly treat them as the margin of error.

Criteria for Assessing Estimates

We will look at the polls at two points of time: at the beginning of October, and a week before the election (i.e., October 27, 2020). The reason for this decision being, we're interested in whether the Democratic candidate could have acted to "course correct" before the election.

The assessment will compare the Democratic candidate's polling average with the votes cast on election day. This is because a lot of Republican supporters are nervous about publicly backing the Republican candidate, and tend to be swept into the "undecided" bucket.

We note that the estimates the Kalman filter produces is a multivariate normal distribution. Since we're interested in the Democratic candidate's performance, we can turn it into a univariate normal distribution. The 95% margin is given in parentheses around the estimates.

Further, we restrict focus to competitive senate seats. Inside Elections considered the following races as "competitive" [i.e., tilt or toss-up]: Arizona, Georgia, Iowa, Kansas, Maine, Montana, North Carolina, South Carolina.

Conclusion: The only state where Kalman filtering the polls produces significantly different results than the observed vote percentage is Maine, where Susan Collins overperformed (or Sarah Gideon drastically underperformed). All other senate race results coincide, within a prescribed margin of error, with the Kalman filtered polling.

Arizona

We plot the polling average as of October 1st:

The Polling averages as of October 27th:

Candidate Sept. 28 Oct. 27 Vote Percent
Mark Kelley (D)46.8% (±4.32%)48.52% (±4.22%)51.16%
Martha McSally (R)38.4%43.37%48.81%
Third Party4.71%3.42%0.03%
Undecided10.0%4.6%--

Georgia Regular

Jon Ossoff faced an uphill battle, but managed to pull off an unexpected victory.

Candidate Oct. 1 Oct. 27 Runoff Vote Percent
Jon Ossoff (D)41.8% (±3.49%)44.87% (±3.40%)47.9%
David Perdue (R)46.8%42.57%49.7%
Third Party2.95%4.08%2.4%
Undecided8.45%8.47%--

Iowa

The polls were fairly accurate for Ms Greenfield, with Kalman filtering at least. We should note the large number of undecideds in the polls reflect the surprisingly large noise.

Candidate Sept. 26 Oct. 25 Vote Percent
Theresa Greenfield (D)47.1% (±4.51%)45.63% (±3.82%)45.15%
Joni Ernst (R)44.0%46.10%51.74%
Third Party1.39%2.89%3.11%
Undecided7.44%5.39%--

Maine

Senator Susan Collins remained stable in the polls around 41% until the very end of October, whereas her Democratic challenger fluctuated between 40% and 50%.

Candidate Sept. 29 Oct. 25 Vote Percent
Sara Gideon (D)45.69% (±6.05%)50.89% (±5.27%)42.39%
Susan Collins (R)42.17%49.0%50.98%
Third Party0.72%0.04989734%6.63%
Undecided11.42%0.06070465%--

Montana

The polls in Montana were far more stable for Steve Bullock.

Candidate Oct. 2 Oct. 26 Vote Percent
Steve Bullock (D)46.01% (±4.3%)46.38% (±4.21%)45.0%
Steve Daines (R)45.40%45.72%55.0%
Third Party3.66%3.31%0%
Undecided4.93%4.60%--

North Carolina

We plot the polling average as of October 1st:

The polling average fluctuates wildly in October, which is hard to see in the plots I could produce, since it's so wild. Remember, Cal Cunningham landed in hot water with an extramarital affair. We see the plot produced October 30, 2020, reflects fluctuation ranges between 45% and 48% for Cunningham:

Candidate Sept. 26 Oct. 27 Vote Percent
Cal Cunningham (D)50.36% (±4%)47.0% (±2.8%)46.9%
Thom Tillis (R)39.30%46.5%48.7%
Third Party4.19%1.42%4.4%
Undecided6.15%5.12%--

South Carolina

It's not clear what caused Sen Graham's support to increase over time, but I suspect it's that undecideds "came back home" to Sen Graham (for whatever reason). Support for Jaime Harrison fluctuated around 44% (with a standard deviation of about ±2%) throughout October, just observing the Kalman filtered results.

Candidate Oct. 2 Oct. 26 Vote Percent
Jaime Harrison (D)44.85% (± 3.9%)41.62% (± 3.6%)44.17%
Lindsey Graham (R)44.82%49.89%54.44%
Third Party3.08%3.38%1.39%
Undecided7.25%5.10%--

Saturday, February 13, 2021

Zettelkasten

I am going to try to describe how Niklas Luhmann worked his Zettelkasten, then examine motivations. Luhmann's zettelkasten is basically a system for "growing" a corpus of notes based off of "synoptical reading" (as Mortimer Adler would call it).

Mechanics

Take a slip of paper (zettel). We will refer to the slip of paper as a "card", but it could be half a piece of copy paper. An economical choice is to take letter paper, and cut it into 4.25-by-5.5 inch quarters.

Write an "atomic" idea on it (in the sense that, it fits on one side of the slip of paper and is self-contained). What was just written is the "content" of the card. A good heuristic for writing content is to write the card to someone (a pen-pal) who doesn't know the topic. Think of the cards as analogous to "tweets". On the upper right-hand party of the card, write the topic of the card.

We also write in the upper left-hand corner a unique "ID" number on the card. There is no role for an ID other than to make reference to cards possible. We sequentially write numbers on these cards starting at 1, 2, 3, etc.

We may have a "thread" (i.e., a sequence of cards all pertaining to the same general thread of thought), and we indicate this with a slash ("/") followed by the position in the thread. There is at most 1 slash in an ID. For example, if the first card is really a thread, then the cards in the thread are given the IDs "1/1", "1/2", "1/3", etc.

Remark. We should pick the topics for "top-level" threads which are sufficiently general, but they need not form a "Dewey decimal" classification of topics. For example, in my Zettelkasten, the first thread is "1/1 Zettelkasten" which discusses all the conventions I've adopted for my Zettelkasten. The next thread is "2/1 System and Method" discussing the notion of a "System" in philosophy, general systems theory, etc., and "Method" which constitutes the operations and heuristics which "generate" a "System". This leads to discussion of "2/2 Language", "2/3 Explication", "2/4 Evidence", and so on. Then I have "3/1 (American) Political Science" which discusses "3/2 Public Opinion", "3/3 Elections and Campaigns", "3/4 Voting Theory and Behaviour", etc. Note the top-level threads begin with sufficiently general fields of discussion, and subfields constitute "thread items". (Later we see that branching can be used to discuss the main topics in the subfield, which can be explored in a subthread.)

But other times we want to elucidate an aspect of a card, which may be divergent from our thread. For example, I want to elucidate an aspect of my card with ID "1/2", then I add a card with ID "1/2a" after "1/2" but before "1/3". This new card with ID "1/2a" is called a "branch". On the original card "1/2", Luhmann wrote in red "(a)" near the text which is elucidated in "1/2a". (If I want to elucidate an aspect of a card, but the card is not in a thread, I transform it into a thread by appending a "1" to the original card. Example: I am looking at the card with ID "2/12a" and want to have a branch off this card. First I rewrite the ID to be "2/12a1", then I write the ID for the branch "2/12a1a".) There is no significance to lowercase letters in IDs, it could be uppercase if that's easier to distinguish from numerals.

A branch could also be a thread, we just append the position in the thread sequence. Continuing the example, I would have "1/2a1", "1/2a2", "1/2a3", etc. We still write just "(a)" in red, even for the branch "1/2a1" which is a thread. Think of this as analogous to "relative paths" in file systems, or "relative URLs" for links in HTML.

This scheme is "compositional", in the sense that I could iterate this thread-then-branch pattern however deep I want. The IDs alternate between numerals and letters, always starting at "1" for numerals and "a" for letters. For example, a branch on "1/2a3" would be "1/2a3a".

Now, lacking a classification of content or some grouping of concepts, we need to refer to concepts crystalized in the cards already in our Zettelkasten: we want to link to cards. This is done by writing, in parentheses, the ID number we want to reference. And this can be done referring to any card in the system, even ones that come after the referee card. For example, card "1/3" could refer to card "7/12" without a problem.

Lacking any ordering, it quickly becomes hard to remember where concepts are recorded once we have a dozen threads or so. We manage our knowledge through special cards called register cards. These are "entry points", portals to clusters of knowledge. A register card consists of an optional brief summary, followed by a list of tags or keywords with links. Not every card will appear on a register, otherwise we'll double the size of our zettelkasten. It is unclear to me if registers have a special placement in the zettelkasten, or if they belong to an external box.

Luhmann maintained a bibliography external to the Zettelkasten, as he described in his essay Communicating with Slip Boxes

Another complementary aid can be the bibliographical apparatus. Bibliographical notes which we extract from the literature, should be captured inside the card index. Books, articles, etc., which we have actually read, should be put on a separate slip with bibliographical information in a separate box. You will then not only be able to determine after some time what you actually read and what you only noted to prepare reading, but you can also add numbered links to the notes, which are based on this work or were suggested by it.

Personally, I have gone back-and-forth between having an external bibliography versus an internal one. It depends on whether we view a book (or article) as a thing worth thinking about in its own right. For example, if we want to note Dirac's book Principles of Quantum Mechanics was completely rewritten in the second edition, that the first edition had material remarkably similar to the many-worlds interpretation, etc., then such notes belong in the Zettelkasten and quite ostensibly serves as the "bibliography entry" for the book. The argument is stronger in the social sciences and philosophy, since texts form a dialogue among each other, constantly responding to the context shaped by previous work.

I do write on the back of a slip the "works cited", including edition of book, pages relevant, etc. This should be sufficiently documented so if, say, the library I used burned down with no books surviving, I should be able to consult another library and find the original source. But the content of the slip should also contain enough information that this should not be necessary.

Bibliographic Notes

Ahrens's How to Take Smart Notes, the only English book on Zettelkastens, observes that when Luhmann read a book, he wouldn't underline anything, nor make marginal notes. Instead, Luhmann wrote down on a slip all these thoughts. This slip contains a citation to the book being read, and would be stored in a separate slip box which Luhmann referred to as his bibliography system.

The idea behind writing notes like this is not to take "close notes", extended quotes, etc. I am uncertain what exactly constitutes the notes written down here, perhaps something as simple as the ideas presented. We write in such a way so as to best facilitate the next step: writing slips for our Zettelkasten.

Motivation

Niklas Luhmann, in his essay Learning How to Read, argues:

The problem of reading theoretical texts seems to consist in the fact that they do not require just short-term memory but also long-term memory in order to be able to distinguish between what is essential and what is not essential and what is new from what is merely repeated. But one cannot remember everything. This would simply be learning by heart. In other words, one must read very selectively and must be able to extract extensively networked references. One must be able to understand recursions. But how can one learn these skills, if no instructions can be given; or perhaps only about things that are unusual like “recursion” in the previous sentences as opposed to “must”?

Perhaps the best method would be to take notes—not excerpts, but condensed reformulations of what has been read. The re-description of what has already been described leads almost automatically to a training of paying attention to “frames,” or schemata of observation, or even to noticing conditions which lead the text to offer some descriptions but not others. What is not meant, what is excluded when something is asserted? If the text speaks of “human rights,” what is excluded by the author? Non-human rights? Human duties? Or is it comparing cultures or historical times that did not know human rights and could live very well without them?

This leads to another question: what are we to do with what we have written down? Certainly, at first we will produce mostly garbage. But we have been educated to expect something useful from our activities and soon lose confidence if nothing useful seems to result. We should therefore reflect on whether and how we arrange our notes so that they are available for later access. At least this should be a consoling illusion. This requires a computer or a card file with numbered index cards and an index. The constant accommodation of notes is then a further step in our working process. It costs time, but it is also an activity that goes beyond the mere monotony of reading and incidentally trains our memory.

I read this to mean, when reading a book we should take notes. We can try to understand the author's terms, or "normalize" the terminology for comparison with other authors. Using Mortimer Adler's terminology, we can do an analytical reading or a synoptical reading (respectively).

Either way, we should produce something from reading. Armed with these notes, we should reflect on whether and how we arrange our notes so that they are available for later access. [...] The constant accommodation of notes is then a further step in our working process.

Luhmann's Zettelkasten is then designed specifically for this constant accommodation of notes. The numbering scheme for IDs enables this "organic growth"...for most subjects.

An Historian's "Zettelkasten"

The historian Douglass Southall Freeman apparently used a zettelkasten-type system when researching material for his books. David E. Johnson's biography of the man, Douglas Southall Freeman, describes Freeman's method of assembling materials, notes, outlines before writing his text. The basic algorithm is as follows:

  1. Read the source material
  2. “Once it was determined that a letter, book, or manuscript contained information that might be useful, the next decision was what type of note to make of it. There were three categories of notes: ‘Now or Never Notes’ which contained ‘absolutely necessary’ information; ‘Maybe Notes’ with a brief summary of the information; and ‘Companion Notes’ that gave the pages and citations to a source close at hand.” (329)
  3. “Whatever the category, note taking was done in a consistent form. The cards—called ‘quarter sheets’—were 5.5-by-4.25 inches [i.e., literally a quarter of a piece of American writing paper]. In the upper left corner of the card the date was noted—year, month, day. In the upper right, the source and page citation. The subject was written in the center-top of the card. A brief abstract of the contents of the item was typed across the card.” (329) An example from Freeman’s research on George Washington looked like:

    1781, Sept. 13 ADVANCE J.Trumball’s Diary, 333
    Leave Mount Vernon, between Colchester and Dumfries, meet letters that report action between two fleets. French have left Bay in pursuit—event not known. “Much agitated.”
  4. “Supplementing the cards were ‘long sheets’ held in three-ring binders. The long sheets contained more details from the source; often including entire letters or lengthy extracts. The cards were filed chronologically, the long sheets by topic.” (330)
  5. Once a particular source has been thoroughly examined, Freeman later in his life (while working on his biography of George Washington) numbered the cards with something called a “numbering machine”.
  6. “With the cards and long sheets complete, Freeman recorded the information in another notebook, a sort of working outline. In these entries, key words were capitalized so he could tell at a glance what his subject was dealing with at a particular moment. His notebook page for George Washington on August 17, 1775, has two words capitalized: POWDER and QUARTERMASTER.” (330)
  7. “The cards, long sheets, and notebooks were cross-referenced and carried identical numbers if they touched on the same topic. For a fact to be lost or slip through the cracks would require failure at four different places.” (330)

This seems to describe a system remarkably similar to Luhmann's zettelkasten: unique numbering of cards, linked by card-number, an external bibliography system (with source material).

What is worth emphasizing is the numbering is written on the cards when the research is finished and not before. This contrasts with Luhmann's approach, where IDs may be written as one develops notes (as opposed to waiting to finish notes on a topic).

How to get started?

I'd like to now describe what I do with my zettelkasten. I've intentionally modeled/imitated Luhmann's approach, but I have some differences. Before discussing the method, I will discuss the mechanics underlying the physical notes themselves.

First, the mechanics, I do use plain paper for my zettelkasten. Specifically letter paper folded into quarters, then I use scissors to slice the paper into slips. When taking notes, I therefore carry around with me a ream of paper and a pair of scissors.

Now, for the method, with a blank slip, I leave space in the upper left-hand corner for the ID, and write the subject or topic in the upper right-hand corner. The body of the slip I write notes. But this is not merely text, I also include "mini-spreadsheets" if I need tabular data for later use (e.g., vote results for a state across multiple elections), or maps (for geographical concerns), or caricatures (because I don't use a printer and I need to remember what someone looks like).

The back of the slip stores metadata. I write on the back after rotating it 90-degrees (so the slip now resembles a "miniature letter sheet"). The metadata stored helps me remember where I obtained information, and where I use the slip.

For bibliographic citations, I write them at the top of the back slip (specifically, what references I actually used, the page number, etc.). One quirk, the page number is of the form pp.x where x is a digit indicating what percent down the page the reference is from (so "10.5" is half-way down page 10, "27.3" is about 30% from the top of page 27, "61.9" is near the bottom of page 61).

Also on the back of the slip, starting at the bottom, I am trying to write "back links". For example, if I am writing text on slip 65/2 and I link/cite slip 42/72, then I write on the bottom of the back of slip 42/72 in black ink "(65/2)". Thus I get a list of "back-references" telling me where this card is used elsewhere in my zettelkasten.

How many "Threads" to have?

I have since learned that Luhmann had two zettelkastens. Johannes Schmidt reports the first Zettelkasten consists of approximately 23,000 cards, which are divided into 108 sections ['threads'] by subjects and numbered consecutively. Schmidt informs us the second had eleven top-level sections with a total of about 100 subsections.

How many threads should we have in our Zettelkasten? The correct answer is, As many as we need.

For physical Zettelkastens, we are constrained to fit the ID in a limited amount of space. This requires some careful thought about how to organize the threads. I would like to quote Schmidt on this matter:

According to Luhmann the collection is a “combination of disorder and order, of clustering and unpredictable combinations emerging from ad hoc selection.” Of course the file collection is not simply a chaotic compilation of notes but an aggregation of a vast number of cards on specific concepts and topics. This order per subject area on a top level is reflected in the first number assigned to the card followed by a comma (first collection) or slash (second collection) that separates it from the rest of the number given each card (see below). The first collection features 108 sections differentiated by subject areas, exploring and reflecting on largely predetermined, fairly detailed fields of knowledge in law, administrative sciences, philosophy and sociology, such as state, equality, planning, power, constitution, revolution, hierarchy, science, role, concept of world, information, and so on. The second collection, by design, is quite more problem-oriented, reflecting the emerging sociological interests of Luhmann: It consists of only eleven top-level subject areas: organizational theory, functionalism, decision theory, office, formal/informal order, sovereignty/state, individual concepts/individual problems, economy, ad hoc notes, archaic societies, advanced civilizations. What this compilation immediately illustrates is that it is not a system of order in the sense of an established taxonomy but a historical product of Luhmann’s reading and research interests especially in the 1960s. Following the subject areas defined at the top level are other subsections that revolve around a variety of topics. The relationship between the top-level subject area and the lower-level subjects cannot be described in terms of a strictly hierarchical order, it is rather a form of loose coupling insofar as one can find lower-level subjects which do not fit systematically to the top-level issue but show only marginally connections.

This is a result of the specific system of organization of the notes applied within these sections on a particular subject matter which ensures that the initial decision for a specific topic did not lead to a sequence of cards confined to that one topic: Whenever Luhmann came across an interesting idea about a secondary aspect on one of his cards, he pursued this idea by adding additional notes and inserted the respective card at that place in the existing sequence of cards. This method could be applied again to the card that had been inserted and so forth, the result being a sequence of cards leading thematically and conceptually farther and farther away from the initial subject and constitute their on subsection. Furthermore this technique enabled the collection not only to grow in absolute numbers, but to grow “inwardly” without the limitations of a systematically order.

But the positioning of larger subject areas as well as individual cards in the collection was not only the historical product of Luhmann’s reading interests and note-taking activities. It also owed to the difficulty of assigning an issue to one and only one single (top-level) subject, which is a matter of ambiguity or so to say conceptual indecisiveness. Luhmann solved this problem by seizing it as an opportunity: instead of subscribing to the idea of a systematic classification system, he opted for organizing entries based on the principle that they must have only some relation to the previous entry without also having to keep some overarching system in mind. One could say: there must be a local solution (i.e. connection or internal fit) only. This indicates, accordingly, that the positioning of a special subject within this system of organization reveals nothing about its theoretical importance — for there are no privileged positions in this web of notes: there is no top and no bottom.

The decision inherent in this filing technique without a fixed system of order is an essential prerequisite of the creativity of the filing system. In explaining his approach, Luhmann emphasized, with the first steps of computer technology in mind, the benefits of the principle of “multiple storage”: in the card index it serves to provide different avenues of accessing a topic or concept since the respective notes may be filed in different places and different contexts. Conversely, embedding a topic in various contexts gives rise to different lines of information by means of opening up different realms of comparison in each case due to the fact that a note is an information only in a web of other notes. Furthermore it was Luhmann’s intention to “avoid premature systematization and closure and maintain openness toward the future.” His way of organizing the collection allows for it to continuously adapt to the evolution of his thinking and his overall theory which as well is not conceptualized in a hierarchical manner but rather in a cybernetical way in which every term or theoretical concept is dependent on the other.

Choice of "Topics"

So Luhmann's attempts at using Zettelkastens began with some kind of Dewey decimal system of subjects, then in his second kasten merely a dozen or so subjects. Should we pick some set of "topics" for the high level threads?

The answer is, it depends on what you're doing. For a zettelkasten dedicated to a particular project (like, writing a book), this may not be wise. But for one's life-long project or education, this might prove useful.

Curiously, the Propædia provides one schematization for organizing all knowledge. Whether one agrees or not with such a schematization, it deserves serious consideration.

My personal opinion is the threads should be sufficiently general subjects. Their ordering doesn't matter (unlike the case of, e.g., the Propædia). Here's a small example of my Zettelkasten's organization.

  1. Zettelkasten
    1. Numbering Scheme
      1. Link
      2. Thread
      3. Branching
      4. Ontological Status of ID Numbers
    2. Register, Tag
    3. Principle of Atomicity
    4. Bibliography
    5. Slips of Paper, Index Cards
  2. Language
    1. Formal Language
    2. Language Game
    3. Pattern Language
      1. Pattern
      2. Context
      3. Forces
      4. Problem
  3. System and Method
        1. System
        2. Component
        3. Boundary
        1. Method
          1. Bare and Stylized Facts
        2. Scientific Methods
        3. Method as Component of System
    1. Language
      1. Formal Language
      2. Language Game
      3. Pattern Language
    2. Computation
  4. Programming
    1. Software Design
    2. Toy Model of a Computer
      1. Basics
      2. Memory Model
      3. CPU
      4. Disk Storage
      5. Secondary Devices
    3. Lisp
      1. Basics
      2. Memory Model
      3. Macros
      4. Domain-Specific Languages
      5. Correctness
    4. C
      1. Basics
      2. Rules to the Language
      3. Macro Tricks
      4. Memory Model
      5. ACSL
      6. Correctness
    5. Operating Systems
      1. xv6
      2. Linux
      3. FreeBSD
      4. DOS
    6. C++
    7. Make A Lisp (Literate C++)
    8. R
    9. Make An R (Literate C)
  5. Mathematics, Statistics
    1. Foundations of Mathematics
      1. Naive Set Theory
      2. Stuff, Structures, Properties
      3. First Order Logic
      4. Set Theory
      5. Type Theory
    2. Category Theory
    3. Linear Algebra
    4. Abstract Algebra
      1. Foundations (working with Stuff, Structure, and Properties, morphisms)
      2. Symmetries (Group Theory)
      3. Number Systems (Ring Theory)
      4. Modules over Rings
      5. Galois Theory
    5. Topology
    6. Measure Theory
    7. Combinatorics
      1. Foundations
      2. Enumerative Combinatorics
        1. Twelvefold Path
        2. Generating Functions
      3. Partition Theory
      4. Design Theory
    8. Probability
      1. Foundations
        1. Random Processes
        2. Events
        3. Sigma Algebras
        4. Probability
      2. Coin Flipping
      3. Classical Puzzles
        1. Birthday Paradox
        2. Coupon Collector Problem
        3. Monty Hall Problem
        4. Dice Problems
        5. Population Puzzles
      4. Random Variables
      5. Probability Distributions
    9. Statistics
      1. Data Collection
      2. Exploratory Data Analysis
      3. Statistical Inference
      4. Regression Analysis
      5. Bayesian Data Analysis

One thing that's surprising is, I recently became interested in bookbinding. This required discussing paper quite a bit, which turns out to be elucidate aspects of slip "1/5 Slips of Paper, Index Cards".

Best Practices

Or, "Things I wish I had-done/am-glad-to-have-done". This is a grocery list of observations, errors, lessons learned...in no particular order.

1. First Thread. The first thread should be about the topic of Zettelkastens. This also stores the reasoning for the conventions I have chosen to follow, the alternatives I had considered, and the arguments for and against the choices made.

2. Numbering Scheme. Dedicate some time thinking about the numbering scheme you'd like to use. If you're imitating Luhmann, what about when you have more than 26 aspects you'd like to drill down on? For example, if we have "1/1a", "1/1b", ..., "1/1z", what will the next card be? "1/1A", "1/1B", ..., "1/1Z" and then what? Or "1/1aa" and then "1/1ab"?

Or will you use a numbering scheme similar to Wittgenstein's Tractatus? (See, e.g., Warren M Tang's summary of the numbering scheme.) So "1.1" instead of "1/1"? Or "1/1.1" instead of "1/1a"? And then "1/1.11" to clarify an aspect of "1/1.1"? As Ogden's translation explains, The decimal figures as numbers of the separate propositions indicate the logical importance of the propositions, the emphasis laid upon them in my exposition. The propositions n.1, n.2, n.3, etc., are comments on proposition No. n; the propositions n.m1, n.m2, etc., are comments on the proposition No. n.m; and so on.

Or will you use a "modern" scheme using multiple periods? So "2.1" is a comment on "2", and "2.1.1" is a comment on "2.1", with each "component" of the number separated by a period, ordered sequentially? This jettisons alternating letters and numbers, which may not be good for one's memory. Also this seems to weaken the difference between (a) a slip in the middle of a thread, and (b) elaborating an aspect of a given slip. Is this advantageous for your needs or is it a disadvantage?

Remember, using either Wittgenstein's scheme or "modern" schemes does not easily facilitate "branching" (in Luhmann's sense). This jettisons one of the key aspects of a Zettelkasten. Is this worth it? Think very hard about this before committing yourself. Branches, I have found, are very useful when you want to elaborate on aspects of a slip...and such elaborations are not necessarily ordered in any way. (You should probably sit down and think if you want branches in your Zettelkasten; amendations, elucidations, forks, asides, all these and more are captured by "branches", but cannot adequately be captured by threads alone.)

3. Index Card vs Paper. For cards which may need replacement/updating/rewriting, use a quarter slip of ordinary paper. This is not as durable as index cards, because index cards consist of thicker paper. The "lifespan" of ordinary paper is far shorter than index cards, or so I have been told.

When will I know that a card needs replacement, updating, or rewriting? One instance is when a card "stores data". For example, my Zettelkasten includes recent presidential election results from, say, Pennsylvania. This will require updating after 2020.

Let me stress again, using paper will result in a zettel that will (with heavy usage) "wear out" in a limited time. I am writing my Zettelkasten with knowledge that using ordinary paper will require replacement.

4. Highlighter, Ink. Consider using highlighters on the edge of the cards. Different colors for different types of cards. (Red for register, yellow for people or organizations, etc.) This lets me look down at the zettelkasten and identify cards visually. But this works best on index cards, not plain paper.

Similarly, ink color could be used for particular significance. I reserve red ink for links, blue ink for defined terms, and so on. Whatever you choose to do, be consistent.

5. Write content first, IDs last. First, I usually write the notes on the slip (either the body or the title, or both), and when I'm done with a batch of slips, I ponder arrangement and clustering. While writing content, I sometimes realize I want a branch to elaborate on particular topics, so I'll insert links (or leave space for them later).

There are some times when I know I need to add notes on, e.g., "American Political Science". In this case, I find an introductory textbook, find the topics discussed (the Constitution, each of the three branches of government, the bureaucracy, public opinion, elections, political culture and geography, etc.) which give the entries in the thread, and branches then elaborate aspects of each entry. This forms the basis of knowledge which is then extended in advanced courses/topics (e.g., committees in congress, game theoretic models of committees, etc.).

Other times, I am relatively aimless. I don't know "where I'm going" with my notes on "System and Method". I explore a train of thought ("System", "Environment and Boundary", "Component", "Method", "Explication", "Analysis", "Bare and Stylized Facts", "Language", etc.), then I organize them and finally give them IDs.

6. Threads should be "sufficiently general subjects". In the example zettelkasten I have produced, we should note how general the top-level thread topics are: language, mathematics, computer programming, etc. (Statistically, Luhmann had on average about 213 cards per "top-level thread" in his first Zettelkasten, and roughly 670 cards per "top level thread" in his second; this is the general aim.)

Really, I'm just writing notes on slips as I am solving a particularly interesting problem, or reading a book. These zettels lack only an ID number. When I get home, I look at my zettelkasten to figure out which thread these slips belong to. I do not start with a schematization ab initio. But I invent new subjects/threads as it becomes relevant.

7. Literate Programming. It is possible to do something like Knuth's literate programming in your Zettelkasten. For example, Knuth's "section" or "chunk" corresponds to a "zettel", the code section may be done in markdown fences (i.e., demarcated by ```lang ...```). This really shines when correctness is a concern, because we can insert slips establishing the preconditions, postconditions, and invariants for the code in a section: correctness becomes a branched thread. (For thicker paper, or pens which don't bleed through the paper, one could use one side for the code section and the other for human readable comments.)

(I'm writing a book on automated theorem proving, so my needs for proving the correctness of a program are probably idiosyncratic here. But, as odd as it sounds, the Zettelkasten structure captures Knuth's approach amazingly well!)

References

This is by no means complete, and I realize I cite sources in this post but neglected to add them here. Apologies!

Tuesday, September 1, 2020

Geometric Mean for Combining Probabilities, addendum

We've noted before the geometric mean is best when combining several different forecasts together into one. Today I'd like to discuss how to do this specifically for election forecasts.

If we naively try to combine the forecasts that, e.g., Biden will win Nevada, using the forecasts as of August 30th:

ForecasterPr(Biden)Pr(Trump)
DecisionDeskHQ.com77.8%22.2%
The Economist89%11%
FiveThirtyEight77%23%
JHKForecasts.com86.1%13.9%
OurProgress.org79%21%
PluralVote.com76.6%24.4%
ReedForecasts.com62.5%37.5%

We would obtain \[ \Pr(Biden) = 77.87021\%\tag{1a} \] but we would also find \[ \Pr(Trump) = 20.33664\%\tag{1b} \] ...which sums to 98.20685%, which is odd. These probabilities should always sum to 100%, what gives?

The solution is to first transform the probabilities into odds. Then take the geometric mean of the odds, and finally transform back to probabilities.

Why does this work? Well, as odds, a forecast would look like \[ O(\text{Biden wins NV}) = \frac{\Pr(Biden)}{\Pr(Trump)} = \frac{N_{\text{Biden}}}{N_{\text{Trump}}}. \tag{2}\] Taking the geometric mean of the odds gives us better approximations for the ratio of frequencies, which could then be transformed back into probabilities. We can obtain the probability of Biden winning Nevada from the odds by \[ \Pr(Biden) = \frac{O(Biden)}{1 + O(Biden)} \tag{3}\] and for Trump we could note \[ O(Trump) = 1/O(Biden) \] then find \[ \Pr(Trump) = \frac{O(Trump)}{1 + O(Trump)} = \frac{1}{1 + O(Biden)}. \tag{4}\] Hence we find adding Eq (3) to Eq (4) that \[ \Pr(Biden) + \Pr(Trump) = 1 \tag{5} \] probabilities sum to 100%, as expected and desired.

Applied to our forecasts, we find the odds given as:

ForecasterOdds(Biden)
DecisionDeskHQ.com3.504505
The Economist8.090909
FiveThirtyEight3.347826
JHKForecasts.com6.194245
OurProgress.org3.761905
PluralVote.com3.273504
ReedForecasts.com1.666667

The geometric mean of these odds is approximately 3.829059, hence a probability of Biden winning Nevada approximately 79.29203% and Trump has a 20.70797% chance of winning Nevada. This makes a difference for Biden of about 2%, whilst negligible improvement for Trump.

Puzzle/Homework. Consider the case of, say, a primary with several candidates. Suppose we have multiple forecasters make predictions for each candidate to win the primary. How can we generalize our method to handle this case?

Monday, July 27, 2020

Kalman Filtering Polls

We will discuss Kalman filters applied to opinion polling. They've been applied quite successfully to robotics (and other fields), so people playing with Arduino kits tend to be curious about them; I hate to disappoint, but we will focus particularly on polls.

Kalman filters are the optimal way to combine polls. The "filter" should be thought of as filtering out the noise from the signal.

We will briefly review state space formalism, then discuss polling framed in this formalism. Once we rephrase polls in state space variables, we will

State Space Models

We have n candidates and we're interested in the support among the electorate for each candidate. This is described by a vector \(\vec{x}_{k}\) on day \(k\). As we may suspect, support changes day-to-day, which would be described by the equation \[ \vec{x}_{k+1} = F_{k}\vec{x}_{k} + \omega_{k} \tag{1a}\] where \(\omega_{k}\sim MVN(0, Q_{k})\) is white noise, \(F_{k}\) is the state evolution operator.

Polls are released, which measure a sample of the electorate. We are informed about the support in terms of how many respondents support each candidate at the time of the survey, denoted \(\vec{z}_{k}\), and it obeys the equation \[ \vec{z}_{k} = H_{k}\vec{x}_{k} + \nu_{k} \tag{1b}\] where \(H_{k}\) is the sampling operator, and \(\nu_{k}\sim MVN(0, R_{k})\) is the sampling error.

State space models, for our interests, work in this general framework. What questions could we ask here? What problems could we solve here?

  1. Filtering problem: from observations \(z_{1}\), ..., \(z_{k}\), estimate the current unobserved/latent state \(x_{k}\)
  2. Smoothing problem: given past, present, and future observations \(z_{1}\), ..., \(z_{k}\), ..., \(z_{N}\) estimate past unobserved/latent states \(x_{1}\), ..., \(x_{k-1}\)
  3. Prediction problem: given observations \(z_{1}\), ..., \(z_{k}\), estimate future unobserved/latent states \(x_{k+t}\) for some \(t\gt0\)
This is not exhaustive, Laine reviews more questions we could try to answer. We could try to also estimate the covariance matrices, for example, in addition to smoothing.

For our interests, we can estimate the covariance matrices \(R_{k}\) and \(Q_{k}\) for the sampling error and white noise using the normal approximation to the multinomial distributions. We add to it, though, some extra margin for variation: we add a diagonal matrix of the form \(0.25 z_{cr}^{2}nI\) where \(I\) is the identity matrix, \(z_{cr}\approx 1.96\) is the 95% critical value for the standard normal distribution, and n is the sample size of the poll.

Kalman Filter

We will stick-a-pin in determining the covariance matrices \(Q_{k}\) and \(R_{k}\), it will be discussed later, and we'll just assume it can be determined. In a similar vein, we will assume our polls give us the number of respondents supporting the Democratic candidate, the Republican candidate, the third party candidate(s), and the undecided respondents. The problem is to estimate \(x_{k}\) using \(z_{1}\), ..., \(z_{k}\) for each k.

The basic structure to Kalman filter amounts to "guess and check", or using more idiomatic phrasing "Predict and Update".

Predict

We begin with an estimate using previous observations \[ \widehat{x}_{k|k-1} = F_{k}\widehat{x}_{k-1|k-1} \tag{2a} \] the notation of the subscripts for estimates should be read as "time of estimate | using observations up to this time". Hence \(\widehat{x}_{k|k-1}\) uses observations \(z_{1}\), ..., \(z_{k-1}\) to estimate \(x_{k}\). This is the first stab at an estimate.

Now, this is a realization of a multivariate normally distributed random variable. There's a corresponding covariance matrix for this estimate, which is also unknown. We can estimate it using the previous estimates and observations as \[ P_{k|k-1} = F_{k}P_{k-1|k-1}F_{k}^{T} + Q_{k}. \tag{2b} \] Along similar lines, we need to estimate the covariance matrix for \(z_{k}\) as \[ S_{k} = H_{k}P_{k|k-1}H_{k}^{T} + R_{k}. \tag{2c} \] Initially this seemed quite random to me, but the reader familiar with covariance of random variables could see it from Eq (1b) and (2b).

None of these predicted estimates use the new observation \(z_{k}\). Instead, they are derived using estimates obtained from previous observations.

Update

The next step incorporates a new observation \(z_{k}\) to improve our estimates. Our estimates have some error, its residuals are \[ \widetilde{y}_{k} = z_{k} - H_{k}\widehat{x}_{k|k-1} \tag{3a} \] which tells us how far off our predicted estimates are from the new observation. We will update our estimates with the goal of minimizing the residuals. This is done as \[ \widehat{x}_{k|k} = \widehat{x}_{k|k} + K_{k}\widetilde{y}_{k} \tag{3b} \] for some "Kalman gain" matrix \(K_{k}\). Minimizing the sum of squares of the residuals give us the formula \[ K_{k} = P_{k|k-1}H_{k}^{T}S_{k}^{-1} \tag{3c} \] which we'll derive later.

The updated covariance matrix for the estimates can similarly derived, in Joseph form for numerical computational convenience, as \[ P_{k|k} = (I-K_{k}H_{k})P_{k|k-1}(I-K_{k}H_{k})^{T} + K_{k}R_{k}K_{k}^{T}. \tag{3d} \] When we use gain matrices other than the Kalman gain, Eq (3c), this updated covariance equation still holds. But for the Kalman gain matrix, we can simplify it further (useful for mathematics, but not so useful on the computer).

Combining it all together, the fitted residuals are now \[ \widetilde{y}_{k|k} = z_{k} - H_{k}\widehat{x}_{k|k} \tag{3e} \] which, for Kalman filters, is minimized. Assuming the model described by Eqs (1) is accurate and we have correct initial values \(P_{0|0}\) and \(\widehat{x}_{0|0}\), then Eq (3e) ensures we have the optimal estimates possible (in the sense that it minimizes the sum of squares of these residuals).

Invariants

If the model is accurate, and if the initial values \(\widehat{x}_{0|0}\) and \(P_{0|0}\) reflect the initial state, then we have the following invariants \[ \mathbb{E}[x_{k}-\widehat{x}_{k|k}] = \mathbb{E}[x_{k}-\widehat{x}_{k|k-1}] = 0\tag{4a} \] and \[ \mathbb{E}[\widetilde{y}_{k}] = 0.\tag{4b}\] These encode the fact that we're accurately estimating the state, and the residuals are just noise. We have similar invariants on the covariance matrices, like \[ \operatorname{cov}[x_{k}-\widehat{x}_{k|k}] = P_{k|k} \tag{4c} \] and \[ \operatorname{cov}[x_{k}-\widehat{x}_{k|k-1}] = P_{k|k-1} \tag{4d} \] as well as the residual covariance \[ \operatorname{cov}[\widetilde{y}_{k}] = S_{k}. \tag{4e} \] The just encode the assertions we're estimating the state and covariance matrices "correctly".

Where did all this come from?

The short answer is from minimizing the sum of squares of residuals, and from the definition of covariance in Eqs (4c) and (4d). From Eq (4c) we derive Joseph's form of covariance Eq (3d).

Kalman gain may be derived by minimizing the square of residuals \(\mathbb{E}[\|x_{k}-\widehat{x}_{k|k}\|^{2}]\). The trick here is to realize \begin{align} \mathbb{E}[\|x_{k}-\widehat{x}_{k|k}\|^{2}] &= \mathbb{E}[\operatorname{tr}\bigl((x_{k}-\widehat{x}_{k|k})(x_{k}-\widehat{x}_{k|k})^{T}\bigr)]\\ &= \operatorname{tr}(\operatorname{Cov}[x_{k} - \widehat{x}_{k|k}]) \tag{5a} \end{align} which, using (4c), amounts to minimizing the trace of the covariance matrix \(P_{k|k}\). As is usual in calculus, we use the derivative test, so this occurs when its derivative with respect to the unknown quantity is zero. We're looking for the Kalman gain (as it is the unknown), we then have \[ \frac{\partial}{\partial K_{k}}\operatorname{tr}(P_{k|k}) = -2(H_{k}P_{k|k-1})^{T} + 2K_{k}S_{k} = 0\tag{5b} \] which we solve for \(K_{k}\). This gives us Eq (3c).

Determine Initial Values and Parameters

I briefly mentioned how to estimate the covariance matrices for the noise terms appearing in Eq (1). It's basically the covariance matrices for multinomial distributions, perturbed by sampling margin of error. For \(R_{k}\), we use the poll data to estimate the multinomial covariance; for \(Q_{k}\), we use the \(\widehat{x}_{k-1|k-1}\) estimates.

The initial guess for \(\widehat{x}_{0|0}\) could be estimated in any number of ways: it could be from party registration data, or from the last presidential election, or just from the gut. I use a vector proportional to the last estimate from the previous election, whose components are integers that sum to 3600.

As for the initial covariance matrix \(P_{0|0}\), I use a modified multinomial distribution covariance matrix derived from the initial guess for \(\widehat{x}_{0|0}\). The changes are: multiply the entire matrix by a factor of 12, the diagonal components by an additional factor of 5, and change the sign on the covariance components of third-party/undecided off-diagonal components (under the hypothesis that third party voters are undecided, and vice-versa). Multiplying by these extra factors reflects the uncertainty in these estimates (it'd correspond to an approximate margin-of-error of ±12%).

For polling data, this amazingly enough works. If we were building a robot or driverless car, then we should use some rigorous and sound principles for estimating the initial state...I mean, if you don't want cars to drive off cliffs or into buildings.

Partial Pooling and Updating the Estimates

The only quirks left are (1) translating polling data into the \(\vec{z}_{k}\) vectors, (2) handling multiple polls on the same day, (3) rescaling \(\vec{x}_{k}\). Let me deal with these in turn.

1. Translating poll data. I'm given the percentage of respondents favoring the Democrat (e.g., "43" instead of "0.43"), the percentage favoring the Republican, the percentage undecided. I lump the remaining percentage (100 - dem - rep - undecided) into a hypothetical "third party" candidate. Using these percentages, I translate them into fractions (e.g., "43" [which stands for "43%"] becomes "0.43") then multiply by the sample size. These form the components of the \(\vec{z}_{k}\) vector.

2. Pooling the Polls. Following Jackman's work, I find the precision for the poll as \(\tau_{k} = 2n/z_{cr}\) where \(z_{cr}\approx 1.96\) is the critical value for the 95% standard normal distribution, and n is the sample size for the poll. When multiple polls are released on the same day, we take the weighted-mean of the polls, weighted by the precision of the polls.

2.1. What date do we assign a poll anyways? Polls usually take place over several days, so what date do we assign it? There's probably a clever way to do this, but the standard way is to take the midpoint between the start and end dates for a poll. The simplest way is to use the end date, which is what I've chosen to do for the moment.

3. Recale the estimates. The \(H_{k}\vec{x}_{k|k-1}\) needs to be of the same scale as \(z_{k}\). This gives us \(H_{k} = \|\vec{z}_{k}\|_{1}/\|\widehat{x}_{k|k-1}\|_{1}I\) using the L1-norm (sum of absolute values of components of vectors). The \(\vec{x}_{k}\) is proportional to the total electorate, but is not equal to it.

At the end, when the dust settles, we get an estimate \(\widehat{x}_{k|k}\) which we interpret as a "true sample estimate" reflective of the electorate. It's an optimal reflective sample.

What can I do with it?

Once we've done this, we get a sequence of optimal estimates of support among the electorate. We can use this to estimate the support for the candidate in a "nowcast" by taking a vector \(\vec{c}\) which, written as a sum of unit vectors, would be for a Democratic candidate \[ \vec{c} = \vec{e}_{dem} -\vec{e}_{rep} + c_{t}\vec{e}_{third} + c_{u}\vec{e}_{undecided} \] where \(c_{t}\) is the fraction of third party voters who ultimately change their mind and vote for the Democratic candidate minus the fraction of third party voters who ultimately vote for the Republican, and likewise for \(c_{u}\) the difference of undecideds who vote Democrat minus those who vote Republican. Implicit in this is the assumption that either the Democratic candidate or the Republican candidate win the election.

We can then construct a univariate normal distribution \[ X \sim\mathcal{N}(\vec{\mu}\cdot\vec{c}, \sigma^{2}=\vec{c}\cdot P_{k|k}\vec{c}) \] which describes the margin of victory for the Democratic candidate. The nowcast amounts to computing the probability \[ \Pr(X\gt 0) = p_{dem} \] to forecast the probability the Democratic candidate will win the election, as measured by the current support as estimated by the polls.

There's still sensitivity analysis to do with this, but it's actually a surprisingly accurate way to forecast an election if one has sufficient state-level polling data in the competitive states. (It predicted Wisconsin, Pennsylvania, and Michigan would all go for Trump in 2016, for example, a week before the election.)

Code

I've written some code implementing a Kalman filter from polling data for US presidential elections. It's rough around the edges, but it does what one would expect and hope.

Concluding Remarks

The topic of "state space models" is huge and vast, and this is by no means exhaustive. We've just looked at one particular filter. Even for the Kalman filter, we could add more bells and whistles: we could factor in how the public opinions changes when polling data is released (because polls are not always published the day after they finish), factor in methodology (phone interview vs internet polls, likely voters vs registered voters vs adults), house effects, etc.

We could also revisit assumptions made, like treating polls as one-day events, to try to model the situation better.

We could leave the covariance matrices as unknowns to be estimated, which greatly complicates things, but ostensibly could be done with MCMC methods. If we wanted to continue working in this domain, using state space models, then MCMC methods prove fruitful for Bayesian approaches.

References

  1. Eric Benhamou, "Kalman filter demystified: from intuition to probabilistic graphical model to real case in financial markets". arXiv:1811.11618
  2. Joao Tovar Jalles, "Structural Time Series Models and the Kalman Filter: a concise review". Manuscript dated 2009, Eprint
  3. Simon Jackman, "Pooling the polls over an election campaign". Eprint
  4. Marko Laine, "Introduction to Dynamic Linear Models for Time Series Analysis". arXiv:1903.11309, 18 pages.
  5. Renato Zanetti and Kyle J. DeMars, "Joseph Formulation of Unscented and Quadrature Filters with Application to Consider States". Eprint, for further discussion on variations of Kalman gain, etc.

Friday, July 24, 2020

Measuring a region's partisanship: a survey

When we say things like, The South is solidly red...what does that mean? How do we measure it?

There are a variety of statistics ("indices"?) to gauge the magnitude of partisanship for the constituency of a region.

Cook PVI

Cook PVI score tells us the party lean for a congressional district (or state), measured as "R+n" or "D+n" or "EVEN", where n is a natural number greater than zero (e.g., 1, 2, 3, 4, 5, etc.). This is basically is done as follows in pidgin code:

function party_margin(local_d_percent, 
                      local_r_percent, 
                      national_d_percent, 
                      national_r_percent) {
    if (local_d_percent > local_r_percent) {
        return national_d_percent - local_d_percent;
    } else {
        return local_r_percent - national_r_percent;
    }
}
// As of 2022, this is the weighted average used for Cook PVI
// Also, the arrays passed as arguments are indexed by ELECTION YEARS
function cook_pvi(local_d_percent_history,
                  local_r_percent_history,
                  national_d_percent_history, 
                  national_r_percent_history) {
    recent = party_margin(local_d_percent_history(last_election), 
                          local_r_percent_history(last_election),
                          national_d_percent_history(last_election),
                          national_r_percent_history(last_election));
    prev = party_margin(local_d_percent_history(last_election - 4), 
                        local_r_percent_history(last_election - 4),
                        national_d_percent_history(last_election - 4),
                        national_r_percent_history(last_election - 4));
    return ((0.75 * recent) + (0.25 * prev)) * 100;
}
// This is the "human readable" Cook PVI
function cook_pvi_toString(pvi) {
    if (pvi < 0.5) {
        return "D+"+round(abs(pvi));
    } else if (pvi > 0.5) {
        return "R+"+round(pvi);
    } else {
        return "EVEN";
    }
}

The "region" is either a congressional district or an entire state, but ostensibly could be arbitrary (e.g., counties could get its own PVI).

One problem with this is the reliance on voting for a single candidate for determining partisanship or political leaning. But there is a different political culture between a region that (1) votes for the incumbent president and the opposition party for congress, and (2) "down ballot" voters.

Another line of criticism takes issue with working with 2 elections at a time. But really the Cook PVI is just the deviation of the simple moving average for a region compared to the simple moving average for the nation. This smooths out some of the fluctuating "noise".

Partisan Propensity Index

FiveThirtyEight's PPI is explained as:

Thus, Partisan Propensity Index, or PPI, is defined as the percentage chance that the Democrat would have won and open-seat race for Congress in a particular district given the conditions present, on average, between 2002 and 2008 (a period which conveniently featured two good cycles for Republicans and two good ones for Democrats). It contains only two variables: the Presidential vote share in the district and the percentage of households there with incomes below $25,000.

This is computed by using a logistic regression (apparently trained on "1" for Democratic winners, "0" for Republican winners).

One reservation I have, as I had articulated for the Cook PVI, is it turns out there are a lot of people who vote one party for President and the opposition party for congress. At present, I am not convinced the PPI avoids this problem.

The last reservation that comes to mind is the reliance on an economic indicator. This is nothing serious, per se, but could produce spurious results in an economic collapse or a sudden migration.

The prudent reader will realize that both Cook PVI and the PPI both are using federal election data, i.e., results for sending candidates to the White House or to Capitol Hill. Both measures ignore state-level data (e.g., for the gubernatorial race, or for state legislature races).

Ranney Index

Ranney Index, which measures (over a specified time period) the average of:

  1. the proportion of seats held by the Democrats in the state's lower legislature,
  2. the proportion of seats held by the Democrats in the state's upper legislature,
  3. the Democratic gubernatorial candidate's percentage in the election,
  4. the proportion of time the Democrats held both (a) majorities in both chambers of the state legislature, and (b) the governorship.
Since each of these factors are themselves between 0 and 1, the Ranney index will be between 0 (super Republican) and 1 (super Democratic).

The folded Ranney index, computed as 1 − abs(Ranney − 0.5), tells us how competitive the state. For states which are competitive (nearer 0.5) or solidly partisan (nearer 1.0).

Another variant is to use a moving average of the Ranney Index computed for each election, with the "time interval" being 2 gubernatorial elections. This mirrors the simple moving average scheme used in the Cook PVI.

This has the exact opposite problem as the Cook PVI and the PPI statistics, namely an exclusive focus on state-level elections while ignoring federal elections.

Majority Party Index

James W. Ceaser and Robert P. Saldin's A New Measure of Party Strength (2005) present a different metric, the Majority Party Index (MPI). The MPI is, like the Ranney index, a weighted average, but split evenly between federal elections and state-level elections.

The first component of the MPI and the first nationally based measure is the two-party vote for president in each state's most recent presidential election. Thus in 2000, the value is based on the election result of that year. For 2002 the same value is entered because there was no presidential election in 2002. This factor accounts for 25 percent of the total index value for each state.

The second MPI component, also at the national level, is the two-party vote in each state's two most recent United States Senate elections and accounts for 12.5 percent of the total index value. To take an example, Idaho's U.S. Senate value is calculated by averaging the results from the 1998 and 2002 Senate elections. By taking both of the Senate elections into account, despite the time lag on the former, the MPI attempts to reflect partisan voting from year to year without over-emphasizing current partisan swings. By including a Senate result every year, it evens out results among different states.

The third component, and the final national measure, is the total two-party average of all votes in each state's biennial U.S. House elections. Virginia's value, for example, is obtained by adding Republican and Democratic votes in all congressional districts and calculating each party's percentage of this total. This method provides a more accurate measure of the overall state partisan choice than would be obtained by averaging the two-party percentages of each district because districts differ in population and turnout. In addition, it reduces the impact of uncontested seats. This component of the MPI accounts for 12.5 percent of each state's total score.

The fourth component of the MPI, and the first state-level measure, is the two-party vote percentage in each state's most recent gubernatorial election. This component accounts for 25 percent of each state's total.

The fifth measure, also at the state level, is the two-party percentage of all seats in each state's Senate. The Major Party Index value is determined in this case by dividing the number of Republican seats by the sum of Democratic and Republican seats. There were two reasons in this case for using seats (as opposed to votes) as the basis of calculation: vote totals for state legislative electlons are difficult to find, and many of these races are uncontested (a large number of uncontested seats skews the two-party vote totals). This component is weighted as 12.5 percent of the total index.

The final component of the MPI, and the third state-level measure, is the two-party percentage of seats in state houses. This score is calculated in the same way as that for the state senate and is worth 12.5 percent of the total index value.

Nebraska has a nonpartisan, unicameral state legislature. What we do for them is omit the state legislature factors, then reweigh everything accordingly. (The president factor is weighed 1/3, the house and senate factors each weighed 1/6, and the governor is weighed 1/3?)

Thus the formula is:

MPI = ((Most recent 2-Party Republican Presidential Vote)*0.25) + 
    ((Average of Two Most Recent Republican 2-Party Votes for US Senate)*O.125) + 
    ((Republican 2-Party Percent of all US House Votes)*O.125) +
    ((Most Recent 2-Party Republican Vote for Governor)*0.25) +
    ((2-Party Republican Percentage of Seats in the State Senate)*O.125) +
    ((2-Party Republican Percentage of Seats in the State House)*O.125).

We could, for ease, rescale this to be between −1 for Democratic states to +1 for Republican states.

The only problem with this approach, and this stems from my own laziness, is there is no good data source for Governor election data. Or, at least, none that I could find.

Also, the turnover for legislator resignation is far higher in state legislatures. (They resign in disgrace far more frequently than federal legislators.) It's unclear to me how to handle the situation when the replacements belong to different parties.

Equally unclear to me is how special elections are handled for the federal offices. When a senator dies or resigns, some states have a special election for replacing the senator. Do we include special election percentages in the MPI?

Concluding Remarks

It would be useful to compute the Cook PVI for the states, as well as the MPI for the states, to see if these correlate or not. Similarly if there's any correlation between the Cook PVI and the Ranney index, that would be interesting to investigate.

We could ostensibly restrict the region size to counties (or county-equivalents) and use vote data to estimate indices at that level. Although counties range from 100 (rural Texas) to 10 million (Los Angeles), the intent is to apply the formulas to different sub-regions of states, to see how they compare within a state.

(This was more or less a summary I've had lying around for over a year, and I thought I ought to quit polishing it and just publish the thing.)