Skip to content

Instantly share code, notes, and snippets.

@sckott
sckott / taxize_example.R
Created June 3, 2011 22:28
Example of use of package-in-development taxize
# A species list, which ecologies often have, but may not know the family names, or if they do,
# they (meaning me) may spell the names wrong from time to time
> splist <- c("annona_cherimola", 'annona_muricata', "quercus_robur",
"shorea_robusta", "pandanus_patina", "oryza_sativa", "durio_zibethinus",
"rubus_ulmifolius", "asclepias_curassavica", "pistacia_lentiscus")
# Get the Taxonomic Serial Number for each species, which are unique (note that there could be many TSN's within a species
# for each subspecies for example. So you may want to query for you species using get_itis_xml in the demos on the github
# site and then make sure you get the TSN for the right subspecies or species
> tsns <- laply(splist, get_tsn, searchtype = "sciname", by_ = "name",
@sckott
sckott / mvmeta_example.R
Created August 2, 2011 23:46
Example for the mvmeta package
> berkey98
trial pubyear npat PD AL var_PD cov_PD_AL var_AL
1 Pihlstrom1983 1983 14 0.47 -0.32 0.0075 0.0030 0.0077
2 Lindhe1982 1982 15 0.20 -0.60 0.0057 0.0009 0.0008
3 Knowles1979 1979 78 0.40 -0.12 0.0021 0.0007 0.0014
4 Ramfjord1987 1987 89 0.26 -0.31 0.0029 0.0009 0.0015
5 Becker1988 1988 16 0.56 -0.39 0.0148 0.0072 0.0304
> model <- mvmeta(cbind(PD,AL),S=berkey98[6:8],data=berkey98,lab=list(mlab=trial))
@sckott
sckott / Rintrotutorial.R
Created September 10, 2011 13:39
A brief introduction to R.
# Intro Tutorial to R
# Scott Chamberlain <myrmecocystus@gmail.com>
# w/ code edited from Nathan Kraft and Dan Bunker
########## HELP ##########
# Getting Help with R on listserves online, etc.
# Go here for correct way to make reproducible examples to submit to help lists:
# https://github.com/hadley/devtools/wiki/Reproducibility
# Code writing style:
@sckott
sckott / ggcorplot.R
Created September 26, 2011 19:19
Pairwise correlations plots
ezLev=function(x,new_order){
for(i in rev(new_order)){
x=relevel(x,ref=i)
}
return(x)
}
ggcorplot = function(data,var_text_size,cor_text_limits){
# normalize data
for(i in 1:length(data)){
@sckott
sckott / visualizations_tutorial.R
Created September 30, 2011 15:47
Tutorial on basic visualizations in R
#######################################################
#### Created by Rolf Lohaus, EEB Dept., Rice University
####
#### Part of the code modified and extended from
#### Robert I. Kabacoff's Quick-R website
#### (http://www.statmethods.net)
#######################################################
############### HIGH-LEVEL PLOTTING FUNCTIONS ###############
@sckott
sckott / PGLMM.data.R
Created October 11, 2011 14:22
Function prepares data so that PGLMM can be fit
######################################
## Function that organizes the data so that PGLMM can be fit
## Created by Matthew Helmus
######################################
PGLMM.data<-function(modelflag=1,sim.dat=NULL,samp=NULL,tree=NULL,traits=NULL,env=NULL,Vcomp=NULL)
{
if (!require(ape))
{
stop("The 'ape' package is required")
@sckott
sckott / PGLMM.fit.R
Created October 13, 2011 13:58
Calls a PGLMM for logistic regression
######################################
## Function calls a PGLMM for logistic regression
## Created by Matthew Helmus
######################################
PGLMM.fit<-function(dat=NULL,Y=NULL,X=NULL,VV=NULL,sp.init=0.5,maxit=25,exitcountermax=50) # [B,B0,s,S95int,LL,flag]=PGLMM_nosparse_funct(Y,X,VV,s)
{
if (!require(corpcor))
{
stop("The 'corpcor' package is required")
@sckott
sckott / PGLMM.reml.R
Created October 13, 2011 14:00
PGLMM reml
######################################
## Created by Matthew Helmus
######################################
PGLMM.reml<-function(sp)
{
#global tH tinvW tVV tX
sp<-abs(Re(sp))
@sckott
sckott / PGLMM.sim.R
Created October 13, 2011 14:01
Simulates models used to test the PGLMM models
# library(plotrix)
# library(ape)
# PGLMM_model_simulations.m
# Simulates models used to test the PGLMM models
# 23 June 2010 MATLAB CODE
# 6 September 2011 R CODE TRANSLATION - HELMUS
@sckott
sckott / PGLMM_example.R
Created October 13, 2011 15:04
Example use case of PGLMMs for phylogenetic community structure
# Example Code
# Load functions
source("/path/where/you/have/this/file/PGLMM.data.R")
source("/path/where/you/have/this/file/PGLMM.fit.R")
source("/path/where/you/have/this/file/PGLMM.reml.R")
source("/path/where/you/have/this/file/PGLMM.sim.R")
# Simulate a dataset for the example
modelflag <- 1