Skip to content

Instantly share code, notes, and snippets.

@ramhiser
ramhiser / gist:1421185
Created December 2, 2011 01:15
Randomly subsample a matrix or data frame (Useful with the 'boot' package in R)
#' Randomly subsample a matrix or data frame.
#'
#' To randomly subsample, we are using the parametric option in the boot function
#' within the boot package. The 'parametric' option requires the specification of
#' a 'ran.gen' function to generate observations based on the original data and a list of
#' maximum likelihood estimators (MLE). We utilize this method, but instead of the
#' MLE, we instead pass the subsample_size.
#'
#' As noted in the boot documentation: Use of sim = "parametric" with a suitable ran.gen
#' allows the user to implement any types of nonparametric resampling which are not
@ramhiser
ramhiser / .emacs
Created December 8, 2011 23:26
My .emacs File
(require 'mouse)
(xterm-mouse-mode t)
(defun track-mouse (e))
;; Save all backup file in this directory.
@ramhiser
ramhiser / .bash_profile
Created January 5, 2012 01:08
My .bash_profile File
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# Creates symbolic links from various subfolders in ~/Dropbox/ to ~/
# This allows for a more consistent structure across my many computers.
if [ ! -L ~/scripts ]; then
ln -s ~/Dropbox/scripts/ ~/scripts
fi
@ramhiser
ramhiser / .bashrc
Created January 5, 2012 01:09
My .bashrc file
PATH=~/scripts:/usr/local/bin:$PATH:/usr/local/texlive/2011/bin/x86_64-darwin:/usr/local/sbin
export PATH
# Never save or restore when running R
alias R='R --no-save --no-restore-data --quiet'
@ramhiser
ramhiser / install.packages()
Created February 22, 2012 20:59
rgl Installation Error on Mac OS X
install.packages("rgl", dep = TRUE)
Installing package(s) into ‘/usr/local/Cellar/r/2.14.1/R.framework/Versions/2.14/Resources/library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.fhcrc.org/src/contrib/rgl_0.92.798.tar.gz'
Content type 'application/x-gzip' length 1677772 bytes (1.6 Mb)
opened URL
==================================================
downloaded 1.6 Mb
* installing *source* package ‘rgl’ ...
@ramhiser
ramhiser / test.Rmd
Created July 15, 2012 21:35
knitr Issue for Rmd and Rcpp
Rmd file to show the issue...
```{r rcpp}
library(Rcpp)
library(inline)
# C++ code to calculate the length of a vector.
src <- '
Rcpp::NumericVector vec_x(x);
int n = vec_x.size();
@ramhiser
ramhiser / gist:4079946
Created November 15, 2012 17:28
flowClust Quantile
#' Computes the quantile from flowClust for a given vector of probabilties
#'
#' We estimate the quantile from a \code{flowClust} fit with a combination of
#' numerical integration and a root-finding method. We are effectively
#' estimating the cumulative distribution function (CDF) of the mixture density
#' estimated by \code{flowClust}.
#'
#' Because we are using numerical methods, we also need an \code{interval} of
#' values in which we will attempt to find the specified quantile.
#'
@ramhiser
ramhiser / download-data.py
Created November 20, 2012 21:25
Downloads Kaggle Data - Handwriting Recognition
import requests
# The direct link to the Kaggle data set
data_url = 'http://www.kaggle.com/c/digit-recognizer/download/train.csv'
# The local path where the data set is saved.
local_filename = "train.csv"
# Kaggle Username and Password
kaggle_info = {'UserName': "my_username", 'Password': "my_password"}
@ramhiser
ramhiser / find_peaks.r
Last active July 2, 2021 06:08
Find local maxima (peaks) in a vector
#' Finds the local maxima (peaks) in the given vector after smoothing the data
#' with a kernel density estimator.
#'
#' First, we smooth the data using kernel density estimation (KDE) with the
#' \code{\link{density}} function. Then, we find all the local maxima such that
#' the density is concave (downward).
#'
#' Effectively, we find the local maxima with a discrete analogue to a second
#' derivative applied to the KDE. For details, see this StackOverflow post:
#' \url{http://bit.ly/Zbl7LV}.
@ramhiser
ramhiser / gist:5564529
Created May 12, 2013 18:56
Preferred Options Tidying R Source Code via formatR
tidy.source(source = "messy-code.r", file = "tidy-code.r", width.cutoff = 80, reindent.spaces = 2)