Gridding data for multi-scale macroecological analyses

These are materials for the first practical lesson of the Spatial Scale in Ecology course. All of the data and codes are available here. The class covered a 1.5h session. R code for the session is also at the end of this post. The following advices and ideas are mostly my personal opinions, they were not published, feel free to spread them, or to comment on them at the end of the post:

1. Do we need to fit everything to grids?

In other words, can't we just use points and shapefiles, and "extract" whatever they overlap? Is scale real, or is it only in the eye of the beholder? What are the alternatives to grids? We haven't really started a deeper discussion here, it was perhaps too abstract. I was trying to push forward the idea that grids should be used always. There is something rotten in the way that current SDM techniques simply extract environmental variables around point records. I consider it to be an open and important (and broad) problem.

2. What is the best shape of grid cells for multi-scale analyses?

Almost everybody works with grids that have rectangular grid cells. It is practical because you can aggregate them into grids of coarser resolution, and you can think about them as simple rectangular matrices and effectively analyze them (e.g. as raster data). Rectangular grids are also useful at sub-continental extents, as geometry of their grid cells is less sensitive to the particular projection at these extents. Triangular and hexagonal grids have one potential advantage over rectangular ones: you can wrap them around a sphere like that (image source: Wikipedia):

Such grids are sort of "projection-free" - they are equidistant and they have constant area of grid cells at the same time, which could be huge advantage in macroecology. The disadvantage is that triangles and hexagons do not fit our rectangular mindsets and toolsets. Another disadvantage of hexagonal grids is that you cannot simply aggregate them to produce grid of coarser grain. On the other hand, triangular grids are scalable - I quite fancy the idea of triangular grids - maybe we should reconsider them as maybe they are easier to work with than we think. Maybe.

What about elongation of grid cells? Can we use any rectangular shapes for macroecological grids? Essentially yes, but it may be wise to keep the shape of a grid cell constant over the extent of a study. Consider the following illustration:
It is from Kunin 1997 who gave the issue the first treatment in ecological context. All of the rectangular shapes have identical area, yet the more elongated ones will generally harbor more habitat heterogeneity and more species, simply because of the First Law of Biogeography: distant places are more different from each other than places that lay close.

3. What needs to be the projection of a rectangular grid?

So elongated shapes harbor more species (habitats, heterogeneity, diversity of any kind) than regular shapes. Well, then you better keep shape of all grid cells constant. But also larger cells harbor more species (diversity of any kind) than small cells. So we need to also keep the area of each grid cell constant. With a spherical world and rectangular grid these are two contradicting requirements, and there is no good solution.
For macroecological purposes the usual compromise is Cylindrical Equal Area projection (or other equal area projection) of the grid, as the effect of area is usually considered more serious than the effect of shape (but this has not been rigorously tested yet - it may not be true). This is gridded world map in the Cylindrical Equal Area projection:
This is how the equal-area grid cells look in the common WGS 1984 projection:

Note the elongated shapes at high latitudes - these will surely over-represent diversity (because of their shape, not because of their area).

4. Should the grids be nested? Should they have the same extent?

I would argue that for simple data visualizations and simple pattern explorations at different grid resolutions, the grids do not have to be strictly nested. However, for more rigorous and multi-scale statistical modelling it can be wise to keep the origin and the extent of the grids constant. For example, in order to build a spatially structured hierarchical model it is really advantageous when the grids are nested.

Currently there are two common solutions, both of them sub-optimal. First approach is to ignore the problem and to pretend that 1/3 of a grid cell is a whole grid cell. This is what (amongst many) Rahbek & Graves 2001 did:

Another extreme is to follow the dictatorship of geometry strictly, and to delete all grid cells that have even a very small proportion of sea. In case of a system of nested grid this will be dependent on our coarsest grid. This the approach that I chose in one of my papers:

The cost is that one loses most of the coastal areas. There are also compromises - some workers have used some arbitrarily chosen thresholds on the acceptable proportion of sea area within a grid cell (e.g. up to 10%-20% is still acceptable).

There is a third way, which we will explore in the following lessons. It involves keeping all grid cells in the data, regardless to the area of sea within them. The next step is not to ignore this fact (as is often done), but to effectively incorporate it into a statistical model as an area of completely unsuitable habitat, with a proper prior knowledge of its effect.

6. What if my grid is irregular?

For simple data explorations it is a problem (see my paper), as the patterns are affected both by shape and area of a grid cell. However, this problem can be easily fixed in hierarchical modelling.

Usually, data in the form of "bioregions", biomes, altitudinal bands, administrative units, "evolutionary arenas", regional checklists or nature reserves are subject to this problem - they can be considered as grids that just happen to have very non-constant grid cell shape and area. Some may argue that they represent a sort of "natural grain or natural grid" - often, their boundaries are really important and determining what happens within the cells. There is, however, a pitfall: they confound the effect of shape, area and environment in such a complex way, that it is difficult to separate them. By working in a regular grid one has at least the geometry under control. This is desirable - unless one is interested purely in the role of geometry, then these "natural units" may be useful, but only if they are defined based on environmental conditions within them.

7. Is there a "good" or "optimal" grid resolution?

No. What really matters is not a particular grain resolution, but spatial scaling relationships that go across all imaginable grain resolutions. We should study them all - the species-area relationship, the occupancy-area relationship, the area-energy-diversity relationship, the relationship between area, habitat and occurrence of a species. They are the key. Everything is sort of "hanging" on these pillars. We should look for simple, rigorous and intuitive ways to construct these relationships, and build the rest of spatial ecology on them.

This is even more important for applied ecology. It does not matter that much what is (or will be in future) the pattern of species distribution at a single scale. It does not matter that much what predicts species occurrences at the finest grain resolutions. It is naive to say that, for applied and conservation purposes, it is fine grain that matters. All grains (potentially) matter. Appropriate scaling relationships are the baseline that links all of the grains together.

Simply put: Do not work at a single scale, do not seek the single best scale, keep in mind that fine-grain ecological properties may not be necessarily more important than coarse-grain properties (but note that fine resolution data can be more useful for further work than coarse-grain data).

8. What is the reliable grid resolution that captures species distributions based on point records and expert-drawn range maps?

Currently, and for continental to global extents, it is something roughly above 100 km x 100 km. See the Jetz & Hurlbert's paper and Hawkins et al.'s paper. This may be different for more systematically collected data. This is also an open problem, there is much more to be explored about spatial scaling of sampling effort, and it would be a nice project for a really nice paper. Somebody should do it. We should do it. Let's do it next Monday.

9. What is the best way to aggregate different types of data?

It all depends on the character of variable that you are aggregating. Recall what you learned in physics about extensive and intensive properties.Use this knowledge to your advantage:Intensive variables - impossible to aggregate by very definition, unless you convert them into something else. Altitude is such variable. You cannot aggregate it, but you can calculate its mean, minimum or maximum in a broader area. But then it is not the variable it used to be any more (you have just converted it into an extensive one). Temperature can be similarly tricky.Extensive variables - easy to aggregate. Area of a suitable habitat, total annual rainfall are examples of such variables.Strange variables- species richness, beta diversity, endemism and all that. They are somewhere between being extensive and intensive. They have their own rules. Beware! (And study species-area relationships).

10. What is the available software
- ArcGIS - see the fishnet function; probably useful to know Python scripting in arcpy
- R - this is what we will focus on.

11. Practical exercise - loading data into R, creating grids in R and aggregating data into grids of different resolutions in R?

The code may have its bugs. This is what we went through during the second half of the class: