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
cut_mixture <- function(x, range = NULL, tol = 1e-6, maxit = 100) { | |
n <- length(x) | |
if (is.null(range)) { | |
range <- c(min(x), max(x)) | |
} | |
# Initialization | |
# Initial value of pi1 are the proportion of x within 2 standard deviations of mu | |
huber_out <- huber(x) |
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
set.seed(42) | |
n <- 50 | |
x1 <- rnorm(n, mean = 5) | |
x2 <- rnorm(n, mean = 0) | |
x3 <- rnorm(n, mean = 20) | |
plot(density(x1), xlim = c(-5, 25)) | |
lines(density(x2), col = "red") |
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
normalmix_loglike <- function(x, y) { | |
y <- as.factor(y) | |
x1 <- x[y == levels(y)[1]] | |
x2 <- x[y == levels(y)[2]] | |
n1 <- length(x1) | |
n2 <- length(x2) | |
n <- n1 + n2 | |
w1 <- n1 / 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
# The following script scrapes ESPN's MLB Standings Grid and writes the | |
# standings for each American League (AL) team to a CSV file, which has the following | |
# format: | |
# Team, Opponent, Wins, Losses | |
from bs4 import BeautifulSoup | |
import urllib2 | |
import re | |
import csv |
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
Interactive Visualization of CyTOF Data | |
======================================================== | |
```{r setup, echo=FALSE} | |
library(rgl) | |
knit_hooks$set(webgl = hook_webgl) | |
opts_knit$set(upload.fun = imgur_upload, base.url = NULL) # upload all images to imgur.com | |
``` | |
This report produces a 3D visualization of the CD8+ T-cell subsets from [Newell et al. (2012)](http://www.ncbi.nlm.nih.gov/pubmed/22265676) using principal components analysis (PCA). |
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
import nltk | |
from nltk.collocations import * | |
from nltk.book import * | |
import re | |
bigram_measures = nltk.collocations.BigramAssocMeasures() | |
# Monty Python and the Holy Grail | |
# Reduces tokens to words. Ignores ALL CAPS words, which are the speaker in the movie. |
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 info about census regions, see: | |
# http://en.wikipedia.org/wiki/List_of_regions_of_the_United_States#Census_Bureau-designated_regions_and_divisions | |
# Region - Northeast | |
# Division - New England | |
new_england <- data.frame( | |
region = "Northeast", | |
division = "New England", | |
state = c("ME", "NH", "VT", "MA", "RI", "CT") |
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
import numpy as np | |
import pandas as pd | |
from itertools import chain, izip, repeat | |
np.random.seed(42) | |
num_rows = 10 | |
num_features = 5 | |
num_feature_values = 3 | |
# Builds tuples of features with many values per feature |
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(dplyr) | |
group_size <- 20 | |
foo <- iris[1:119, ] | |
filter(group_by(foo, Species), n() >= group_size) |
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
# FCC's Census Block Conversions API | |
# http://www.fcc.gov/developers/census-block-conversions-api | |
latlong2fips <- function(latitude, longitude) { | |
url <- "http://data.fcc.gov/api/block/find?format=json&latitude=%f&longitude=%f" | |
url <- sprintf(url, latitude, longitude) | |
json <- RCurl::getURL(url) | |
json <- RJSONIO::fromJSON(json) | |
as.character(json$County['FIPS']) | |
} |