Skip to content

Instantly share code, notes, and snippets.

View Dpananos's full-sized avatar
🏠
Working from home

Demetri Pananos Dpananos

🏠
Working from home
View GitHub Profile
# 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)
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)) %>%
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)
@Dpananos
Dpananos / r-squared-sim.py
Created October 23, 2020 02:28
Simulation for R squared CI coverage
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):
library(palmerpenguins)
library(rstanarm)
library(tidybayes)
library(tidyverse)
library(brms)
minsmaxs = penguins %>%
drop_na() %>%
group_by(species) %>%
summarise(low = min(flipper_length_mm),
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
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
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)
@Dpananos
Dpananos / stay.R
Created June 6, 2019 01:29
Length of stay in days
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)
library(tidyverse)
N = 1000
#So imagine we have all the data we need for people with low birth weights
race = sample(c('Caucasian','AfricanAmerican'), size = N, replace = T) #Race of people who have low birth weight
birthweight = sample(c('Low','Normal'), size = N, replace = T)
social_class = sample(c('Upper','Middle','Lower'), size = N, replace = T) #Social class of people with low birth weight. These are the strata