[Mattice-commits] r93 - in pkg: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Dec 18 16:43:06 CET 2008
Author: andrew_hipp
Date: 2008-12-18 16:43:06 +0100 (Thu, 18 Dec 2008)
New Revision: 93
Added:
pkg/inst/VERSIONS
pkg/man/plot.ouSim.Rd
Modified:
pkg/DESCRIPTION
pkg/R/ouSim.hansenBatch.R
pkg/R/ouSim.phylo.R
pkg/R/ouSimHead.R
pkg/R/plot.ouSim.R
pkg/man/ouSim.Rd
pkg/man/runBatchHansen.Rd
Log:
core documentation complete; updated to version 0.4
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/DESCRIPTION 2008-12-18 15:43:06 UTC (rev 93)
@@ -1,8 +1,8 @@
Package: maticce
Type: Package
Title: Mapping Transitions in Continuous Character Evolution
-Version: 0.1
-Date: 2008-11-13
+Version: 0.4
+Date: 2008-12-18
Depends: ouch, ape
Suggests: phylobase, geiger
Author: Andrew Hipp <ahipp at mortonarb.org>, with contributions from Marcial Escudero.
Modified: pkg/R/ouSim.hansenBatch.R
===================================================================
--- pkg/R/ouSim.hansenBatch.R 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/R/ouSim.hansenBatch.R 2008-12-18 15:43:06 UTC (rev 93)
@@ -1,9 +1,9 @@
ouSim.hansenBatch <- function(analysis, tree, treeNum = 1, rootState = NULL, ...) {
## runs ouSim.ouchtree for a hansenBatch or hansenSummary object, using the model-averaged alpha, sigma.squared, and theta vector from one tree
-## tree, rootState = 0, alpha = 0, variance = 1, theta = rootState, steps = 1000
if(class(analysis) == "hansenBatch") analysis <- summary(analysis)
if(identical(rootState, NULL)) rootState <- analysis$thetaMatrix[treeNum, ][tree at root] # rootstate taken to be the optimum at the root
outdata <- ouSim(tree, rootState, alpha = analysis$modelAvgAlpha, variance = analysis$modelAvgSigmaSq, theta = analysis$thetaMatrix[treeNum, ], ...)
+ class(outdata) <- "ouSim"
return(outdata)
}
@@ -25,5 +25,6 @@
tree <- ouchtree(analysis at nodes, analysis at ancestors, analysis at times)
outdata <- ouSim.ouchtree(tree, rootState, alpha, variance, theta, ...)
outdata$colors <- analysis at regimes[[1]]
+ class(outdata) <- "ouSim"
return(outdata)
}
\ No newline at end of file
Modified: pkg/R/ouSim.phylo.R
===================================================================
--- pkg/R/ouSim.phylo.R 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/R/ouSim.phylo.R 2008-12-18 15:43:06 UTC (rev 93)
@@ -62,6 +62,6 @@
if(model == "meanVar") branchList <- branchList
value <- (list(branchList = branchList, timesList = timesList, steps = steps, parameters = list(rootState = rootState, alpha = alpha, variance = variance, theta = theta)))
-class(value) <- "ouSimPhylo"
+class(value) <- "ouSim"
return(value)
}
\ No newline at end of file
Modified: pkg/R/ouSimHead.R
===================================================================
--- pkg/R/ouSimHead.R 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/R/ouSimHead.R 2008-12-18 15:43:06 UTC (rev 93)
@@ -1,16 +1,12 @@
-ouSim <- function(tree, ...) {
+ouSim <- function(object, ...) {
# right now this is just a switcher, but eventually these should be turned into proper methods of a generic ouSim
- if(class(try(colors, silent = T)) == 'try-error') {
- if("colors" %in% names(ouSim)) colors <- ouSim$colors
- else colors <- rep("black", length(ouSim$branchList))
- }
- switch(class(tree),
- phylo = ouSim.phylo(tree, ...), # original function
- ouchtree = ouSim.ouchtree(tree, ...), # completed
- browntree = ouSim.brownHansen(tree, ...), # completed
- hansentree = ouSim.brownHansen(tree, ...),
- hansenBatch = ouSim.hansenBatch(tree, ...), # completed
- hansenSummary = ouSim.hansenBatch(tree, ...), # completed
+ switch(class(object),
+ phylo = ouSim.phylo(object, ...),
+ ouchtree = ouSim.ouchtree(object, ...),
+ browntree = ouSim.brownHansen(object, ...),
+ hansentree = ouSim.brownHansen(object, ...),
+ hansenBatch = ouSim.hansenBatch(object, ...),
+ hansenSummary = ouSim.hansenBatch(object, ...),
stop("Unrecognized tree class")
)
}
\ No newline at end of file
Modified: pkg/R/plot.ouSim.R
===================================================================
--- pkg/R/plot.ouSim.R 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/R/plot.ouSim.R 2008-12-18 15:43:06 UTC (rev 93)
@@ -1,12 +1,13 @@
-plot.ouSimPhylo <- function(ouSim, nodeColor = "blue", nodeDotSize = 1.4, colors = NULL, ...) {
+plot.ouSim <- function(ouSim, nodeColor = "blue", nodeDotSize = 1.4, colors = NULL, ...) {
## To plot different clades, set the colors vector according to the branches in the original
## only passes the ... along to lines
+ branches = length(ouSim$branchList)
+ if(length(nodeColor) == 1) nodeColor <- rep(nodeColor, branches)
if(identical(colors, NULL)) {
if("colors" %in% names(ouSim)) colors <- ouSim$colors
- else colors <- rep("black", length(ouSim$branchList))
+ else colors <- rep("black", branches)
}
- branches = length(ouSim$branchList)
plot(1:ouSim$steps, ylim = range(unlist(ouSim$branchList)), type = "n", ylab = "Trait value", xlab = "Time")
for(i in 1:branches) lines(ouSim$timesList[[i]], ouSim$branchList[[i]], col = colors[i], ...)
- for(i in 1:branches) points(ouSim$timesList[[i]][1], ouSim$branchList[[i]][1], pch = 19, col = nodeColor, cex = nodeDotSize)
+ for(i in 1:branches) points(ouSim$timesList[[i]][1], ouSim$branchList[[i]][1], pch = 19, col = nodeColor[i], cex = nodeDotSize)
}
\ No newline at end of file
Added: pkg/inst/VERSIONS
===================================================================
--- pkg/inst/VERSIONS (rev 0)
+++ pkg/inst/VERSIONS 2008-12-18 15:43:06 UTC (rev 93)
@@ -0,0 +1,7 @@
+v0.5 18 December 2008
+- All functions working correctly with ouch v2
+- core documentation completed
+
+v0.1 13 November 2008
+- Project initiated
+- Old functions moved to R-Forge, beginning translation to ouch v2
\ No newline at end of file
Modified: pkg/man/ouSim.Rd
===================================================================
--- pkg/man/ouSim.Rd 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/man/ouSim.Rd 2008-12-18 15:43:06 UTC (rev 93)
@@ -2,67 +2,112 @@
\alias{ouSim}
\title{Discrete-time simulation of Ornstein-Uhlenbeck models on a user tree.}
\description{
- \code{ouSim} simulates the evolution of a single character on an \code{ape}-style user tree under arbitrarily
- complex Ornstein-Uhlenbeck models.
+ \code{ouSim} simulates the evolution of a single character for visualization purposes; for parametric bootstrapping,
+ utilize the \code{simulate} methods in \code{ouch}.
}
\usage{
-(phy, rootState = 0, shiftBranches = NULL, shiftStates = NULL, alpha = 0, variance = 1, theta = rootState, model = "OU", branchMeans = NULL, steps = 1000)
+ ouSim(object, ...) ## Generic function
+ ouSim.phylo(phy, rootState = 0, shiftBranches = NULL, shiftStates = NULL, alpha = 0, variance = 1, theta = rootState, model = "OU", branchMeans = NULL, steps = 1000)
+ ouSim.ouchtree(tree, rootState = 0, alpha = 0, variance = 1, theta = rootState, steps = 1000)
+ ouSim.brownHansen(analysis, ...)
+ ouSim.hansenBatch(analysis, tree, treeNum = 1, rootState = NULL, ...)
}
+\details{
+ A call to \code{ouSim} detects the class of \code{object} and behaves as follows:
+ \item{phylo} {
+ With an \code{ape}-style tree, all parameters of the model are specified by branch. Most flexibility, least convenience.
+ }
+ \item{ouchtree} {
+ With an \code{ouch}-style (S4) tree, again, all parameters of the model are specified by branch.
+ Somewhat less flexibility than \code{ouSim.phylo} but all the pain. Typically just called by the next two methods.
+ }
+ \item{browntree} {
+ All Brownian motion model parameters and tree are extracted from the \code{browntree} object.
+ }
+ \item{hansentree} {
+ All Ornstein-Uhlenbeck model parameters and tree are extracted from the \code{hansentree} object.
+ Only the first regime is utilized.
+ }
+ \item{hansenBatch} {
+ Model-averaged parameters from the \code{hansenBatch} object are used for analysis.
+ One of the trees used for analysis must be provided, and a corrsponding tree number must be provided so that
+ branches are indexed correctly.
+ }
+ \item{hansenSummary} {
+ Behaves exactly like a \code{hansenBatch} object.
+ }
+ ouSim.phylo is a very basic simulation engine, but also the most flexible. As written, the user has to specify the
+ model using two vectors that correspond to the branches in an \code{ape}-format tree. It is important to note that
+ this simulation method is really heuristic device, not appropriate for estimating parameter distributions. For
+ analysis purposes, you should utilize the \code{simulate} and \code{bootstrap} methods in \code{ouch}.
+}
\arguments{
- \item{phy}{
- An object of class \code{phylo}.
- }
- \item{rootState}{
- The character state at the root of the tree
- }
- \item{shiftBranches}{
- An optional vector indicating any branches at which an OU model has a determined shift in ancestral state.
+ \item{object} {
+ In a call to the generic function, an object of class ouchtree, browntree, hansentree, hansenBatch, or hansenSummary.
+ }
+ \item{phy} {
+ An \code{ape}-style tree, class \code{phylo}.
+ }
+ \item{rootState} {
+ The character state at the root of the tree. In a {browntree} object, this value is provided. In a {hansentree} or
+ {batchHansen} object, the value at the root is not provided, but it is taken to be the equilibrium or optimum
+ (\code{theta}) at the root of the tree.
+ }
+ \item{shiftBranches} {
+ For a \code{phylo} tree only. An optional vector indicating any branches at which an OU model has a determined shift in ancestral state.
Same order as \code{shiftStates}. This argument and \code{shiftStates} are only needed if you want to specify a model with
a disjunction in phenotype, similar to restarting evolution at a new point.
}
- \item{shiftStates}{
- An optional vector of length = \code{length(shiftStates)} indicating the ancestrat states for the branches at which the state shifts.
+ \item{shiftStates} {
+ For a \code{phylo} tree only. An optional vector of length = \code{length(shiftStates)} indicating
+ the ancestral states for the branches at which the state shifts.
}
- \item{alpha}{
- The strength of attraction toward an equilibrium or optimum. This term is refered to as the rate of evolution by Hansen (1997)
+ \item{alpha} {
+ The rate of evolution toward an equilibrium or optimum. This term is refered to as the rate of evolution by Hansen (1997)
and the strength of selection by Butler and King (2004). It is a multiplier by the difference between the character state and the
character state optimum. Alpha can be submitted as a single value applied to all branches or as a vector corresponding to branches
in the \code{phylo} object. At \code{alpha = 0}, the simulation approximates a Brownian motion process.
+ This parameter is taken from the analysis results for \code{browntree} (\code{alpha} = 0), \code{hansentree} (point estimate},
+ \code{hansenBatch} or \code{hansenSummary} (model-averaged).
}
- \item{variance}{
+ \item{variance} {
The variance on the stochastic portion of the Ornstein-Uhlenbeck model.
+ This parameter is taken from the analysis results for \code{browntree} (\code{alpha} = 0), \code{hansentree} (point estimate},
+ \code{hansenBatch} or \code{hansenSummary} (model-averaged).
}
- \item{theta}{
- The character state optimum. \code{theta} can be submitted as a single value or, like \code{alpha}, as a vector corresponding to
- branches of the tree.
+ \item{theta} {
+ The character state optimum. \code{theta} can be submitted as a single value or, like \code{alpha},
+ as a vector corresponding to branches of the tree.
+ This parameter is taken from the analysis results for \code{browntree} (\code{alpha} = 0), \code{hansentree} (point estimate},
+ \code{hansenBatch} or \code{hansenSummary} (model-averaged).
}
- \item{branchMeans}
- The mean for each branch, utilized only in the Platt model.
+ \item{model} {
+ For a \code{phylo} tree only. Specify "OU" for Ornstein-Uhlenbeck and Brownian motion models, "meanVar" for a model
+ in which the variance is constant across the tree, but mean varies by branch, and distribution in each generation
+ depends on only these parameters (ancestry is not considered, only current mean and variance).
}
- \item{steps}
+ \item{branchMeans} {
+ For a \code{phylo} tree only. The mean for each branch, utilized only in the "meanVar" model.
+ }
+ \item{steps} {
The number of slices into which the tree is divided for simulation.
}
}
-\details{
- ouSim as currently written is a very basic simulation engine, but also flexible. As written, the user has to specify the
- model using two vectors that correspond to the branches in an \code{ape} format tree (a \code{phylo} object). The next
- iteration of this function will take an ouchtree as input; interface with the \code{regimeVectors} function for painting
- regimes; accept a \code{hansentree} or \code{ouchtree} object as input, using the actual regimes and estimated paramters
- to run the simulation; and return results that are scaled correctly for the tree (I believe at this point that the
- sigma and alpha parameters don't return results that match the distributions you get using \code{simulate} on a \code{hansentree}
- or \code{browntree} object, which you should.
-
- To do: split ouSim into two functions, one handling an \code{ape} format tree and the other handling an \code{ouchtree}
- object, with the option in the latter case of catching a \code{hansentree} or \code{browntree} as discussed above.
-}
\value{
A list of class 'ouSim' that describes the phenotype at the beginning and end of each branch segment, as well as the model.
}
\author{Andrew Hipp ahipp at mortonarb.org}
\seealso{
- \code{plot.ouSim} for visualizing simulation
+ \code{\link{plot.ouSim}} for visualizing simulation
+ \code{\link{carex}} for examples
}
-\examples{
-XXX
-}
+\references{
+ Hansen, T.F. (1997)
+ Stabilizing selection and the comparative analysis of adaptation.
+ Evolution 51:1341-1351.
+
+ Butler, M. and A.A. King. (2004)
+ Phylogenetic comparative analysis: a modeling approach for adaptive evolution.
+ American Naturalist 164:683-695.
+ }
\keyword{models}
Added: pkg/man/plot.ouSim.Rd
===================================================================
--- pkg/man/plot.ouSim.Rd (rev 0)
+++ pkg/man/plot.ouSim.Rd 2008-12-18 15:43:06 UTC (rev 93)
@@ -0,0 +1,35 @@
+\name{plot.ouSim}
+\alias{plot.ouSim}
+\title{Visualizing discrete-time simulation of Ornstein-Uhlenbeck models.}
+\description{
+ \code{plot.ouSim} is a \code{plot} method for an \code{ouSim} object.
+}
+\usage{
+ plot.ouSim(ouSim, nodeColor = "blue", nodeDotSize = 1.4, colors = NULL, ...)
+}
+\arguments{
+ \item{ouSim} {
+ An \code{ouSim} object.
+ }
+ \item{nodeColor} {
+ A single color for the dot indicating nodes, or a vector of colors corrsponding to node numbers.
+ }
+ \item{nodeDotSize} {
+ Size of the dot at the nodes.
+ }
+ \item{colors} {
+ A vector correponding to branches. If not provided, color is extracted from the regime in a \code{hansentree} object.
+ This vector can be the same format as a regime, so you can color branches with a call to \code{\link{paintBranches}}.
+ }
+ \item{...} {
+ Additional arguments passed along to \code{lines} (e.g., \code{lwd} for line width, \code{lty} for line type).
+ }
+}
+\value{
+ None. Called for its side-effect (plotting).
+ }
+\author{Andrew Hipp ahipp at mortonarb.org}
+\seealso{
+ \code{\link{ouSim}} for simulations
+ \code{\link{carex}} for examples
+}
Modified: pkg/man/runBatchHansen.Rd
===================================================================
--- pkg/man/runBatchHansen.Rd 2008-12-17 22:54:46 UTC (rev 92)
+++ pkg/man/runBatchHansen.Rd 2008-12-18 15:43:06 UTC (rev 93)
@@ -95,6 +95,3 @@
\code{\link{summary.hansenBatch}} for summarizing data
\code{\link{carex}} for an example
}
-\examples{
-## See \code{\link{carex}} for example
-}
More information about the Mattice-commits
mailing list