Skip to content

Instantly share code, notes, and snippets.

View tengpeng's full-sized avatar

Teng Peng tengpeng

View GitHub Profile
@tengpeng
tengpeng / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@tengpeng
tengpeng / gist:5ec7134cefb638273b8b
Created February 14, 2015 21:47
Find sample size for given width of confidence interval for contrast in R
find_n = function(ep, g, n, MSE, SSW, w){
n = 4*(qt(1-ep/2, g*(n-1)))^2*MSE*SSW/w^2
return(n)
}
@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 = ",")