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
###############Food web plotting function################ | |
### Date: 12/13/2011 | |
### Author: Edmund Hart (edmund.m.hart@gmail.com) | |
### Description: A function to create grahps of trophic networks using ggplot2 | |
### Plots food webs in a circular graph | |
### requires ggplot2 | |
######################################################### | |
library(ggplot2) | |
########## support function create.xy |
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
#' Description: Code using deSolve for some simple ecological ODE models | |
#' There are 3 examples, one is a simple LV Pred-Prey example with plots | |
#' The next is a Macarthur-Wilson model with plots of both the species curve and the equlibrium points | |
#' The last plot is a quick crack at putting stochasticity into the model by adding oscillations in I with t. | |
#' LV code is modified from a blog post here: http://assemblingnetwork.wordpress.com/2013/01/31/two-species-predator-prey-systems-with-r/ | |
#' Other additions are my own | |
#' | |
#' Author: Edmund Hart | |
#' Date: 3/28/2013 | |
#' E-mail: edmund.m.hart@gmail.com |
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(ggplot2) | |
### Imagine a coin is flipped 100 times | |
### You get 60 heads | |
### How can you assess if the coin is fair or not? | |
# Set up the plot | |
binom_density <- dbinom(0:100,100,.5) | |
flips <- data.frame(flip_count = 0:100, density = binom_density) |
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
num2letter = {"2":"abc", "3":"def", "4":"ghi", "5":"jkl", "6":"mno", | |
"7":"pqrs", "8":"tuv", "9":"wxyz"} | |
def keys2letters(key_presses): | |
results = [x for x in num2letter[key_presses[0]]] | |
if len(key_presses) <= 1: | |
return(results) | |
else: | |
for x in key_presses[1:]: |
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
theme.blank = function(size=12) { | |
theme( | |
#axis.line=element_blank(), | |
axis.text.x=element_text(size=size), | |
axis.text.y=element_text(size=size), | |
#axis.ticks.y=element_text(size=size), | |
# axis.ticks=element_blank(), | |
axis.ticks.length=unit(0.1, "lines"), | |
axis.ticks.margin=unit(0.5, "lines"), | |
axis.title.x=element_text(size=size*1), |
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
### Define terms to understand investment potentional | |
### This function will simulate scenarios to compare renting to buying and allow us to make an informed financial decision | |
## Parameters of the model (some are hard coded but can still be changed) | |
## r - Annual appreciation rate | |
## term - Term you want to own the house for (in months) | |
## house_cos - cost of the house in dollars | |
## ir - Interest rate of my mortgage | |
## closing - total closing costs |
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
### Define terms to understand investment potentional | |
### This function will simulate scenarios to compare renting to buying and allow us to make an informed financial decision | |
## Parameters of the model (some are hard coded but can still be changed) | |
## r - Annual appreciation rate | |
## term - Term you want to own the house for (in months) | |
## house_cos - cost of the house in dollars | |
## ir - Interest rate of my mortgage | |
## closing - total closing costs |
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("dplyr") | |
library("audio") | |
notes <- c(A = 0, B = 2, C = 3, D = 5, E = 7, F = 8, G = 10) | |
pitch <- "D D E D G F# D D E D A G D D D5 B G F# E C5 C5 B G A G" | |
duration <- c(rep(c(0.75, 0.25, 1, 1, 1, 2), 2), | |
0.75, 0.25, 1, 1, 1, 1, 1, 0.75, 0.25, 1, 1, 1, 2) | |
bday <- data_frame(pitch = strsplit(pitch, " ")[[1]], | |
duration = duration) |
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(lme4) | |
library(ggplot2) | |
#create some levels | |
levs <- as.factor(c("l1","l2","l3","l4","l5")) | |
#set the factor means | |
f_means <- c(6,16,2,10,13) | |
# set individual as a factor |
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
### "Smart brute force" algorithm. Works in most mortal situations. | |
### Works by looping through a matrix that is m by k and putting numbers in | |
### Is aware of the top and left cell, and works by sampling based on the probabilities of | |
### numbers that are left in the set of valid possible numbers, e.g. those not excluded by the neighborhood rules (von Neumann) | |
### Parameters: | |
### k -- The number of rows | |
### m -- The number of columns | |
### n -- 1:N vector of desired outcomes (plants in the blog post), e.g. if N = 3, your n parameter would be n <- 1:3 | |
### maxiter -- The maximum number of iterations you want to use in the algorithm (default is 100. |
NewerOlder