Skip to content

Instantly share code, notes, and snippets.

View JackStat's full-sized avatar

Tyler Hunt JackStat

  • Salt Lake City, UT
View GitHub Profile
@JackStat
JackStat / animate-lm-optimization.R
Created February 13, 2020 00:18
Animating the line fitting process for a simple linear model
library(tidyverse)
library(gganimate)
library(modelr)
options(na.action = na.warn)
slopes <- 0
intercepts <- 0
fit <- 0
@JackStat
JackStat / Visualizing T-Test Statistical Power.R
Last active February 27, 2019 16:00
Sample Size Impact on Statistical Power
## Let's create a function for conducting power analysis for two groups with a t-test
t.test.power <- function(N = 100, samples = 100, g1_mean = 0, g1_sd = 1,
g2_mean = 0, g2_sd = 1){
## Setting up an empty vector to collect p-values for each sample
PValues <- rep(NA, samples)
Group1Mean <- rep(NA, samples)
Group2Mean <- rep(NA, samples)
for(i in 1:samples){
library(curl)
testfunc <- function(x){
## Setting up data vendor calls in parallel
###############################
out <<- list()
dbout <<- list()
@JackStat
JackStat / xgb.plot.single.tree.R
Last active March 27, 2019 22:31
plots a single tree from xgboost model
graphTree <- function(feature_names, model, tree) {
allTrees <- xgb.model.dt.tree(feature_names = feature_names, model = model)
allTrees <-
allTrees %>%
filter(Tree == tree)
allTrees <- data.table(allTrees)
library(xgboost)
library(dplyr)
library(parallel)
library(ModelMetrics)
print(detectCores())
Train <-
iris %>%
mutate(
@JackStat
JackStat / allScoringSummary.R
Created October 27, 2016 03:11
Pulls scoring summary for all games in 2016 up to week 8
#devtools::install_github("JackStat/cfb")
library(foreach)
library(cfb)
TotalWeeks = 8
allScoringSummary <- foreach(i = 1:TotalWeeks, .combine = 'rbind') %do% {
message(i)
scb <- NCAAscoreboard(2016, i)
library(microbenchmark)
SS <- runif(10000)
forLoop <- function(x){
fill = rep(NA, length(x))
for(i in 1:length(x)){
fill[i] = sqrt(x[i])
}
return(fill)
}
@JackStat
JackStat / quick auc comparison
Last active July 28, 2017 13:48
Quick benchmark of auc from various R packages
N = 100000
Actual = as.numeric(runif(N) > .5)
Predicted = as.numeric(runif(N))
actual = Actual
predicted = Predicted
s1 <- system.time(a1 <- ModelMetrics::auc(Actual, Predicted))
## Suffers from integer overflow
s2 <- system.time(a2 <- Metrics::auc(Actual, Predicted))
@JackStat
JackStat / vagrant_spot_instance.md
Last active September 22, 2015 03:07 — forked from ozzyjohnson/vagrant_spot_instance.md
Use an EC2 spot instance with Vagrant

Setup:

git clone git@github.com:nabeken/vagrant-aws.git
cd vagrant-aws
git checkout spot-3
gem build vagrant-aws.gemspec
vagrant install plugin vagrant-aws-0.5.0.gem

Vagrantfile:

## 2010-06-25
## (c) Felix Andrews <felix@nfrac.org>
## GPL-2
## If 'which' is given it should be a logical matrix specifying bold cells.
## Otherwise: in each column or row with numeric data, the maximum or minimum
## value is set bold; 'max' can have entries for each column/row, NA means skip.
## Examples:
## library(xtable)