Skip to content

Instantly share code, notes, and snippets.

View lennybronner's full-sized avatar

Leonard Bronner lennybronner

View GitHub Profile
@lennybronner
lennybronner / bundestag-2021-uniform-swing.R
Created September 25, 2021 02:17
Calculate number of seats in the German Bundestag given uniform swing from 2017 results.
library(hextri)
library(ggplot2)
library(ggparliament)
library(dplyr)
library(readr)
library(tidyr)
library(sf)
df = read_csv("data/results.csv") %>%
replace(is.na(.), 0) %>%

Keybase proof

I hereby claim:

  • I am lennybronner on github.
  • I am lbronner (https://keybase.io/lbronner) on keybase.
  • I have a public key ASBuwVjvoyur4pPPykO_1_lfdhEsbYuHlToUIBHTbdUTzwo

To claim this, I am signing this object:

import scipy
import numpy as np
import itertools
# critical value for confidence interval using f distribution (two sided)
# f has n and d degrees of freedom
def get_f(n, d, conf=0.95):
return scipy.stats.f.ppf((1 + conf) / 2, n, d)
import numpy as np
from scipy.optimize import fsolve, least_squares, root
def pairwise(iterable):
return list(zip(iterable[::2], iterable[1::2]))
def equations(p, mus, cov):
equations = []
def alpha_eq(alpha, beta):