This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(boot) | |
library(plyr) | |
set.seed(22042017) # for reproducibility | |
generate_data <- function(nsamples=100) { | |
x <- rnorm(nsamples,mean=.75, sd=.5) | |
y <- 4 + 5*x -3*x^2 + rnorm(length(x), mean=0, sd = 1) | |
data.frame(x,y) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plyr) | |
# some very tight high-dimensional data vs some less tight HD data | |
big <- raply(75, rnorm(50)) | |
small <- raply(75, rnorm(50, sd=1/50)) | |
datas <- rbind(big, small) | |
colrs <- c(rep("black", 75), rep("red", 75)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# regression to the mean | |
n <- 10000 | |
base <- runif(n, 0,10) | |
dat <- data.frame(x=base+rnorm(n), y=base+rnorm(n)) | |
plot(dat) | |
abline(0,1, col="grey") | |
abline(lm(y~x, data=dat)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plyr) | |
experiment <- raply(10000, function() { | |
x <- runif(100, -1, 5) | |
y <- 1 + 2* x + rnorm(100,sd = 16) | |
split_x <- split(x, ceiling(seq_along(x)/5)) | |
split_y <- split(y, ceiling(seq_along(y)/5)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plyr) | |
set.seed(2017-06-08) | |
l=0.5 | |
# this distribution has mean and variance both = l above | |
# importantly it never produces values < 0 | |
plot(table(rpois(100, lambda=l))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is my experiment that I want to run many times | |
x <- rnorm(500) | |
y <- rnorm(500) | |
my_model <- lm(y~x) | |
# I usually like to write my results to a randomly named file. I recommend using an absolute path | |
# so you're 100% sure where the file ends up | |
random_output_file <-paste0("/home/einar/my_experiments/linear_model", as.character(sample(1:999999, 1)), ".RData") | |
save(my_model, file = random_output_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# commands to the batch system start with '#SBATCH ' | |
# pick a name for your job | |
#SBATCH --job-name=my_job | |
# I want 500 duplicate jobs that use a single cpu each | |
#---------------------------------------------------------------- | |
# one machine per job: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --- Version history --- | |
# 0.4: added variable to store file path, and $2 for base file name | |
# added variable to store desired reporting interval | |
# 0.3: added $1 to send in process ID at run time. | |
# 0.2: switched to $SECONDS for the loop. works. | |
# 0.1: didn't work well at all. | |
# --- Version history --- | |
# Usage: cputrack [PID] [filename] |
NewerOlder