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) | |
library(rtweet) | |
user.name = 'PhDemetri' | |
#Get user's most recent tweets | |
user = get_timeline(user = user.name, n = 5000) | |
#Clean the data. |
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) | |
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, |
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) | |
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 |
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) |
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) | |
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 |
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 |
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), |
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): | |
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) |
OlderNewer