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
# image trees are named something like paup1.tre to paup100.tre | |
require(ape) | |
# could use a for loop, but sapply is faster and will parallelize | |
sapply(1:100, function(i){ | |
tree <- read.tree(paste("paup", i, ".tre", sep="")) | |
pdf(file=paste("paup", i, ".pdf", sep="")) | |
plot(tree) # add fancy plotting options etc, | |
dev.off() | |
}) |
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 function f will remember whatever options it is passed | |
f <- function(y, ...){ | |
out <- y + dnorm(...) | |
list(out, opts=list(...)) | |
} | |
## This is the way to call the function using its exact arguments | |
a <- f(1, x=4, sd=2, mean=4) | |
b <- do.call(f, c(list(y=1), a$opt)) | |
identical(a,b) # TRUE |
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
##### socialR header info ##### | |
require(socialR) | |
script <- "example.R" # Must specify the script name! | |
gitcommit(script) # Must commmit at start! | |
##### Optional but a good idea ##### | |
#almost requisite, if not me running "repo"/"dir" | |
gitopts = list(user = "cboettig", dir = "demo", repo = "socialR") | |
on.exit(system("git push")) # For git links. May prompt for pw, | |
tags <- "test" ## multiple possible: space, delim, multiple items, etc. |
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
data(faithful) | |
attach(faithful) | |
## EM Algorithm | |
W = waiting | |
s = c(0.5, 40, 90, 16, 16) | |
em = function(W,s) { | |
Ep = s[1]*dnorm(W, s[2], sqrt(s[4]))/(s[1]*dnorm(W, s[2], sqrt(s[4])) + |
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
data(faithful) | |
attach(faithful) | |
#Assumes two gaussian populations of eruptions | |
W = waiting | |
# Guess of the parameters: | |
s = c(p=0.5, mu1=50, mu2=90, sigma1=30, sigma2=30) | |
# EXPECTATION STEP | |
expectation_step <- function(observed, parameters){ |
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
#segue_test.R | |
on.exit(stopCluster(myCluster)) | |
library(segue) | |
setCredentials(getOption("amazon_key"), getOption("amazon_secret")) | |
# Jeffery Breen's example, adapted with "custom function" works fine | |
my_fun <- mean # a custom definition | |
myList <- NULL |
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
@ARTICLE{, | |
author = {L.H. Yang and V. H. Rudolf}, | |
title = {Phenology, ontogeny and the effects of climate change on the timing | |
of species interactions}, | |
journal = {Ecology Letters}, | |
year = {2010}, | |
volume = {13}, | |
pages = {1-10}, | |
doi = {10.1111/j.1461-0248.2009.01402.x}, |
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(segue) | |
setCredentials(getOption("amazon_key"), getOption("amazon_secret")) | |
require(mcmcTools) | |
X <- rnorm(20, 2, 5) | |
loglik <- function(pars){ | |
sum( dnorm(X, mean=pars[1], sd=pars[2], log=TRUE) ) | |
} | |
prior <- function(pars){ | |
1/pars[2]^2 | |
} |
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
mat <- rbind(c(1),c(2),c(3)) # three rows, 1 column | |
layout(mat, height = c(1, .5, .5)) # height of each row | |
par(mar=c(4,6,4,2)) # can be changed for each subsequent plot |
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
## THANKS to David Scott for this one: | |
## http://r.789695.n4.nabble.com/Greek-letters-on-a-multi-line-plot-title-td1018642.html | |
### Change spacing to allow for multiline title | |
par(oma=c(2, 0, 4, 0)) | |
### Some greek letters | |
mu <- 0 | |
alpha <- 1 | |
beta <- 2 |