# Difference between revisions of "R Hackathon 1/ContinuousData"

Line 7: | Line 7: | ||

== Fitting and Comparing Brownian Motion to Other Models == | == Fitting and Comparing Brownian Motion to Other Models == | ||

+ | |||

+ | Start by reading in the Geospiza data and extracting the the wingL varable: | ||

+ | |||

+ | data(geospiza) | ||

+ | wL<- geospiza$geospiza.data[,1] | ||

+ | names(wL)<- row.names(geospiza$geospiza.data) | ||

+ | |||

+ | Get the Geospiza tree and drop the olivacea species: | ||

+ | |||

+ | tr<- geospiza$geospiza.tree | ||

+ | tr2<- drop.tip(tr, "olivacea") | ||

+ | |||

+ | Now, we are ready, | ||

+ | |||

Suggested examples: | Suggested examples: |

## Revision as of 16:38, 13 December 2007

## Inferring Models for Continuous Characters in R

Introductory material on continuous models: Brownian motion (BM), Pagel transformations, Ornstein-Uhlenbeck models.

## Fitting and Comparing Brownian Motion to Other Models

Start by reading in the Geospiza data and extracting the the wingL varable:

data(geospiza) wL<- geospiza$geospiza.data[,1] names(wL)<- row.names(geospiza$geospiza.data)

Get the Geospiza tree and drop the olivacea species:

tr<- geospiza$geospiza.tree tr2<- drop.tip(tr, "olivacea")

Now, we are ready,

Suggested examples:
(1) fitting simple BM
(2) fitting a Pagel transformation
(3) fitting an OU-1 model
(4) Show model comparisons among 1-3 using AIC

## A Note about Multiple Implementations of these Methods

Currently, there are multiple implementations of several of these models across different packages. The results are not always the same across methods, however, because either the purpose of the analysis is slightly different across packages, or the implementations use different computational strategies. The models that currently have multiple implementations as of this writing (13 December 2007) are (i) Brownian motion and (ii) Ornstein-Uhlenbeck with one optimum.

**Brownian motion**

Currently, there are three packages that implement inference of the BM model: ape in function ace(), geiger in function fitContinuous(), and ouch in function brown.fit(). The function ace() will return a log-likelihood and a parameter estimate for the BM model, but these are conditional upon the reconstructed trait values of the nodes. This is consistent with the main purpose of ace(), but these results are not comparable with other model fits (which are not usually conditioned in this way). Thus, unless your main focus is on ancestral reconstructions, you should probably be using the functions in either geiger or ouch to fit the BM model.

The functions in geiger and ouch share the approach of not conditioning the model fits on particular values at ancestral nodes. Although their computational strategies differ somewhat, they seem to produce log-likelihoods and rate estimates that are very nearly the same (note that rate parameter in ouch, "sigma", is the square root of the rate parameter in geiger, "beta").

**Ornstein-Uhlenbeck**

Both geiger and ouch can fit OU models with a single optimum (only ouch can currently fit OU models with more than one optimum). Again, the approaches differ in algorithmic approach. The log-likelihoods produced seem to be very similar, but the parameter estimates may not be. Differences in the parameter estimates reflect that this can be a very difficult model to fit, as there is often a very large ridge over which the log-likelihood changes very little. The differences can be small enough so that optimization routines can differ as to where they stop along this ridge.