[Mattice-commits] r104 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 22 18:23:48 CET 2008
Author: andrew_hipp
Date: 2008-12-22 18:23:48 +0100 (Mon, 22 Dec 2008)
New Revision: 104
Added:
pkg/man/informationCriterion.Rd
Removed:
pkg/man/print.hansenSummary.Rd
Modified:
pkg/R/informationCriterion.R
pkg/man/ouSim.Rd
Log:
added informationCriterion.Rd; updated informationCriterion.R with a print method; updated ouSim.Rd
Modified: pkg/R/informationCriterion.R
===================================================================
--- pkg/R/informationCriterion.R 2008-12-22 17:05:29 UTC (rev 103)
+++ pkg/R/informationCriterion.R 2008-12-22 17:23:48 UTC (rev 104)
@@ -1,6 +1,9 @@
informationCriterion <- function(u = NULL, lnL = NULL, K, n = 1, names = NULL) {
## Returns information criterion values + weights for a vector of u or lnL, a vector of K (= df), and a single n (sample size); names for analyses are optional
+ if(n = 1) warning("Information criterion values calculated assuming sample size = 1;
+ if this is accurate, consider additional sampling for future projects.")
if(identical(u,NULL)) u <- -2 * lnL # deviance (u) needed; take from lnL if not provided, ignore lnL if provided
+ if(identical(names, NULL)) names <- seq(length(u))
AIC <- vector("numeric", length(u))
BIC <- vector("numeric", length(u))
AICc <- vector("numeric", length(u))
@@ -14,7 +17,10 @@
AICwi <- as.vector(lapply(deltaAIC, function(x, allDelta) {exp(-0.5 * x) / sum(exp(-0.5 * allDelta), na.rm = T)}, allDelta = deltaAIC), mode = "numeric")
AICcwi <- as.vector(lapply(deltaAICc, function(x, allDelta) {exp(-0.5 * x) / sum(exp(-0.5 * allDelta), na.rm = T)}, allDelta = deltaAICc), mode = "numeric")
BICwi <- as.vector(lapply(deltaBIC, function(x, allDelta) {exp(-0.5 * x) / sum(exp(-0.5 * allDelta), na.rm = T)}, allDelta = deltaBIC), mode = "numeric")
- return(list(names = names, u = u, K = K, AIC = AIC, AICc = AICc, BIC = BIC, AICwi = AICwi, AICcwi = AICcwi, BICwi = BICwi)) }
+ outdata <- list(names = names, u = u, K = K, AIC = AIC, AICc = AICc, BIC = BIC, AICwi = AICwi, AICcwi = AICcwi, BICwi = BICwi)
+ class(outdata) <- 'informationCriterion'
+ return(outdata)
+}
informationCriterion.hansenBatch <- function(hansenBatch) {
## call informationCriterion for a 'hansen.batch' object
@@ -26,4 +32,11 @@
outdata[[i]] <- informationCriterion(lnL = temp[, 'loglik'], K = temp[, 'dof'], n = N, names = row.names(temp))
}
outdata
+}
+
+print.informationCriterion <- function(ic) {
+ items <- c('u', 'K', 'AIC', 'AICc', 'BIC', 'AICwi', 'AICcwi', 'BICwi')
+ out <- matrix(NA, nrow = length(ic$names), ncol = length(items), dimnames = list(ic$names, items))
+ for(i in items) out[, i] <- ic[[i]]
+ print(out)
}
\ No newline at end of file
Added: pkg/man/informationCriterion.Rd
===================================================================
--- pkg/man/informationCriterion.Rd (rev 0)
+++ pkg/man/informationCriterion.Rd 2008-12-22 17:23:48 UTC (rev 104)
@@ -0,0 +1,77 @@
+\name{informationCriterion}
+\alias{informationCriterion}
+\alias{informationCriterion.hansenBatch}
+\alias{print.informationCriterion}
+\title{Information criterion and weights for a set of models}
+\description {
+ Returns AIC, AICc, and BIC values and weights for a set of models.
+}
+\usage {
+ informationCriterion(u = NULL, lnL = NULL, K, n = 0, names = NULL)
+ informationCriterion.hansenBatch(hansenBatch)
+ print.informationCriterion(ic)
+}
+\details {
+ At the minimum, a vector of either the model log-likelihoods (\code{lnL}) or deviances (\code{u} = -2 * lnL) and a vector
+ of number of free parameters for each model (\code{K}) must be provided for the function to work. If the sample size
+ (\code{n}) is not provided, the function calculates AICc and BIC assuming \code{n} = 1. Information criterion statistics
+ are calculated following Burnham and Anderson (2002).
+}
+\arguments{
+ \item{u}{
+ A vector of deviances, indexed by model.
+ }
+ \item{lnL}{
+ A vector of log-likelihoods, indexed by model.
+ }
+ \item{K}{
+ A vector of degrees-of-freedom / number of free parameters, indexed by model.
+ }
+ \item{n}{
+ Sample size; for a phylogenetic comparative analysis, \code{n} = the number of tips.
+ }
+ \item{names}{
+ Optional vector of model names, indexed by model.
+ }
+ \item{hansenBatch}{
+ Output from \{runBatchHansen}.
+ \item{ic}{
+ Output from \{informationCriterion}.
+}
+\value{
+ A list with the following vectors, all indexed by model number:
+ \item{names}{
+ Model names; if not provided, a vector of 1:length(u).
+ }
+ \item{u}{
+ Deviance.
+ }
+ \item{K}{
+ Degrees of freedom.
+ }
+ \item{AIC}{
+ Akaike information criterion.
+ }
+ \item{AICc}{
+ Small-sample AIC.
+ }
+ \item{BIC}{
+ Bayes information criterion.
+ }
+ \item{AICwi}{
+ AIC weight.
+ }
+ \item{AICcwi}{
+ AICc weight.
+ }
+ \item{BICwi}{
+ BIC weight.
+ }
+
+}
+\author{Andrew Hipp ahipp at mortonarb.org}
+\references{
+ Burnham, K. P., and D. R. Anderson (2002)
+ Model selection and multimodel inference: a practical information-theoretic approach.
+ Springer, New York.
+}
\ No newline at end of file
Modified: pkg/man/ouSim.Rd
===================================================================
--- pkg/man/ouSim.Rd 2008-12-22 17:05:29 UTC (rev 103)
+++ pkg/man/ouSim.Rd 2008-12-22 17:23:48 UTC (rev 104)
@@ -1,5 +1,9 @@
\name{ouSim}
\alias{ouSim}
+\alias{ouSim.ouchtree}
+\alias{ouSim.brownHansen}
+\alias{ouSim.phylo}
+\alias{ouSim.hansenBatch}
\title{Discrete-time simulation of Ornstein-Uhlenbeck models on a user tree.}
\description{
\code{ouSim} simulates the evolution of a single character for visualization purposes; for parametric bootstrapping,
Deleted: pkg/man/print.hansenSummary.Rd
===================================================================
--- pkg/man/print.hansenSummary.Rd 2008-12-22 17:05:29 UTC (rev 103)
+++ pkg/man/print.hansenSummary.Rd 2008-12-22 17:23:48 UTC (rev 104)
@@ -1,22 +0,0 @@
-\name{print.hansenSummary}
-\alias{print.hansenSummary}
-\title{Print method for a hansenSummary object}
-\description{
- \code{print.hansenSummary} is a print method for a \code{hansenSummary} object.
-}
-\usage{
-print(hansenSummary)
-}
-\arguments{
- \item{hansenSummary}{
- Output from \code{summary.hansenBatch}.
- }
-}
-\details{
- This function provides an easy-to-read synopsis of the analysis summary. Called automatically when you simply type
- in the name of the summary object.
-}
-\author{Andrew Hipp <ahipp at mortonarb.org>}
-\seealso{
-\code{\link{carex}} for example
-}
More information about the Mattice-commits
mailing list