Skip to content

Instantly share code, notes, and snippets.

View rmaia's full-sized avatar

Rafael Maia rmaia

View GitHub Profile
# Plotting eigenvectors from PCA onto scatterplots
sigmat <- matrix(c(1,-.9,-.9,1), nrow=2)
cent <- c(8,3)
dat <- MASS::mvrnorm(n=100, mu=cent, Sigma=sigmat)
eig <- eigen(cov(dat))
plot(dat, xlim=cent[1]+c(-3,3)*sigmat[1,1],
require(XML)
scrapeBirdlife <- function(searchterm){
webaddress <- paste("http://www.birdlife.org/datazone/sowbsearchresults.php?a=ns&SearchTerms", searchterm, sep='=')
aa <- readLines(webaddress)
# scrap only web address, common name, species name, IUCN status
aa <- aa[grep('species/factsheet', aa)]
aa <- gsub('<li><a href=\"','',aa)
ubercoldist <- function(Qi, ni=c(1,2,2,4), w=0.2){
Qi <- Qi[, 1:length(ni)]
Qi <- log(Qi)
e <- setNames(w/sqrt(ni), names(Qi))
# prepare output
pairsid <- t(combn(nrow(Qi),2))