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
##################################################################### | |
# Created by Scott Chamberlain | |
# Ecology and Evolutionary Biology Dept., Rice University | |
# Houston, TX 77005, USA | |
# [email protected] | |
# http://schamber.wordpress.com/ | |
##################################################################### | |
##### Directions | |
#Put your phylogeny, in format required by phylometa (see Phylometa manual), in your working directory |
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
# Convert degrees to radians | |
deg2rad <- function(deg) return(deg*pi/180) | |
# Calculates the geodesic distance between two points specified by | |
# radian latitude/longitude using the Haversine formula | |
# Ouputs distance between sites 1 and 2 as meters | |
gcd.hf <- function(long1, lat1, long2, lat2) { | |
R <- 6371 # Earth mean radius [km] | |
delta.long <- (long2 - long1) | |
delta.lat <- (lat2 - lat1) |
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
# Run these functions first (scalePhylo, assign.ages, and assign.brlen) | |
# scalePhylo, assign.ages, and assign.brlen written by Gene Hunt (http://paleobiology.si.edu/staff/individuals/hunt.cfm) | |
# AdjBrLens written by Scott Chamberlain ([email protected]) | |
scalePhylo<- function(tr, tip.ages, node.mins=NULL, min.diff=0.1) | |
## tr is a 'phylo' object | |
## tip.ages is a vector of the ages of terminal taxa (best if this vector has names that match the taxa labels) | |
## tip.ages MUST BE A NAMED VECTOR, that is, e.g., names(tipages) <- tree$tip.label [where tipages is a numeric vector of ## the tip ages] | |
## node.mins is a vector of optional constraints on nodes | |
## min.diff is the minimum branch length that will be imposed |
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
##################################################################### | |
# Created by Scott Chamberlain | |
# Ecology and Evolutionary Biology Dept., Rice University | |
# Houston, TX 77005, USA | |
# [email protected] | |
##################################################################### | |
# Function to split confidence intervals, this function is required in the below functions | |
CI_split <- function(a){ | |
dd<-c(gsub("\\(","",unlist(strsplit(a[5],","))[1]),gsub("\\)","",unlist(strsplit(a[5],","))[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
##################################################################### | |
# Created by Scott Chamberlain | |
# Ecology and Evolutionary Biology Dept., Rice University | |
# Houston, TX 77005, USA | |
# [email protected] | |
# http://schamber.wordpress.com/ | |
##################################################################### | |
########Directions | |
#Put your phylogeny, in format required by phylometa (see Phylometa manual), in your working directory |
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
############################################## | |
# Created by Scott Chamberlain | |
# Ecology and Evolutionary Biology Dept., Rice University | |
# Houston, TX 77005, USA | |
# [email protected] | |
############################################## | |
#### Load packages | |
require(stringr); require(ape); require(plyr); require(reshape2) | |
#### Set directory |
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
# a = data frame | |
# b = list of variables in x | |
# c = list of variables in y | |
# method_ = one of pearson, spearman, kendall (or their abbreviations) | |
# output is a data frame with as many columns as b * c | |
GetCorrs <- function(a, b, c, method_) { | |
dfout_ <- list() | |
names <- list() | |
names_ <- list() |
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
# load packages | |
require(plyr); require(reshape2) | |
# Make immutable data frame | |
baseball_i <- idata.frame(baseball) | |
# Example 1 - idata.frame more than twice as fast | |
system.time( replicate(50, ddply( baseball, "year", summarise, mean(rbi))) ) | |
system.time( replicate(50, ddply( baseball_i, "year", summarise, mean(rbi))) ) |
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
###### Simple function for plotting phylogenies in ggplot2 | |
# x = a phylo object | |
# form = one of: star or ladder | |
# dependencies: ape, ggplot2, adephylo (loaded within function) | |
ggtree <- function(x, form) { | |
# Load packages | |
require(ape); require(ggplot2); require(adephylo) | |
# Define plotting format | |
phytheme_ <- function() |
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
#### Simulations | |
install.packages(c("ape","reshape2","ggplot2")) | |
require(ape); require(reshape2); require(ggplot2) | |
source("http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/phylosig/v0.3/phylosig.R") | |
source("http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/fastBM/v0.4/fastBM.R") | |
# Simulation function physig_sim | |
# input: x = number of species in tree | |
# output: a vector length two with (K, lamba) | |
physig_sim <- function(x) { |
OlderNewer