R Tutorial (Glor & O'Meara)

InfoInfo
Search:    

Installing R Packages
Like Mesquite, R consists of a set of packages with different authors and analytical goals. In most cases you will install these packages interactively; when installing packages interactively you will type a command into the R interface (install.packages), R will search the internet to find the appropriate package in its archive, and R will install this package in your local framework. Due to the slow connection here at Bodega, we're going to avoid interactive installation in favor of local installation. Here are the instructions for conducting a local installation of the packages required for the phylogenetic and comparative methods we'll use in the workshop:

1. Install R from the CD.
2. Obtain a copy of the 'R_Packages' folder from one of the thumb drives that is circulating.
3. Open R by double clicking on the program icon.
4. Directions here diverge between Mac and PC

Mac
1. Go to the 'Packages & Data' menu and select 'Package Installer'.
2. Select 'Local Binary Package' from the pull down menu that initially reads 'CRAN (binaries)'
3. Click the 'Install' button in the bottom right corner of the 'R Package Installer Window'
4. Navigate to Mac_Binaries folder within the R_Packages folder and select one the one of the packages in this folder (for Mac users these will end in '.tgz'; for PC users they will end in '.zip') and click 'Open.' You may not see anything happen, but your package should now be installed.
5. Repeat steps 5 & 6 for each of the following eight packages: gee, geiger, lattice, msm, mvtnorm, nlme, ouch, VR.

PC
1. Go to the 'Packages' window and select 'Install package(s) from local zip files...'
2. Navigate to the PC_Binaries folder in the R_Packages folder and select all of the '.zip' files in this folder (using shift or control to select more than one file) and then click 'Open.'

Introduction to R
Doing phylogenetic comparative studies can be a real pain the ass. One of the biggest problems is that these analyses require users to become familiar with a varied and diffuse collection of software. Making matters worse, most of this software is relatively user unfriendly and characterized by a variety of alternative user interfaces and an idiosyncratic suite of input formats.

Over the years, several groups have attempted to bring all of the various phylogenetic comparative analyses into a shared programming environment. Mesquite is an example of these efforts. Another is based on the statistical package R. Although R lacks the graphical, menu-driven interface of Mesquite it is more nimble in the sense that it provides users with greater flexibility to develop new applications.

Much like Mesquite, R is not a single program in the traditional sense; it’s better thought of as a framework under which a variety of distinct programs are brought together in a shared working environment. There are tremendous advantages to this type of software. For one, it’s relatively easy to write new add-on packages that take advantage of the pre-existing framework. No need to write entirely new code to perform simple functions like tree building or tree plotting when you can use the code generated by others. This means that even novice programmers have the potential to develop and implement new applications in an incredibly powerful environment.

The goal of the following exercises is to get you familiar with the R environment and its potential applications to comparative studies. Perhaps the greatest draw-back to R is that there can be a relatively steep learning curve for new users. One hurdle is that the R interface is in a command line format, not the type of visually pleasing, pull-down menu driven format that most users prefer. If this is what’s stopping you from learning R the best advice I can give is: “get over it.” If you want to be on the leading edge of science you need to learn to use command line software. A second problem is that R has a somewhat unusual syntax which will take a bit of getting used to (especially for people who aren’t practiced in computer programming). My advice here is that you stick with it. Whatever earlier troubles you may encounter, I can promise some incredible pay-offs in the end; I believe that R is the most powerful tool available for practicing comparative biologists.

The PDF file below contains a number of basic exercises to get you started in R
R_for_Phylogenetics_v2.pdf (R tutorial with Glor)
anolis_mtDNA_mrb.con (Tree for use in R tutorial)
anolis_data.csv (Data for use in R tutorial)

Other things to download:
[WWW]randomPoints.R
[WWW]randomPointsAnswers.R

Other Resourcess
The [WWW]NESCent R Wiki for phylogenetic comparative methods

This is a Wiki Spot wiki. Wiki Spot is a 501(c)3 non-profit organization that helps communities collaborate via wikis.