[Pomp-commits] r160 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 21 19:53:07 CEST 2009


Author: kingaa
Date: 2009-09-21 19:53:07 +0200 (Mon, 21 Sep 2009)
New Revision: 160

Added:
   pkg/R/slice.R
   pkg/man/slice.Rd
Log:
- add a new function "slice.design" for help with sliced likelihoods


Added: pkg/R/slice.R
===================================================================
--- pkg/R/slice.R	                        (rev 0)
+++ pkg/R/slice.R	2009-09-21 17:53:07 UTC (rev 160)
@@ -0,0 +1,21 @@
+slice.design <- function (vars, n) {
+  if (!is.list(vars) || is.null(names(vars)))
+    stop("slice.design error: ",sQuote("vars")," must be a named list")
+  if (!all(sapply(vars,function(x)is.numeric(x)&&(length(x)%in%c(1,3)))))
+    stop("slice.design error: each entry in ",sQuote("vars")," must specify a center or a center and range")
+  nvars <- length(vars)
+  varying <- which(sapply(vars,length)>1)
+  nranges <- length(varying)
+  center.point <- sapply(vars,function(x)if(length(x)>1){x[2]}else{x[1]})
+  ranges <- lapply(vars[varying],function(x)x[c(1,3)])
+  x <- as.data.frame(matrix(center.point,byrow=TRUE,ncol=nvars,nrow=n,dimnames=list(NULL,names(vars))))
+  y <- vector(mode="list",length=nranges)
+  for (v in seq(length=nranges)) {
+    y[[v]] <- x
+    w <- varying[v]
+    y[[v]][[w]] <- seq(from=ranges[[v]][1],to=ranges[[v]][2],length=n)
+  }
+  y <- do.call(rbind,y)
+  y$slice <- as.factor(rep(names(vars)[varying],each=n))
+  y
+}

Added: pkg/man/slice.Rd
===================================================================
--- pkg/man/slice.Rd	                        (rev 0)
+++ pkg/man/slice.Rd	2009-09-21 17:53:07 UTC (rev 160)
@@ -0,0 +1,29 @@
+\name{slice.design}
+\alias{slice.design}
+\title{Slices through multidimensional parameter space}
+\description{
+  Generate a data-frame representing points taken along one or more slices through a point in a multidimensional space.
+}
+\usage{
+slice.design(vars, n)
+}
+\arguments{
+  \item{vars}{
+    Named list of numeric vectors, each of which has length either 1 or 3.
+    Variables along which slices are to be taken should have length 3, corresponding to the minimum of the range, central point, and maximum of the range.
+    For fixed variables, specify just the value.
+  }
+  \item{n}{Number of points per slice.}
+}
+\value{
+  \code{slice.design} returns a data frame with \code{n} points per slice.
+  The column \code{slice} is a factor that tells which slice each point belongs to. 
+}
+\author{Aaron A. King \email{kingaa at umich dot edu}}
+\examples{
+## A single 11-point slice through the point c(A=3,B=8,C=0) along the B direction.
+slice.design(list(A=3,B=c(0,8,10),C=0),n=11)
+## Two slices through the same point along the A and C directions.
+slice.design(list(A=c(0,3,5),B=8,C=c(0,0,5)),n=11)
+}
+\keyword{design}



More information about the pomp-commits mailing list