## Not run:
# ##Example 1
# ###This example uses the four models used in Weir et al. 2012 to test for
# ###a latitudinal effect on Euclidean distances for bird song pitch on 87
# ###forest sister pairs.
# data(bird.pitch)
# attach(bird.pitch)
#
# #STEP 1 Correct Euclidean distances for sampling and measurement bias
# DIST_cor <- MScorrection(nA=bird.pitch$number_individuals_Species1,
# nB=bird.pitch$number_individuals_Species2,
# VarA=bird.pitch$Variance_PC1and2_Species1,
# VarB=bird.pitch$Variance_PC1and2_Species2,
# DIST_actual=bird.pitch$Uncorrected_Euclidean_Distance)
#
# #STEP 2 Extract and test only forest species
# DIST <- subset(DIST_cor, subset = (bird.pitch$Habitat == "forest"))
# TIME <- subset(bird.pitch$TIME,subset = (bird.pitch$Habitat == "forest"))
# GRAD <- subset(bird.pitch$GRAD,
# subset = (bird.pitch$Habitat == "forest"))
# models = c("BM_null", "BM_linear", "OU_null", "OU_linear")
# #The following generally takes 1 to 2 minutes to run
# FIT1 <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models)
#
# ###The best fit model for forest species is the OU_linear model in which
# ###rates of evolution increase with latitude (b1_slope is positive) and
# ###evolutionary constraint declines with increasing latitude (a1_slope is
# ###negative).High latitude species are evolving faster and in a less
# ###constrained fashion.
#
# ##Example 2
# ###This example tests to see if allopatric and sympatric species pairs
# ###have significantly different rates under the BM_null model
#
# #STEP 1 Correct Euclidean distances for sampling and measurement bias
# DIST_cor <- MScorrection(nA=bird.pitch$number_individuals_Species1,
# nB=bird.pitch$number_individuals_Species2,
# VarA=bird.pitch$Variance_PC1and2_Species1,
# VarB=bird.pitch$Variance_PC1and2_Species2,
# DIST_actual=bird.pitch$Uncorrected_Euclidean_Distance)
#
# #STEP 2 First, fit BM_linear to the entire dataset
# DIST <- DIST_cor
# TIME <- bird.pitch$TIME
# GRAD <- bird.pitch$GRAD
# models = c("BM_null")
# FIT2a <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models)
#
# #STEP 3 Next, fit BM_linear to the allopatric subset
# DIST <- subset(DIST_cor, subset = (bird.pitch$Patry == "allopatric"))
# TIME <- subset(bird.pitch$TIME,
# subset = (bird.pitch$Patry == "allopatric"))
# GRAD <- subset(bird.pitch$GRAD,
# subset = (bird.pitch$Patry == "allopatric"))
# models = c("BM_null")
# FIT2b <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models)
#
# #STEP 4 Finally, fit BM_linear to the sympatric subset
# DIST <- subset(DIST_cor, subset = (bird.pitch$Patry == "sympatric"))
# TIME <- subset(bird.pitch$TIME,
# subset = (bird.pitch$Patry == "sympatric"))
# GRAD <- subset(bird.pitch$GRAD,
# subset = (bird.pitch$Patry == "sympatric"))
# models = c("BM_null")
# FIT2c <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models)
#
# #STEP 5 Compare the AIC of the model fit to the entire dataset to the model
# #with separate rates for allopatric and sympatric subsets.
# ###To calculate AIC for the allopatric and sympatric model
# ###the loglikelihoods for the subsets are summed
# logLikelihood <- as.numeric(FIT2b[1,]) + as.numeric(FIT2c[1,])
# ###The subsets model has 2 parameters (1 for each subset)
# ###thus AIC = 2*2 - 2*logLike
# AIC_forest_nonforest <- 2*2 - 2*logLikelihood
#
# ###The AIC for the entire dataset is 319.86 and for the model with separate rates
# ###for allopatric and sympatric AIC is 320.13. The best fit model is the full dataset
# ###model without separate rates for different subsets, indicating a failure to reject
# ###the null hypothesis in favour of separate rates for allopatric and sympatric
# ###species pairs.
#
#
# ##Example 3
# ###using the same data as Example 1, this example demonstrates user control of
# ###starting parameters
# #STEP 1 generate matrices of starting values for those models which the user
# #wishes to use customized starting values
# p_matrix <- c(0.0001, 0.001, 0.01, 0.1, 1,2,3,4,5,10,100,1000)
# BM_null_starting <- matrix(p_matrix, length(p_matrix), 1, byrow=TRUE)
#
# p_matrix <- c(10, -1, 10, 1, 0, -0.1, 0, 0.1)
# BM_linear_starting <- matrix(p_matrix, length(p_matrix)/2, 2, byrow=TRUE)
#
# #first, use only 2 models, each with customize starting parameters
# models <- c("BM_null", "BM_linear")
# FIT3a <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models,
# starting = list(BM_null_starting, BM_linear_starting) )
#
# #next use 4 models, but customize starting parameters for only the first two
# models <- c("BM_null", "BM_linear", "OU_null", "OU_linear")
# FIT3b <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models,
# starting = list(BM_null_starting, BM_linear_starting, "NULL", "NULL") )
#
#
# ##EXAMPLE 4
# ###This example uses the syllable dataset for oscine songbirds Weir & Wheatcroft 2011
# data(bird.syllables)
# attach(bird.syllables)
#
# #STEP 1 Correct Euclidean distances for sampling and measurement bias
# DIST_cor <- MScorrection(nA=bird.syllables$number_individuals_Species1,
# nB=bird.syllables$number_individuals_Species2,
# VarA=bird.syllables$Species1_PC2_var,
# VarB=bird.syllables$Species2_PC2_var,
# DIST_actual=abs(bird.syllables$Species1_PC2_mean -
# bird.syllables$Species2_PC2_mean))
#
# #STEP 2 Test all models on oscines only (in which song has a strong
# #culturally transmitted component)
# DIST <- subset(DIST_cor, subset = (bird.syllables$Suboscine == "oscine"))
# TIME <- subset(bird.syllables$TIME,subset = (bird.syllables$Suboscine == "oscine"))
# GRAD <- subset(bird.syllables$GRAD,
# subset = (bird.syllables$Suboscine == "oscine"))
# FIT5 <- model.test.sisters(DIST=DIST, TIME=TIME, GRAD=GRAD, models=models)
# #The best fit model in FIT5 is BM_linear in which tropical species have a
# #much slower rate than temperate species.
# ## End(Not run)#end dontrun
Run the code above in your browser using DataLab