This file contains hidden or 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
# For each day, find the appropriate Poisson Parameter and use it to calculate the likelihood of the actual view count | |
# Likelihood = P(D|H) | |
Calc.Likelihood <- function(changes, poissons, stats, periods) { | |
likelihood <- 0 | |
for (day in 1:nrow(stats)) { | |
proceed <- FALSE | |
period <- 1 | |
while (!proceed) { | |
if (day < changes[period]) { |
This file contains hidden or 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(httr) | |
library(rjson) | |
key <- '<edited>' | |
secret <- '<edited>' | |
tokenURL <- 'http://api.fitbit.com/oauth/request_token' | |
accessTokenURL <- 'http://api.fitbit.com/oauth/access_token' | |
authorizeURL <- 'http://www.fitbit.com/oauth/authorize' | |
fbr <- oauth_app('MyHome', key, secret) |
This file contains hidden or 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(rjson) | |
library(reshape) | |
user <- 'TheLaughFactory' | |
videos <- data.frame(matrix(data = 0, nrow = 1000, ncol = 8)) | |
colnames(videos) <- c('id', 'link', 'title', 'date', 'duration', 'view.count', 'avg.rating', 'num.raters') | |
found.all <- FALSE | |
index <- 1 |
This file contains hidden or 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
# Quantifies homecourt advantage in each regular season | |
library(RCurl) | |
library(XML) | |
# Get Basketball Reference regular season schedule with home margin of victory for each game | |
GetSchedule <- function(year) { | |
url <- paste("http://www.basketball-reference.com/leagues/NBA_", year, "_games.html", sep = "") | |
tables <- readHTMLTable(url) |
This file contains hidden or 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(ggplot2) | |
library(moments) | |
library(sportsTools) | |
library(dplyr) | |
clean.lines <- function(data) { | |
data <- data[-which(is.na(data$home.line)), ] | |
data$expected <- -data$home.line | |
data$actual <- data$home.score - data$away.score | |
data$residual <- data$actual - data$expected |
This file contains hidden or 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(sportsTools) | |
library(ggplot2) | |
library(grid) | |
# All years since NBA-ABA Merger | |
years <- 1977:2016 | |
# Create empty data frame to hold results from each year | |
df <- data.frame(matrix(nrow = length(years), ncol = 4)) | |
colnames(df) <- c('year', 'mean', 'sd', 'n') |
This file contains hidden or 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
options(stringsAsFactors = FALSE) | |
ScrapeLSN <- function(school, cycle) { | |
base.url <- 'http://SCHOOL.lawschoolnumbers.com/stats/CYCLE' | |
url <- gsub('SCHOOL', school, base.url) | |
url <- gsub('CYCLE', cycle, url) | |
src <- readLines(url) |
This file contains hidden or 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(sportsTools) | |
library(dplyr) | |
library(ggplot2) | |
start.year <- 2001 | |
end.year <- 2015 | |
all.games <- data.frame() | |
for (year in start.year:end.year) { |
This file contains hidden or 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
Player | Season | |
---|---|---|
Allen Iverson | 2006 | |
Amar'e Stoudemire | 2005 | |
Anthony Davis | 2016 | |
Blake Griffin | 2016 | |
Carmelo Anthony | 2007 | |
Charles Barkley | 1988 | |
Chris Mullin | 1989 | |
Chris Webber | 2001 | |
Clyde Drexler | 1989 |
This file contains hidden or 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
Player | Position | Team | Prime BPM | Projected MPG | |
---|---|---|---|---|---|
Stephen Curry | PG | GSW | 12.4 | 30.4 | |
Draymond Green | PF | GSW | 6.4 | 30.8 | |
Andrew Bogut | C | GSW | 4.4 | 23.7 | |
Andre Iguodala | SG | GSW | 4.4 | 32.0 | |
Leandro Barbosa | SG | GSW | 2.9 | 29.4 | |
Klay Thompson | SG | GSW | 2.7 | 28.7 | |
Harrison Barnes | SF | GSW | 1.1 | 25.4 | |
Festus Ezeli | C | GSW | 0.9 | 16.0 | |
Brandon Rush | SG | GSW | 0.7 | 23.7 |