This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def poisson_bootstrap_nth_percentile_and_ci( | |
data: List[float], n_iter: int = 1000, alpha: float = 0.95, percentile: float = 95 | |
) -> Tuple[float, float, float, float]: | |
data = np.array(data) | |
n = len(data) | |
weights = np.random.poisson(1, (n_iter, n)) | |
percentiles = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bootstrap_nth_percentile_and_ci( | |
data: List[float], n_iter: int = 1000, alpha: float = 0.95, percentile: float = 95 | |
) -> Tuple[float, float, float, float]: | |
"""Compute the nth percentile and confidence interval using bootstrapping | |
Args: | |
data (List[float]): List of data | |
n_iter (int, optional): Number of bootstrap samples. Defaults to 1000. | |
alpha (float, optional): Confidence level. Defaults to 0.95. | |
percentile (float, optional): Percentile to compute. Defaults to 95. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bootstrap_mean_and_ci( | |
data: List[float], n_iter: int = 1000, alpha: float = 0.95 | |
) -> Tuple[float, float, float]: | |
n = len(data) | |
bootstrap_samples = np.random.choice(data, (n_iter, n), replace=True) | |
means = bootstrap_samples.mean(axis=1) | |
mean = means.mean() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH customers AS ( | |
SELECT 'Customer1' AS customer_id UNION ALL | |
SELECT 'Customer2' AS customer_id UNION ALL | |
SELECT 'Customer3' AS customer_id UNION ALL | |
SELECT 'Customer4' AS customer_id | |
) | |
SELECT | |
c.customer_id, | |
CONVERT(BIGINT, SUBSTRING(HASHBYTES('MD5', c.customer_id), 1, 5)) % 100 AS assigned_bucket | |
FROM customers c; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS customers AS | |
SELECT 'Customer1' AS customer_id UNION ALL | |
SELECT 'Customer2' AS customer_id UNION ALL | |
SELECT 'Customer3' AS customer_id UNION ALL | |
SELECT 'Customer4' AS customer_id; | |
SELECT | |
c.customer_id, | |
('0x' || md5(c.customer_id)[:10])::int64 % 100 as assigned_bucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
probability_assignments = {"Control": 50, "Variant 1": 30, "Variant 2": 20} | |
random_customer_ids = ["Customer1", "Customer2", "Customer3", "Customer4"] | |
def get_hash(customer_id): | |
hash_object = hashlib.md5(customer_id.encode()) | |
return hash_object.hexdigest()[:10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function adapted from https://github.com/AfricaBirdData/ABAP/ | |
# Only pulls presence data | |
library("tidyverse") | |
library("purrr") | |
jsonToTibble <- function(jsonfile) { | |
out <- jsonfile %>% | |
lapply(function(x) { | |
x[sapply(x, is.null)] <- NA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0. set up --------------------------------------------------------------- | |
# libraries | |
library(rabm) | |
library(tidyverse) | |
library(geojsonio) | |
library(broom) | |
library(ggplot2) | |
library(gganimate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
files <- list.files(path = "./data/", pattern = "*.csv") | |
df <- files %>% | |
map(function(x) { | |
read_csv(paste0("./data/", x)) | |
}) %>% | |
reduce(rbind) | |