Skip to content

Instantly share code, notes, and snippets.

View AndrewLJackson's full-sized avatar

Andrew Jackson AndrewLJackson

View GitHub Profile
@AndrewLJackson
AndrewLJackson / ggplot2-isotopes.Rmd
Created February 13, 2019 12:50
how to ggplot bivariate isotope plots
---
title: "SIA biplots using ggplot2"
author: "Andrew L Jackson & Chris Harrod"
date: "`r Sys.Date()`"
output: html_notebook
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.width = 9, fig.height = 6)
```
@AndrewLJackson
AndrewLJackson / test_bhatt.coeff
Created August 14, 2017 14:50
Testing disparity::bhatt.coeff
# examples of iteration estimates
# iteration 1, model 1
it1.m1<-c(0.007439839, 0.229489378, 0.035664652, 0.015154735, 0.712251396)
# iteration 2, model 1
it2.m1<-c(0.04197685, 0.22032073, 0.05718590, 0.03484489, 0.64567163)
# iteration 1, model 2
it1.m2<-c(0.09325976, 0.29549676, 0.15327778, 0.08599277, 0.37197294)
# iteration 2, model 2
it2.m2<- c(0.06429175, 0.02222554, 0.15422684, 0.65528134, 0.10397452)
@AndrewLJackson
AndrewLJackson / jdiFromScholar.R
Last active January 17, 2018 21:46
Code to calculate JDI from google scholar profile
# About: Code to calculate JDI and produce barplot as per
# https://scientistseessquirrel.wordpress.com/2017/08/03/my-journal-life-list/
# Additional code from
# https://www.r-bloggers.com/yet-another-post-on-google-scholar-data-analysis/
# Author: Andrew Jackson
# http://www.tcd.ie/Zoology/research/research/theoretical/andrewjackson.php
# Date: 04-Aug-2017
@AndrewLJackson
AndrewLJackson / point-cloud-to-polygon
Created July 18, 2017 09:56
use chull to order points correctly for creating polygons.
theta <- seq(0, 2*pi, length = 360)
Z <- data.frame(x = cos(theta), y = sin(theta))
par(mfrow = c(2,2))
# points in order
plot(y~x, data = Z, type = "l", main = "Made in order", asp = 1)
@AndrewLJackson
AndrewLJackson / dplyr_split.R
Created July 17, 2017 10:06
Demonstration of how to split a data frame into a list when the grouping variable is a character string
library(dplyr)
# use the iris dataset
dd <- iris
# The normal way to group or split is by directly referencing the var object
dd %>% group_by(Species)
dd %>% split(.$Species)
@AndrewLJackson
AndrewLJackson / slice_reorders.R
Last active July 12, 2017 17:08
odd reordering by dplyr::slice
library(tidyverse)
# create a list of length 10 with a small dataframe in each entry
df <- lapply(1:10,function(x){data.frame(y = 1:5)})
# convert to tbl
df_tbl<- bind_rows(df, .id = "id")
# pluck out the last entry for each "id" using slice()
last_entry <- df_tbl %>% group_by(id) %>% slice(n())
# code based on https://en.wikipedia.org/wiki/Mahalanobis_distance
set.seed(1)
# define a point D
x <- matrix(rmnorm(1, c(2,2), matrix(c(1,0.1,0.1,1), 2, 2)), 1, 2) # vector of locations in 2 dimensional space
x <- t(x) # transpose
# Define a multivariate normal distribution for comparison
mu <- matrix(c(0, 0), 1, 2) # vector of bivariate means
@AndrewLJackson
AndrewLJackson / posthoc_anova
Created July 22, 2015 19:35
Example for running various post hoc analyses on ANOVA models in matlab
strength = [82 86 79 83 84 85 86 87 74 82 ...
78 75 76 77 79 79 77 78 82 79];
alloy = {'st','st','st','st','st','st','st','st',...
'al1','al1','al1','al1','al1','al1',...
'al2','al2','al2','al2','al2','al2'};
% NB also works on two-way anovas using anova2()
[p, tbl, stats] = anova1(strength,alloy,'off')
% this line will compute pairwise comparisons, at the usual
@AndrewLJackson
AndrewLJackson / test_rmultireg.r
Last active August 29, 2015 14:23
direct call of function rmultireg for testing Linux installation
require(plyr)
#require(siar)
t1 <- data.frame(SizeClass=c("Meiofauna","Smaller Macrofauna","Bigger Macrofauna"),
num=rpois(3,10),
md13C=rnorm(3,-10,10),
sd13C=rlnorm(3,1,1),
md15N=rnorm(3,5,5) ,
sd15N=rlnorm(3,1,1))
t1
@AndrewLJackson
AndrewLJackson / test_siber.hull.metrics_AJ.r
Created June 16, 2015 13:42
reported bug by Leonardo Saravia ‏@larysar
require(plyr)
require(siar)
t1 <- data.frame(SizeClass=c("Meiofauna","Smaller Macrofauna","Bigger Macrofauna"),
num=rpois(3,10),
md13C=rnorm(3,-10,10),
sd13C=rlnorm(3,1,1),
md15N=rnorm(3,5,5) ,
sd15N=rlnorm(3,1,1))
t1