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
SET VARIABLE EXPERIMENT_START_DATE = TIMESTAMP '2024-10-01 00:00:00'; | |
SET VARIABLE EXPERIMENT_END_DATE = TIMESTAMP '2024-10-31 00:00:00'; | |
with prep_cleaned_exposures as ( | |
select distinct | |
userid, | |
treatment, | |
min(exposure_time) over (partition by userid) as exposure_time, | |
(min(treatment) over (partition by userid)) <> (max(treatment) over (partition by userid)) as multiple_exposures |
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(WeightIt) | |
library(tidyverse) | |
library(furrr) | |
plan(multisession, workers = 10) | |
sim <- function(n, l1, l2, l3, l4, ate, prop_br, ps_model_formula, simnum, ...) { | |
withr::with_seed(simnum, { |
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) | |
# Genuine confounding example. Sex confounds relationship between drug and death | |
set.seed(0) | |
n <- 1000000 | |
is_male <- rbinom(n, 1, 0.5) | |
drug <- rbinom(n, 1, 0.6 + 0.3*is_male) | |
y <- rbinom(n, 1, 0.4 - 0.1*drug + 0.4*is_male) | |
d <- tibble(drug, is_male, y) |
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
# Licensed to the Apache Software Foundation (ASF) under one | |
# or more contributor license agreements. See the NOTICE file | |
# distributed with this work for additional information | |
# regarding copyright ownership. The ASF licenses this file | |
# to you under the Apache License, Version 2.0 (the | |
# "License"); you may not use this file except in compliance | |
# with the License. You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# |
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 matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.stats import multinomial | |
import cmdstanpy | |
def simulate(n_transitions): | |
A = 1000 | |
B = 100 |
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) | |
library(marginaleffects) | |
g <- LETTERS[1:4] | |
N <- rpois(length(g), 100000) | |
theta <- c(0.1, 0.12, 0.14, 0.08) | |
y <- rbinom(length(g), N, theta) | |
d <- tibble(g, N, y) |
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(survival) | |
library(tidyverse) | |
library(broom) | |
library(marginaleffects) | |
# Make a toy model | |
gr <- sample(letters[1:2], size = 10000, replace=T) | |
g <- as.numeric(gr=='a') | |
etime <- rexp(length(gr), rate = (5+1*g)/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
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import pymc as pm | |
import arviz as az | |
N = 50_000 | |
treatment_conversions = np.array([541, 557, 559, 556, 530, 532, 516, 532, 528, 544, 519, 552]) | |
control_conversions = np.array([496, 524, 486, 500, 516, 475, 507, 475, 490, 506, 512, 489]) |
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 numpy as np | |
from statsmodels.nonparametric.smoothers_lowess import lowess | |
from sklearn.datasets import load_breast_cancer | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.model_selection import KFold, RepeatedKFold, GridSearchCV, cross_val_score | |
from sklearn.metrics import make_scorer, brier_score_loss | |
from sklearn.utils import resample |
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
# LRT | |
data = c(27,24,3,14,9,14,4,6,7,8) | |
m = matrix(data, nrow = 2) | |
theta_null = colSums(m)/sum(m) | |
theta_1 = m[1,]/sum(m[1,]) | |
theta_2 = m[2,]/sum(m[2,]) | |
L0 = dmultinom(colSums(m), prob = theta_null, log=T) | |
L1 = dmultinom(m[1,], prob = theta_1, log=T) + dmultinom(m[2,], prob = theta_2, log=T) |
NewerOlder