Andrew Barr
September 19, 2015
library(ggplot2)
groups <- factor(rep(c("A", "B"), 100))
x <- rnorm(200) | to-report prob-density [x mu sigma] | |
| ;reporter which returns the probablity density for a given value x | |
| ;in a normal distribution parametrized by mean = mu and standard deviation = sigma | |
| report (1 / (sigma * (sqrt (2 * pi)))) * (exp (-0.5 * ((x - mu) / sigma ) ^ 2)) | |
| end |
| 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)) |
| 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") |
| 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(): |
| ## 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 | |
| } |
| 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]) | |
| }) |
| #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(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 |