Skip to content

Instantly share code, notes, and snippets.

View nmatzke's full-sized avatar

Nicholas J. Matzke nmatzke

View GitHub Profile
# Source ALL of the R files in a particular R/ directory
# (so we don't have to have a fully-functioning package)
# Author: Nick Matzke, nmatzke
# License: GPL-3
sourceall_git <- function(repo)
{
library(httr) # for GET
library(devtools) # for source_url
# =============================================
# genericR_v1.R: many useful utility functions
# for R
#
# by Nick Matzke
# Copyright 2011-infinity
# matzkeATberkeley.edu
# January 2011
#
# Please link/cite if you use this, email me if you have
@nmatzke
nmatzke / num_unobservable_patterns_v2.R
Last active February 2, 2016 14:03
Calculating the number of unobservable site patterns for the Mk-parsimony-informative ascertainment bias correction
#######################################################
# Calculating the number of unobservable site patterns
# for the Mk-parsimony-informative ascertainment bias
# correction
#
# by Nick Matzke, 2015-2016
#
# Free to re-use; we are preparing an ms on this issue,
# please email nick.matzke@anu.edu.au if interested.
#
# Install optimx
install.packages("optimx", dependencies=TRUE, repos="http://cran.rstudio.com")
# Install BioGeoBEARS from CRAN 0-cloud:
#install.packages("BioGeoBEARS", dependencies=TRUE, repos="http://cran.rstudio.com")
# If default install for BioGeoBEARS doesn't work, install dependencies in this order,
# then install BioGeoBEARS from source:
install.packages("Rcpp", dependencies=TRUE)
install.packages("RcppArmadillo", dependencies=TRUE)
@nmatzke
nmatzke / birthdeath_example
Created July 23, 2016 06:38
Converting between birth rate, death rate (speciation and extinction) and r (diversification rate) and epsilon (relative death rate)
# Example converting between
# birth rate, death rate (speciation and extinction)
# and
# r (diversification rate) and epsilon (relative death rate)
library(ape)
library(BioGeoBEARS)
# Load the Psychotria tree
trfn = np(paste(addslash(extdata_dir), "Psychotria_5.2.newick", sep=""))
@nmatzke
nmatzke / data_frame_utilities_v1.R
Created December 22, 2016 04:45
Utilities to manage annoying features of R data frames (list, factor issues)
#######################################################
# These functions are some utilitys for dealing with
# annoying features of R's use of data.frames, e.g.
# the tendency for some functions to have something that
# looks like a data.frame, but is actually a series of lists.
#
# Also, dfnums_to_numeric semi-intelligently converts
# columns with numeric data to numeric (rather than
# factor or character).
#######################################################
@nmatzke
nmatzke / Beast2_GeneralSubstitutionModel_v1.R
Created December 22, 2016 04:58
Figuring out the Beast2 GeneralSubstitutionModel
#######################################################
# Figuring out the Beast2 GeneralSubstitutionModel
#######################################################
# The Beast2 documentation says:
#
# file:///Applications/BEAST_2.4.3/Beast2_XML_as_HTML_help/beast.evolution.substitutionmodel.GeneralSubstitutionModel.html
# Simple setup of a human/chimp/etc. phylogeny
# by Nick Matzke
#######################################################
# Phylogeny versus cladogram
#######################################################
# Tree specification
newick_string = "((((human:6,chimp:6):1,gorilla:7):6,orang:13):5,gibbon:18);"
tr = read.tree(file="",text=string)
install.packages("devtools")
library(devtools)
install_github("nmatzke/rexpokit")
install.packages("phytools")
library(phytools)
install.packages("geomorph")
install.packages("BioGeoBEARS")
install.packages("plot3D")
@nmatzke
nmatzke / _ex_Eulers_WORKS.jl
Created April 18, 2019 02:31
Revising Chris Rackauckas's "exp_euler_test.jl" from Julia 0.6 so it works in Julia 1.1
########################################################
# Revising Chris Rackauckas's "exp_euler_test.jl" from
# Julia 0.6 so it works in Julia 1.1
########################################################
#
# Original 0.6 code from:
#
# ChrisRackauckas/exp_euler_test.jl
# https://gist.github.com/ChrisRackauckas/cf91f4575b0587a45c72620384612b82