Skip to content

Commit

Permalink
some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kingaa committed Jul 4, 2024
1 parent ca463ba commit 10c1dd2
Show file tree
Hide file tree
Showing 25 changed files with 616 additions and 630 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ouch
Type: Package
Title: Ornstein-Uhlenbeck Models for Phylogenetic Comparative Hypotheses
Version: 2.19-3
Date: 2024-05-22
Version: 2.19-4
Date: 2024-07-04
Authors@R: c(person(given=c("Aaron","A."),family="King",role=c("aut","cre"),email="kingaa@umich.edu",comment=c(ORCID="0000-0001-6159-3207")),
person(given=c("Marguerite","A."),family="Butler",role=c("ctb")))
Maintainer: Aaron A. King <kingaa@umich.edu>
Expand All @@ -15,7 +15,7 @@ License: GPL-3
LazyLoad: true
LazyData: true
Roxygen: list(roclets = c("collate", "namespace", "rd"), markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
BugReports: https://github.com/kingaa/ouch/issues/
Encoding: UTF-8
Collate:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
REPODIR = repo
INCLUDES=
HEADERS=
SESSION_PKGS = datasets,utils,grDevices,graphics,stats,methods,tidyverse,$(PKG)

include rules.mk
79 changes: 39 additions & 40 deletions R/anolis.R
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
#' Greater Antillean anolis lizard sexual size dimorphism data
#'
#' The dataset consists of sexual size-dimorphism data for 38 species of anoles from Cuba, Hispaniola, Jamaica, and Puerto Rico (Butler, Schoener, and Losos 2000).
#' Each of these species belongs to one of six microhabitat types, or "ecomorphs" (sensu Williams, 1972):
#' trunk-ground, grass-bush, trunk, trunk-crown, twig, and crown-giant.
#' The data were used to demonstrate an evolutionary association between habitat type and degree of sexual size dimorphism.
#'
#' Size dimorphism was calcuated as the log-ratio of male snout-to-vent length to female snout-to-vent length (males are larger).
#'
#' In this example, we tested three models of evolution:
#' Brownian motion, Ornstein-Uhlenbeck with one global optimum, and Ornstein-Uhlenbeck with seven optima (one for each ecomorph type plus an additional one for an "unknown" type).
#'
#' For the seven-optima model, we assigned each terminal branch to an optimum according to the ecomorph type of the extant species.
#' Because we had no information to help guide hypotheses about internal branches, we assigned
#' internal branches to the "unknown" selective regime.
#' The phylogeny of these species is consistent with and adaptive radiation, with a burst of speciation events early in the evolutionary history of this clade (see phylogeny in Butler & King (2004) or example below).
#'
#' @name anolis.ssd
#' @rdname anolis_ssd
#' @family examples
#' @docType data
#' @format
#' A data frame with 38 observations on the following 6 variables.
#' - `node`: Labels for the nodes.
#' - `species`: Names of extant species.
#' - `log.SSD`: Log sexual size dimorphism of extant species.
#' - `ancestor`: Name of ancestor node.
#' - `time`: Time of node.
#' - `OU.1`: a factor with one level, `ns`.
#' - `OU.7`: a factor with levels corresponding to ecomorph (`tg`, `tc`, `gb`, `cg`, `tw`, `tr`, `anc`).
#' @author Marguerite A. Butler, Aaron A. King
#' @references
#' \Butler2000
#'
#' \Williams1972
#'
#' @source \Butler2004
#' @keywords models
#' @example examples/anolis.R
#'
##' Greater Antillean anolis lizard sexual size dimorphism data
##'
##' The dataset consists of sexual size-dimorphism data for 38 species of anoles from Cuba, Hispaniola, Jamaica, and Puerto Rico (Butler, Schoener, and Losos 2000).
##' Each of these species belongs to one of six microhabitat types, or "ecomorphs" (sensu Williams, 1972):
##' trunk-ground, grass-bush, trunk, trunk-crown, twig, and crown-giant.
##' The data were used to demonstrate an evolutionary association between habitat type and degree of sexual size dimorphism.
##'
##' Size dimorphism was calcuated as the log-ratio of male snout-to-vent length to female snout-to-vent length (males are larger).
##'
##' In this example, we tested three models of evolution:
##' Brownian motion, Ornstein-Uhlenbeck with one global optimum, and Ornstein-Uhlenbeck with seven optima (one for each ecomorph type plus an additional one for an "unknown" type).
##'
##' For the seven-optima model, we assigned each terminal branch to an optimum according to the ecomorph type of the extant species.
##' Because we had no information to help guide hypotheses about internal branches, we assigned
##' internal branches to the "unknown" selective regime.
##' The phylogeny of these species is consistent with and adaptive radiation, with a burst of speciation events early in the evolutionary history of this clade (see phylogeny in Butler & King (2004) or example below).
##'
##' @name anolis.ssd
##' @rdname anolis_ssd
##' @family examples
##' @docType data
##' @format
##' A data frame with 38 observations on the following 6 variables.
##' - `node`: Labels for the nodes.
##' - `species`: Names of extant species.
##' - `log.SSD`: Log sexual size dimorphism of extant species.
##' - `ancestor`: Name of ancestor node.
##' - `time`: Time of node.
##' - `OU.1`: a factor with one level, `ns`.
##' - `OU.7`: a factor with levels corresponding to ecomorph (`tg`, `tc`, `gb`, `cg`, `tw`, `tr`, `anc`).
##' @author Marguerite A. Butler, Aaron A. King
##' @references
##' \Butler2000
##'
##' \Williams1972
##'
##' @source \Butler2004
##' @keywords models
##' @example examples/anolis.R
NULL
40 changes: 20 additions & 20 deletions R/ape2ouch.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#' Convert an \pkg{ape} tree to an \pkg{ouch} tree
#'
#' `ape2ouch` translates \pkg{ape}'s `phylo` representation of a phylogenetic tree into \pkg{ouch}'s `ouchtree` representation.
#' Optionally, the user can adjust the branch lengths while preserving the topology.
#'
#' @param tree a tree of class [ape::phylo].
#' @param scale optional.
#' If `scale=TRUE`, the tree's depth will be scaled to 1.
#' If `scale` is a number, then the branch lengths will be scaled by this number.
#' @param branch.lengths optional vector of branch lengths.
#' @author A. A. King, D. Ackerly
#' @keywords models
#' @rdname ouchtree
#' @include ouchtree.R
#' @export
##' Convert an \pkg{ape} tree to an \pkg{ouch} tree
##'
##' `ape2ouch` translates \pkg{ape}'s `phylo` representation of a phylogenetic tree into \pkg{ouch}'s `ouchtree` representation.
##' Optionally, the user can adjust the branch lengths while preserving the topology.
##'
##' @param tree a tree of class [ape::phylo].
##' @param scale optional.
##' If `scale=TRUE`, the tree's depth will be scaled to 1.
##' If `scale` is a number, then the branch lengths will be scaled by this number.
##' @param branch.lengths optional vector of branch lengths.
##' @author A. A. King, D. Ackerly
##' @keywords models
##' @rdname ouchtree
##' @include ouchtree.R
##' @export
ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
## This function takes a tree file in the phylo format (from
## ape/read.tree) and creates an ouchtree object.
Expand All @@ -22,13 +22,13 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
## t = object of type `phylo`, as returned by ape::read.tree
## branch.lengths = optional branch length vector in same
## order as `t$edge.length`; default is to use `t$edge.length`
##
##
## D. Ackerly, July 18, 2006.
## Modified by A.A. King, 15 July 2007.

if (!inherits(tree,'phylo'))
pStop("ape2ouch",sQuote("tree")," must be of class ",sQuote("phylo"))

nnodes <- nrow(tree$edge)+1 # number of nodes
n.term <- length(tree$tip.label) # number of terminal nodes
n.int <- nnodes-n.term # internal nodes
Expand All @@ -53,7 +53,7 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
ancestor[n] <- node[1]
}
}

if (is.null(tree$node.label))
tree$node.label <- rep('',n.int)
species <- rev(c(tree$tip.label,tree$node.label[-1],tree$node.label[1]))
Expand All @@ -69,7 +69,7 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {
} else {
pStop("ape2ouch",sQuote("scale")," must be either logical or numeric.")
}

ouchtree(
nodes=node,
ancestors=ancestor,
Expand All @@ -80,7 +80,7 @@ ape2ouch <- function (tree, scale = TRUE, branch.lengths = tree$edge.length) {

branch_height <- function (node, anc, bl, k) {
## this recursion might prove expensive for large trees
## there should be a direct method
## there should be a direct method
if (is.na(anc[k])) {
0
} else {
Expand Down
28 changes: 14 additions & 14 deletions R/as_data_frame.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#' Coerce an \pkg{ouch} object to a data frame
#'
#' @name as_data_frame
#' @rdname as_data_frame
#' @family methods for ouch trees
#' @include ouchtree.R brown.R hansen.R
#' @inheritParams base::as.data.frame
#'
##' Coerce an \pkg{ouch} object to a data frame
##'
##' @name as_data_frame
##' @rdname as_data_frame
##' @family methods for ouch trees
##' @include ouchtree.R brown.R hansen.R
##' @inheritParams base::as.data.frame
##'
NULL

#' @rdname as_data_frame
#' @export
##' @rdname as_data_frame
##' @export
as.data.frame.ouchtree <- function (x, ...) as(x,"data.frame")

#' @rdname as_data_frame
#' @export
##' @rdname as_data_frame
##' @export
as.data.frame.browntree <- function (x, ...) as(x,"data.frame")

#' @rdname as_data_frame
#' @export
##' @rdname as_data_frame
##' @export
as.data.frame.hansentree <- function (x, ...) as(x,"data.frame")
101 changes: 50 additions & 51 deletions R/bimac.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
#' Anolis bimaculatus lizard size data
#'
#' This is the \emph{Anolis bimaculatus} dataset used in Butler & King (2004).
#' It is used to test a hypothesis of character displacement using an interspecific dataset of body sizes and current data on sympatry/allopatry.
#'
#' Explanations of the data follow:
#' - **Body size.**
#' We use the phenotypic data and phylogeny of Losos (1990), which employed the head lengths (of males) as a proxy for body size.
#' In this group of lizards, head length correlates very strongly with snout-to-vent length and the cube root of mass, which are standard measures of body size.
#' The data are head lengths in mm; note that we use the log of this value in analyses.
#' - **Tree structure.**
#' The phylogenetic tree is encoded via three variables:
#' `node`, `ancestor`, and `time`.
#' The `node` variable gives a name to each node.
#' The `ancestor` variable names the ancestor of each node.
#' The root node has no ancestor (i.e., \code{ancestor=NA}).
#' The variable `time` specifies the temporal location of each node, the root node being at time 0.
#' - **Specifications of selective regimes.**
#' (Columns `OU.1`, `OU.3`, `OU.4`, `OU.LP`).
#' These columns are factors, the levels of which correspond to the \dQuote{paintings} of the respective adaptive regime hypotheses onto the phylogeny (see [paint()]).
#' Each selective regime is named (small, medium, large, etc.).
#' Each column corresponds to a different painting of the selective regimes, and thus to a different hypothesis.
#' In this example, there are 3 alternative models (see Butler & King 2004): `OU.4` is 4-regime model, `OU.3` is 3-regime model (all ancestors are medium), `OU.LP` is the linear parsimony model.
#' - **Other variables.**
#' In addition to the above, there is a two-letter code for each taxon (`spcode`) and the name of the island on which the taxon is found (`island`).
#'
#' @name bimac
#' @rdname bimac
#' @docType data
#' @family examples
#' @format A data frame with 45 observations on the following 11 variables.
#' - `node`: Labels for the nodes.
#' - `spcode`: Two-letter code for each taxon.
#' - `species`: Species names for extant species.
#' - `island`: Name of the island on which the population is found.
#' - `size`: Body size (head length in mm) of extant species.
#' - `ancestor`: Ancestral node.
#' - `time`: Time of node.
#' - `OU.1`: a factor with levels `ns`
#' - `OU.3`: a factor with levels `small`, `medium`, `large`
#' - `OU.4`: a factor with levels `small`, `medium`, `large`, `anc`
#' - `OU.LP`: a factor with levels `small`, `medium`, `large`
#' @author Marguerite A. Butler and Aaron A. King
#' @references
#' \Lazell1972
#'
#' \Losos1990
#' @source \Butler2004
#' @keywords models
#' @example examples/bimac.R
#'
##' Anolis bimaculatus lizard size data
##'
##' This is the \emph{Anolis bimaculatus} dataset used in Butler & King (2004).
##' It is used to test a hypothesis of character displacement using an interspecific dataset of body sizes and current data on sympatry/allopatry.
##'
##' Explanations of the data follow:
##' - **Body size.**
##' We use the phenotypic data and phylogeny of Losos (1990), which employed the head lengths (of males) as a proxy for body size.
##' In this group of lizards, head length correlates very strongly with snout-to-vent length and the cube root of mass, which are standard measures of body size.
##' The data are head lengths in mm; note that we use the log of this value in analyses.
##' - **Tree structure.**
##' The phylogenetic tree is encoded via three variables:
##' `node`, `ancestor`, and `time`.
##' The `node` variable gives a name to each node.
##' The `ancestor` variable names the ancestor of each node.
##' The root node has no ancestor (i.e., \code{ancestor=NA}).
##' The variable `time` specifies the temporal location of each node, the root node being at time 0.
##' - **Specifications of selective regimes.**
##' (Columns `OU.1`, `OU.3`, `OU.4`, `OU.LP`).
##' These columns are factors, the levels of which correspond to the \dQuote{paintings} of the respective adaptive regime hypotheses onto the phylogeny (see [paint()]).
##' Each selective regime is named (small, medium, large, etc.).
##' Each column corresponds to a different painting of the selective regimes, and thus to a different hypothesis.
##' In this example, there are 3 alternative models (see Butler & King 2004): `OU.4` is 4-regime model, `OU.3` is 3-regime model (all ancestors are medium), `OU.LP` is the linear parsimony model.
##' - **Other variables.**
##' In addition to the above, there is a two-letter code for each taxon (`spcode`) and the name of the island on which the taxon is found (`island`).
##'
##' @name bimac
##' @rdname bimac
##' @docType data
##' @family examples
##' @format A data frame with 45 observations on the following 11 variables.
##' - `node`: Labels for the nodes.
##' - `spcode`: Two-letter code for each taxon.
##' - `species`: Species names for extant species.
##' - `island`: Name of the island on which the population is found.
##' - `size`: Body size (head length in mm) of extant species.
##' - `ancestor`: Ancestral node.
##' - `time`: Time of node.
##' - `OU.1`: a factor with levels `ns`
##' - `OU.3`: a factor with levels `small`, `medium`, `large`
##' - `OU.4`: a factor with levels `small`, `medium`, `large`, `anc`
##' - `OU.LP`: a factor with levels `small`, `medium`, `large`
##' @author Marguerite A. Butler and Aaron A. King
##' @references
##' \Lazell1972
##'
##' \Losos1990
##' @source \Butler2004
##' @keywords models
##' @example examples/bimac.R
NULL
36 changes: 18 additions & 18 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#' Bootstrapping for uncertainty quantification
#'
#' Parametric bootstrapping for \pkg{ouch} models.
#'
#' `bootstrap` performs a parametric bootstrap for estimation of confidence intervals.
#'
#' @rdname bootstrap
#' @name bootstrap
#' @family methods for ouch trees
#' @example examples/bootstrap.R
#' @param object A fitted model object.
#' @param nboot integer; number of bootstrap replicates.
#' @param seed integer; setting `seed` to a non-`NULL` value allows one to fix the random seed (see [simulate]).
#' @param ... Additional arguments are passed to [`update`].
##' Bootstrapping for uncertainty quantification
##'
##' Parametric bootstrapping for \pkg{ouch} models.
##'
##' `bootstrap` performs a parametric bootstrap for estimation of confidence intervals.
##'
##' @rdname bootstrap
##' @name bootstrap
##' @family methods for ouch trees
##' @example examples/bootstrap.R
##' @param object A fitted model object.
##' @param nboot integer; number of bootstrap replicates.
##' @param seed integer; setting `seed` to a non-`NULL` value allows one to fix the random seed (see [simulate]).
##' @param ... Additional arguments are passed to [`update`].
NULL

setGeneric(
Expand All @@ -21,8 +21,8 @@ setGeneric(
}
)

#' @rdname bootstrap
#' @export
##' @rdname bootstrap
##' @export
setMethod(
"bootstrap",
signature=signature(object="missing"),
Expand All @@ -31,8 +31,8 @@ setMethod(
}
)

#' @rdname bootstrap
#' @export
##' @rdname bootstrap
##' @export
setMethod(
"bootstrap",
signature=signature(object="ANY"),
Expand Down
Loading

0 comments on commit 10c1dd2

Please sign in to comment.