Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew McDavid amcdavid

View GitHub Profile
@amcdavid
amcdavid / .Rprofile
Last active Nov 14, 2020
Load environment modules (https://modules.readthedocs.io/en/latest/index.html) after R is started
View .Rprofile
local({
# modify as needed
modules = c("git", "git-lfs", "gcc")
capt = system2("./capture_module_environment.sh", modules, stdout = TRUE)
split = strsplit(capt, '=', fixed = TRUE)
out = lapply(split, function(v){
do.call(Sys.setenv, stats::setNames(list(v[2]), v[1]))
})
message("Added environment variables for ", paste(modules, collapse = ', '))
})
View number_of_folds.R
# 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
View 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))