Skip to content

Instantly share code, notes, and snippets.

View amcdavid's full-sized avatar

Andrew McDavid amcdavid

View GitHub Profile
# function to fold data into k folds. this returns a list of matrices where
# the 1st column in each is the response and all other columns are predictors
fold <- function(y, X, k){
n <- length(y)
lapply(0:(k-1)*n/k + 1, function(i){
cbind(y, X)[seq(from=i, length.out=n/k),]
})
}
# function to compute MSE for datasets with different numbers of folds
@amcdavid
amcdavid / heatmap3.R
Last active August 14, 2018 19:14 — forked from nachocab/heatmap3.R
# EXAMPLE USAGE
# example of colsidecolors rowsidecolors (single column, single row)
mat <- matrix(1:100, byrow=T, nrow=10)
column_annotation <- sample(c("red", "blue", "green"), 10, replace=T)
column_annotation <- as.matrix(column_annotation)
colnames(column_annotation) <- c("Variable X")
row_annotation <- sample(c("red", "blue", "green"), 10, replace=T)
row_annotation <- as.matrix(t(row_annotation))