Andrew Barr
July 6, 2015
ts1 <- cumsum(rnorm(1000))
ts2 <- cumsum(rnorm(1000))
library(ggplot2) | |
library(reshape2) | |
n <- 7000 | |
theMean <- 0 | |
theSD <- 5 | |
A <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD) | |
B <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD) | |
C <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD) | |
modelID <- 1:n |
#get the current md5sum, and use awk to strip out filename, which is reuturned as well | |
#note, this assumes that md5sum_of_database_at_last_backup.txt exists and contains the hash of db at last backup | |
#currently no error checking | |
currentMD5=$(md5sum test.db | awk '{print $1}') | |
lastMD5=$(cat /home/user/md5sum_of_database_at_last_backup.txt) | |
if [ "$currentMD5" == "$lastMD5" ] | |
then |
library(plotrix) | |
cols <- c(rainbow(6),"white") | |
radii <- seq(from=1, to=0.5, length.out = length(cols)) | |
plot(0,0,ylim=c(0,9), type = "n") | |
lapply(1:length(cols), FUN=function(index){ | |
draw.circle(0,0,radius=radii[index], col=cols[index]) | |
}) |
## updated with input from @richfitz and @hadley - Thanks, guys!! | |
export_eps <- function(filename, expression, ...){ | |
old <- setEPS() | |
on.exit(do.call(ps.options, old), add = TRUE) | |
postscript(filename, ...) | |
on.exit(dev.off(), add = TRUE) | |
expression | |
} |
from mesa.datacollection import DataCollector | |
class MyDataCollector(DataCollector): | |
## subclass DataCollector to only collect data on certain agents | |
## in this case, I only report them if they are NOT alive | |
## self.alive is an attribute that I track for my agents | |
def collect(self, model): | |
""" Collect all the data for the given model object. """ | |
if self.model_reporters: | |
for var, reporter in self.model_reporters.items(): |
library(factoextra) | |
PCA <- prcomp(iris[,1:4], scale=T) | |
fviz(PCA, "var") | |
fviz(PCA, "ind", repel=T, habillage = iris$Species, label='none') | |
fviz_ellipses(PCA,habillage = iris$Species, ellipse.type = "convex", geom="point") + | |
labs(title="mytitle") |
compound <- function(start, growthrate_percent, fees_percent, years=15) { | |
amount <- start | |
growthrate_proportion <- growthrate_percent/100 | |
fees_proportion <- fees_percent/100 | |
yearly_vals <- rep(NA, years) | |
for(year in 1:years) { | |
amount <- amount*(1+growthrate_proportion) - amount*fees_proportion | |
yearly_vals[year] <- amount | |
} | |
plot(x=1:years,y=yearly_vals, pch=16, cex=2, ylab="total value in dollars", xlab="year", main=sprintf("growing at %.3f%% with fees of $%.3f%%\nstarting value: $%.2f\nending value: $%.2f",growthrate_percent, fees_percent,start, amount)) |