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
@Dpananos
Dpananos / twitter-glm.r
Created July 6, 2018 21:23
Analyze your twitter favorites over time
library(tidyverse)
library(lubridate)
library(rtweet)
user.name = 'PhDemetri'
#Get user's most recent tweets
user = get_timeline(user = user.name, n = 5000)
#Clean the data.
@Dpananos
Dpananos / gist:6d4a156fa45e58c12e44655594dd2a86
Created September 15, 2018 16:39
Confidence interval simulation
library(tidyverse)
n.samples = 25
set.seed(5)
rerun(20,rnorm(n.samples)) %>%
map_dfr(~data_frame(data = list(.x)), .id = 'samples') %>%
mutate(mu = map_dbl(data,mean),
se = map_dbl(data,~sd(.x)/sqrt(length(.x))),
top = mu +1.96*se,
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
@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)
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)
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
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
library(palmerpenguins)
library(rstanarm)
library(tidybayes)
library(tidyverse)
library(brms)
minsmaxs = penguins %>%
drop_na() %>%
group_by(species) %>%
summarise(low = min(flipper_length_mm),
@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):
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)