Using parallel processing in R

multicore
Lately I’ve been running a lot of complex models with huge datasets, which is grinding my computer to a halt for hours. Streamlining code can only go so far, but R is limited because the default session runs on only 1 core. In a time when computers have at least 2 cores, if not more, why not take advantage of that extra computing power? (Heck, even my phone has 2 cores.*)

Luckily, R comes bundled with the “parallel” package, which helps to distribute the workload across multiple cores. It’s a cinch to set up on a local machine:

Continue reading

R^2 for linear mixed effects models

Linear mixed effects models are a powerful technique for the analysis of ecological data, especially in the presence of nested or hierarchical variables. But unlike their purely fixed-effects cousins, they lack an obvious criterion to assess model fit.

[Updated October 13, 2015: Development of the R function has moved to my piecewiseSEM package, which can be found here under the function sem.model.fits]

Continue reading

Black theme for ggplot2

[EDIT 06/05/16: See updated version of this code here for ggplot2 version 2.X.X: https://gist.github.com/jslefche/eff85ef06b4705e6efbc]

I’ve long extolled the virtues of using ggplot2 as a graphing tool for R for its versatility and huge feature set. One of my favorite aspects of ggplot2 is the ability to tweak every aspect of the plot using intuitive commands. With the recent release of version 0.9.2 though, creator Hadley Wickham overhauled the theme options, which broke my preferred black theme, theme_black(), found here. I’ve updated theme_black() to work with the current version of ggplot 0.9.3.1. Enjoy!

ggplot2black Continue reading

Mapping in R, Part II

The other day, I posted an introductory demo to mapping in R using some of the built-in maps. But of course there are only a few regions represented in the “maps” package: the US states, the US as a whole, Italy, France, and the world. Even then, there are some limitations to these: for instance, the USSR is still alive and kicking in the world of “maps.” If you are living in the 21st century–or working somewhere other than these locations–you may want to supply your own, more updated maps. The most popular filetype is, of course, the GIS shapefile. But to access, visualize, manipulate, and plot on shapefiles, it was formerly necessary to use ArcGIS, which is proprietary and thus costly. I’ll show you how to do it all in R!

Continue reading

Mapping in R, Part I

I’m consistently amazed at the capabilities of R: if it can be done, it can be done in R. And so is the case with mapping. Recently, I had the need to do some complicated geospatial analysis, and I wanted to do it in R for the obvious reasons: it’s free, it’s open-source, and there is a great support community. As it turns out, R has much of the functionality of ArcGIS, albeit with a lot less flash and a lot more hair-pulling. But once you’ve done the legwork to get the data in and formatted, and the functions set, it’s a snap to run through all sorts of data.

Continue reading

Why students should start reading blogs (and commenting!)

Yesterday, Jeremy Fox posted a rather lengthy blog on why academics should read blogs. I’m going to convince the neophyte academic, the graduate student, why you especially should be reading blogs, and commenting too.

I will skip topics like “What is a blog?” and “What do blogs cover?” because Jeremy and his team at Dynamic Ecology have done an excellent job compiling the answers to these questions.

So, why should students read blogs? I’ll keep it simple: connection.

Continue reading

An ode to the hagfish

As a marine ecologist, I would be remiss if I let my blog go so long without a shoutout to my favorite of marine critters, the noble and misunderstood hagfish. Slimy, ancestral, largely unknown: what’s not to love?

As an undergrad, I put together some materials on the biology and physiology of the Atlantic hagfish for a fisheries class at the Mount Desert Island Biological Labs. I’ve held onto the document in the (misguided?) sense that it may be useful to someone one day, but was never sure of the appropriate venue to disseminate it. Hello, blog. Below, find the 36-page document in all its pictorial glory, including close up images of its five–count ’em, FIVE–hearts.

Anatomical Review and Standard Operating Procedure for the Atlantic Hagfish (Myxine glutinosa)

Happy dissecting!

(Image credit: Wikimedia commons)

BioDiverse Perspectives

I’m happy to announce the launch of the new blog, BioDiverse Perspectives! The blog is a cooperative effort by graduate students all over the world blogging on the topic of biodiversity science, using casual, approachable language to initiate discussion amongst the next generation of biodiversity researchers. The project is funded through the NSF’s Dimensions of Biodiversity Distributed Graduate Seminar (which I previously blogged about here). Each article revisits a foundational paper in biodiversity research, or highlights emerging new concepts in the field. The purpose is to stimulate discussion amongst graduate students in the digital age. So stop by, read an article (or contribute one), and leave a comment! A big thanks to co-PI Julia Parrish, Hillary Burgess, and the University of Washington for making the blog possible.

Continue reading