Skip to content

Instantly share code, notes, and snippets.

View gowerc's full-sized avatar

Craig Gower-Page gowerc

View GitHub Profile
import pandas as pd
import numpy as np
dat = pd.DataFrame({
"player1" : ["A", "A", "A", "A","A","B","B", "B", "C", "C", "C", "C", "C"],
"player2" :[ "B", "C", "B", "B", "C", "A", "C", "C", "A", "B", "A", "B", "B"],
"player1_won" : [ 1, 0, 1, 1, 1, 0, 1, 0 , 1, 0 , 0, 0, 0]
})
names = sorted(set(dat["player1"]))
@gowerc
gowerc / async_web_api.py
Created May 9, 2021 21:58
Example of using Async http requests in python
import aiohttp
import asyncio
URLS = [
"http://www.laughfactory.com/jokes/clean-jokes/2",
"http://www.laughfactory.com/jokes/clean-jokes/3",
"http://www.laughfactory.com/jokes/clean-jokes/4",
"http://www.laughfactory.com/jokes/clean-jokes/5",
"http://www.laughfactory.com/jokes/clean-jokes/6",
"http://www.laughfactory.com/jokes/clean-jokes/7",
library(dplyr)
library(purrr)
library(parallel)
library(knitr)
set.seed(40130)
CIVS <- c("A", "B", "C", "D")
true_score_mean <- 0
true_score_sd <- 0.5
###################################################
#
#
# Setup Dataset
#
#
#
library(tidyverse)
library(flexsurv)
@gowerc
gowerc / file_format_performance_tests.R
Last active September 19, 2022 10:52
R data formats performance tests
library(dplyr)
library(arrow)
library(stringi)
library(lubridate)
time_it <- function(expr) {
start <- Sys.time()
x <- eval(expr)
stop <- Sys.time()
tdiff <- round(as.numeric(difftime(stop, start, units = "sec")), 4)
#############################
#
#
# Exploring the impact of completely random & independently
# distributed covariates
#
#
#############################
@gowerc
gowerc / cran_clang_rdevel.sh
Last active December 14, 2022 17:00
R CMD CHECK on R devel clang
# Relevant Links
#
# CRAN Server builds
# https://cran.r-project.org/web/checks/check_flavors.html#r-devel-linux-x86_64-debian-clang
#
# clang + devel specific instructions
# https://www.stats.ox.ac.uk/pub/bdr/Rconfig/r-devel-linux-x86_64-fedora-clang
#
# Instructions for building R from source
# https://docs.posit.co/resources/install-r-source/
#######################################
# Classes
#######################################
#
# The class function is how you construct objects in python. There are several key concepts to
# understand
#
# General syntax:
# class <object name>(<object to inherit from>):
# <define class wide attributes>
@gowerc
gowerc / distribution_coverage.R
Last active August 18, 2023 10:47
Examples of distributions & transformations where 95% probability is contained within mean +- 1.96 * sd
##################################
#
#
# This simple script aims to highlight several non-normal distributions
# and transformations of distributions where 95% of the distribution
# can be found within the interval mu +- 1.96*sigma
# Results can be found as comments inline with the code
#
@gowerc
gowerc / brms.R
Created October 2, 2023 14:57
brms Joint Model
library(brms)
library(dplyr)
bform <-
bf(y1 ~ age, family = gaussian() ) +
bf(y2 ~ age + y1, family = gaussian()) +
set_rescor(FALSE)
df <- tibble(