Scholarly metadata from R

Metadata! Metadata is very cool. It’s super hot right now - everybody is talking about it. Okay, maybe not everyone, but it’s an important part of archiving scholarly work. We are working on a repo on GitHub rmetadata to be a one stop shop for querying metadata from around the web. Various repos on GitHub we have started - rpmc, rdatacite, rdryad, rpensoft, rhindawi - will at least in part be folded into rmetadata. As a start we are writing functions to hit any metadata services that use the OAI-PMH: “Open Archives Initiative Protocol for Metadata Harvesting” framework. OAI-PMH has six methods (or verbs as they are called) for data harvesting that are the same across different metadata providers: ...

September 17, 2012 · 6 min · Scott Chamberlain

Getting data on your government

I created an R package a while back to interact with some APIs that serve up data on what our elected represenatives are up to, including the New York Times Congress API, and the Sunlight Labs API. What kinds of things can you do with govdat? Here are a few examples. How do the two major parties differ in the use of certain words (searches the congressional record using the Sunlight Labs Capitol Words API)? ...

September 1, 2012 · 3 min · Scott Chamberlain

Getting ecology and evolution journal titles from R

So I want to mine some #altmetrics data for some research I’m thinking about doing. The steps would be: Get journal titles for ecology and evolution journals. Get DOI’s for all papers in all the above journal titles. Get altmetrics data on each DOI. Do some fancy analyses. Make som pretty figs. Write up results. It’s early days, so jus working on the first step. However, getting a list of journals in ecology and evolution is frustratingly hard. This turns out to not be that easy if you are (1) trying to avoid Thomson Reuters, and (2) want a machine interface way to do it (read: API). ...

August 31, 2012 · 3 min · Scott Chamberlain

Making matrices with zeros and ones

So I was trying to figure out a fast way to make matrices with randomly allocated 0 or 1 in each cell of the matrix. I reached out on Twitter, and got many responses (thanks tweeps!). Here is the solution I came up with. See if you can tell why it would be slow. {% highlight r linenos %} mm <- matrix(0, 10, 5) apply(mm, c(1, 2), function(x) sample(c(0, 1), 1)) {% endhighlight %} ...

August 30, 2012 · 4 min · Scott Chamberlain

ggplot2 maps with insets

UPDATE: changed data source so that the entire example can be run by anyone on their own machine. Also, per Joachim’s suggestion, I put a box around the blown up area of the map. In addition, rgeos and maptools removed, not needed. Here’s a quick demo of creating a map with an inset within it using ggplot. The inset is achieved using the gridExtra package. Install libraries install.packages(c("ggplot2", "maps", "grid", "gridExtra")) library("ggplot2") library("maps") library("grid") library("gridExtra") Create a data frame dat <- data.frame(ecosystem = rep(c("oak", "steppe", "prairie"), each = 8), lat = rnorm(24, mean = 51, sd = 1), lon = rnorm(24, mean = -113, sd = 5)) head(dat) #> ecosystem lat lon #> 1 oak 49.58285 -107.6930 #> 2 oak 52.58942 -116.6920 #> 3 oak 50.49277 -114.5542 #> 4 oak 50.05943 -116.5660 #> 5 oak 51.76492 -112.1457 #> 6 oak 52.82153 -112.8858 Get maps using the maps library Get a map of Canada ...

August 22, 2012 · 3 min · Scott Chamberlain

Recent R packages for ecology and evolution

Many R packages/tools have come out recently for doing ecology and evolution. All of the below were described in Methods in Ecology and Evolution, except for spider, which came out in Molecular Ecology Resources. Here are some highlights. mvabund paper - get R pkg Model-based analysis of multivariate abundance data. Visualising data, fitting predictive models, checking assumptions, hypothesis testing. popdemo paper - get R pkg Population demography using projection matrix analysis. motmot paper - get R pkg Models of trait macroevolution on trees spider paper - get R pkg Analysis of species identity and evolution, with particular reference to DNA barcoding BaSTA paper - get R pkg Bayesian estimation of age-specific survival from incomplete mark–recapture/recovery data with covariates abc paper - get R pkg Approximate Bayesian Computation (ABC) RNetLogo paper - get R pkg Running and exploring individual-based models implemented in NetLogo phytools paper - get R pkg Tools for phylogenetic comparative biology smatr paper - get R pkg Estimation and inference about allometric lines RBrownie paper - get R pkg ? Testing hypotheses about rates of evolutionary change polytomy resolver paper - get R pkg Resolve polytomies on dated phylogenies with their R scripts [here][]. And a cool tool came out for the Python programming language. ...

June 14, 2012 · 2 min · Scott Chamberlain

mvabund - new R pkg for multivariate abundance data

There is a new R package in town, mvabund, which does, as they say “statistical methods for analysing multivariate abundance data”. The authors introduced the paper in an online early paper in Methods in Ecology and Evolution here, R package here. The package is meant to visualize data, fit predictive models, check model assumptions, and test hypotheses about community-environment associations. Here is a quick example (originally from https://gist.github.com/2112141) #### mvabund play # install mvabund from CRAN pkg repository install.packages("mvabund") require(mvabund) # plot abundance by copepod species data(Tasmania) attach(Tasmania) tasmvabund <- mvabund(Tasmania$copepods) plot(tasmvabund ~ treatment, col = as.numeric(block)) # fit negative binomial model for each species and plot residuals vs. fitted tas.nb <- manyglm(copepods ~ block*treatment, family="negative.binomial") plot(tas.nb) ...

March 19, 2012 · 1 min · Scott Chamberlain

Take the INNGE survey on math and ecology

Many ecologists are R users, but we vary in our understanding of the math and statistical theory behind models we use. There is no clear consensus on what should be the basic mathematical training of ecologists. To learn what the community thinks, we invite you to fill out a short and anonymous questionnaire on this topic here. The questionnaire was designed by Frédéric Barraquand, a graduate student at Université Pierre et Marie Curie, in collaboration with the International Network of Next-Generation Ecologists (INNGE). ...

February 17, 2012 · 1 min · Scott Chamberlain

Scraping Flora of North America

So Flora of North America is an awesome collection of taxonomic information for plants across the continent. However, the information within is not easily machine readable. So, a little web scraping is called for. rfna is an R package to collect information from the Flora of North America. So far, you can: Get taxonomic names from web pages that index the names. Then get daughter URLs for those taxa, which then have their own 2nd order daughter URLs you can scrape, or scrape the 1st order daughter page. Query Asteraceae taxa for whether they have paleate or epaleate receptacles. This function is something I needed, but more functions will be made like this to get specific traits. Further functions will do search, etc. ...

January 27, 2012 · 2 min · Scott Chamberlain

RNetLogo - A package for running NetLogo from R

Described in a new Methods in Ecology and Evolution paper here, a new R package RNetLogo allows you to use NetLogo from R. NetLogo is software is a “multi-agent programmable modeling environment”. NetLogo can be used in individual- and agent-based modeling, and is used in the book Agent-based and Individual-based Modeling: A Practical Introduction by Railsback & Grimm. I have not tried the package yet, but looks interesting. I am always a fan of running stand-alone programs from R if possible. ...

January 23, 2012 · 1 min · Scott Chamberlain