View optimism_corrected_calibration.py
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 |
View LRT
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) |
View binning.R
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) | |
set.seed(7) | |
N = 1000 | |
x = rnorm(N) | |
p = plogis(0.2*x - 0.8) | |
y = rbinom(N, 1, p) | |
tibble(x, y) %>% | |
mutate(z = cut_number(x, 5)) %>% |
View squared_error_plot.py
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 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
x = np.random.normal(size = 10) | |
y = 2*x + 1 + np.random.normal(0, 0.3, size=x.size) | |
grid = np.linspace(-12, 20, 25) | |
b0, b1 = np.meshgrid(grid, grid) |
View r-squared-sim.py
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 | |
import matplotlib.pyplot as plt | |
from sklearn.linear_model import LinearRegression | |
from scipy.special import expit, logit | |
from itertools import product | |
import pandas as pd | |
import seaborn as sns | |
def make_regression_data(n, alpha, sigma): | |
View bayesian_penguins.R
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(palmerpenguins) | |
library(rstanarm) | |
library(tidybayes) | |
library(tidyverse) | |
library(brms) | |
minsmaxs = penguins %>% | |
drop_na() %>% | |
group_by(species) %>% | |
summarise(low = min(flipper_length_mm), |
View ruzzle.py
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 string | |
import numpy as np | |
import networkx | |
import pickle | |
import pandas as pd | |
#First, we need to determine the set of legal moves in the game. | |
# The grid is 4x4, and we can move in any direction so long as we don't | |
# retrace our steps. | |
# This means we take a simple walk on a graph |
View Bounded Regression.py
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 sklearn.svm import SVR | |
from sklearn.pipeline import Pipeline | |
from sklearn.compose import TransformedTargetRegressor | |
from scipy.stats import beta | |
from scipy.special import expit, logit | |
np.random.seed(0) | |
# Generate features |
View simulate_power.R
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) | |
logit <- function(p) log(p/(1-p)) | |
simulate_trial<-function(N, effect_size){ | |
catheter_diameter = sample(c(-1,0,1), replace = T, size = N) | |
vaso_band = rbinom(N, 1, 0.5) | |
X = model.matrix(~catheter_diameter*vaso_band) | |
View stay.R
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(lubridate) | |
#Make fake data | |
dates2019 <- seq(ymd('2019-01-01'), ymd('2019-12-31'), by ='1 week') | |
dates2020 <- seq(ymd('2020-01-01'), ymd('2020-12-31'), by ='1 week') | |
admission <- sample(dates2019, size = 10) | |
discharge <- sample(dates2020, size = 10) |
NewerOlder