Skip to content

Instantly share code, notes, and snippets.

View tengpeng's full-sized avatar

Teng Peng tengpeng

View GitHub Profile
@tengpeng
tengpeng / gist:30268e415be0ac44eebb
Created February 21, 2015 21:48
MLE gamma in R
x <- c(22, 23.9, 20.9, 23.8, 25, 24, 21.7, 23.8, 22.8, 23.1, 23.1, 23.1, 23.5, 23, 23)
fitdistr(x, "gamma")
@tengpeng
tengpeng / gist:0e8fa3669c8d410f34f7
Created February 25, 2015 23:51
Check columns classes in R
# Check columns classes
sapply(DF, class)
@tengpeng
tengpeng / gist:43d37a089d538ab5b1c0
Created February 26, 2015 23:02
Convert multiple columns into factors
p143[1:2] = lapply(p143[1:2], as.factor)
@tengpeng
tengpeng / gist:6dabc0edf921a4833e13
Created February 27, 2015 00:56
OS X R speed up
cd /Library/Frameworks/R.framework/Versions/Current/Resources/lib
ln -sf /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib libRblas.dylib
ln -sf libRblas.0.dylib libRblas.dylib
\section{Standard Test}
\begin{tabular}{l|cc}
\textbf{GRE} & Verbal & Math \\
\hline
Score & 157 & 168 \\
Percentile & 73\% & 96\% \\
\end{tabular}\\[10pt]
pairedBootstrap <- function(yourData, responseName, numberBoot){
#####CREATE USEFUL VARIABLES FOR THE BOOTSTRAP METHOD
originalSampleSize <- dim(yourData)[1] #the data sample size
numberExplanatory <- dim(yourData)[2]-1 #the number of explanatory variables
#explanatory variable names
explanatoryNames <- setdiff(names(yourData),responseName)
#explanatory variable formula (for the lm function)
#################################################################
##### Perform the paired bootstrap for linear regression #####
##### #####
##### - yourData is a data frame containing the response and#####
##### explanatory variables(no extra variables should be#####
##### included) #####
##### - responseName is the name of your response variable #####
##### as it appears in the data frame(character) #####
##### - numberBoot is the number of bootstrap samples to #####
##### take #####
paste("p143$x", 1:25, sep = "", collapse = ",")
FantasyBaseball3 <- log(FantasyBaseball[, -1])
est_mean <- colMeans(FantasyBaseball3)
k=1
for (i in 1:7){
for (j in (i+1) : 8){
est <- est_mean[i]-est_mean[j]
pair <- paste(names(est_mean[i]), names(est_mean[j]), sep="~")
Lower <- est-margin
Upper <- est+margin
result[k, ]<- c(pair, est, Lower, Upper)
@tengpeng
tengpeng / gist:2fa57a3addc95ef4e733
Created April 5, 2015 05:01
Haase Diagram TikZ
\begin{center}
\begin{tikzpicture}
\node (max) at (0,4) {$M_{1}^{1}$};
\node (a) at (-2,2) {$A_{2}^{3}$};
\node (c) at (2,2) {$D_{2}^{3}$};
\node (d) at (-2,0) {$(B)_{3}^{6}$};
\node (ad) at (0,0) {$(AD)_{4}^{9}$};
\node (f) at (2,0) {$(C)_{3}^{6}$};