Environmental Niche Factor Analysis in R

25 August 2011. This page is out of date. I've learned more about R since I originally posted this, and presumably ENFA has progressed considerably since I put this up here. Leaving for now but will likely take down soon.


I know very little about what an ENFA does still, and I have a lot to learn about what my results actually mean. That being said, Bette has shown me how to make it work on both a Mac and a PC, and I provide here both the code itself and example files that you can use to play with this analysis. For those who actually want to know what they're doing, below are two papers and one helpfile you can check out, plus I recommend going to this website: Ecological Niche Factor Analysis.

Help file for adehabitat package
Calenge - 2006 - The package adehabitat for the R software
Calenge - 2007 - Exploring habitat selection with adehabitat

The output of an ENFA will give you a bunch of values with respect to the significance and direction of preference for a given habitat variable as compared with background habitat. More on that later when I know more about what I'm talking about. The code included here describes how to get those values. The ENFA can also provide two neat histograms. The first shows the distribution of your points, in gray, with respect to the background. This incorporates two metrics: the marginality, or the squared distance of the niche from the mean available habitat, and the specialization, or how narrow the niche is relative to the habitat conditions available.



The second figure the ENFA can provide specifies exactly how these marginality scores break down across all your habitat variables.



To begin,
1) Install R on your computer (if you have no experience with R this should still be possible, but it may be a little overwhelming).

2) Load R and download and install the packages "adehabitat" and "ade4."

3) Set your working directory to wherever you will be placing your files. This option is included in the pull down menus of both Macs (Misc<"Change Working Directory") and PCs (File<"Change dir").

4) What you need now are all your habitat files in ASCII format. They need to have the same extent. Take care of this in GIS beforehand. You also need X,Y points for the species you are analyzing. Save these in a comma-delimited (.csv) file. There should be headers in these columns, e.g. "X" and "y".

5) If you are using your own data, get it ready per point 4 above. If you want to use example data, download the following zip file and unzip to the same folder you have set as your working directory.

6) Regardless of what you chose to do for point 5, download, read through, modify accordingly, and execute the ENFA script