[Pomp-commits] r333 - in pkg: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 28 17:22:42 CEST 2010


Author: kingaa
Date: 2010-09-28 17:22:42 +0200 (Tue, 28 Sep 2010)
New Revision: 333

Added:
   pkg/R/profile-design.R
   pkg/R/slice-design.R
   pkg/man/profile-design.Rd
   pkg/man/slice-design.Rd
Removed:
   pkg/R/slice.R
   pkg/man/slice.Rd
Modified:
   pkg/DESCRIPTION
   pkg/NAMESPACE
   pkg/R/sobol.R
   pkg/inst/NEWS
   pkg/man/sobol.Rd
Log:
- rearrange the slice and profile design functions to make them easier to use


Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/DESCRIPTION	2010-09-28 15:22:42 UTC (rev 333)
@@ -1,8 +1,8 @@
 Package: pomp
 Type: Package
 Title: Statistical inference for partially observed Markov processes
-Version: 0.33-1
-Date: 2010-09-25
+Version: 0.33-2
+Date: 2010-09-28
 Author: Aaron A. King, Edward L. Ionides, Carles Breto, Steve Ellner, Bruce Kendall, Helen Wearing, 
 	Matthew J. Ferrari, Michael Lavine, Daniel C. Reuman
 Maintainer: Aaron A. King <kingaa at umich.edu>
@@ -13,7 +13,8 @@
 License: GPL(>= 2)
 LazyLoad: true
 LazyData: false
-Collate: eulermultinom.R euler.R plugins.R slice.R sobol.R bsplines.R 
+Collate: eulermultinom.R euler.R plugins.R 
+	 slice-design.R profile-design.R sobol.R bsplines.R 
 	 pomp-fun.R pomp.R pomp-methods.R rmeasure-pomp.R rprocess-pomp.R 
 	 dmeasure-pomp.R dprocess-pomp.R simulate-pomp.R skeleton-pomp.R 
 	 trajectory-pomp.R plot-pomp.R init.state-pomp.R 

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/NAMESPACE	2010-09-28 15:22:42 UTC (rev 333)
@@ -56,6 +56,7 @@
        onestep.dens,
        gillespie.sim,
        sobol,
+       sobol.design,
        slice.design,
        profile.design,
        bspline.basis,

Added: pkg/R/profile-design.R
===================================================================
--- pkg/R/profile-design.R	                        (rev 0)
+++ pkg/R/profile-design.R	2010-09-28 15:22:42 UTC (rev 333)
@@ -0,0 +1,22 @@
+profile.design <- function (..., lower, upper, nprof) {
+  prof <- list(...)
+  pvars <- names(prof)
+  if (any(pvars==""))
+    stop(sQuote("profile.design"),": you cannot profile over an unnamed variable!")
+  ovars <- names(lower)
+  if (!all(sort(ovars)==sort(names(upper))))
+    stop(sQuote("profile.design"),": names of ",sQuote("lower")," and ",sQuote("upper")," must match!")
+  vars <- ovars[!(ovars%in%pvars)]
+  x <- as.matrix(expand.grid(...))
+  y <- as.matrix(sobol.design(lower=lower,upper=upper,nseq=nprof))
+  z <- array(dim=c(nrow(x)*nrow(y),ncol(x)+ncol(y)))
+  colnames(z) <- c(colnames(x),colnames(y))
+  i <- 1
+  for (j in seq_len(nrow(x))) {
+    for (k in seq_len(nrow(y))) {
+      z[i,] <- c(x[j,],y[k,])
+      i <- i+1
+    }
+  }
+  as.data.frame(z)
+}

Copied: pkg/R/slice-design.R (from rev 324, pkg/R/slice.R)
===================================================================
--- pkg/R/slice-design.R	                        (rev 0)
+++ pkg/R/slice-design.R	2010-09-28 15:22:42 UTC (rev 333)
@@ -0,0 +1,38 @@
+slice.design <- function (center, ...) {
+  slices <- list(...)
+  if ((!is.numeric(center))||is.null(names(center)))
+    stop(sQuote("slice.design"),": ",sQuote("center")," must be a named numeric vector")
+  slnm <- names(slices)
+  if (any(slnm==""))
+    stop(sQuote("slice.design"),": you cannot slice along an unnamed parameter")
+  if (!all(slnm%in%names(center))) {
+    problems <- slnm[!(slnm%in%names(center))]
+    stop(
+         sQuote("slice.design"),
+         " error: variable(s) ",
+         sQuote(paste(problems,collapse=",")),
+         " do not appear in ",
+         sQuote("center")
+         )
+  }
+  nslice <- length(slices)
+  nvars <- length(center)
+
+  y <- vector(mode="list",length=nslice)
+  for (k in seq_len(nslice)) {
+    y[[k]] <- as.data.frame(
+                            matrix(
+                                   data=center,
+                                   nrow=length(slices[[k]]),
+                                   ncol=nvars,
+                                   byrow=TRUE,
+                                   dimnames=list(names(slices[[k]]),names(center))
+                                   )
+                            )
+    y[[k]][[slnm[k]]] <- as.numeric(slices[[k]])
+    y[[k]]$slice <- slnm[k]
+  }
+  y <- do.call(rbind,y)
+  y$slice <- as.factor(y$slice)
+  y
+}

Deleted: pkg/R/slice.R
===================================================================
--- pkg/R/slice.R	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/R/slice.R	2010-09-28 15:22:42 UTC (rev 333)
@@ -1,36 +0,0 @@
-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_len(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
-}
-
-profile.design <- function (..., vars, n) {
-  prof <- list(...)
-  y <- as.matrix(sobol(vars,n))
-  x <- as.matrix(do.call(expand.grid,prof))
-  z <- array(dim=c(nrow(x),nrow(y),ncol(x)+ncol(y)))
-  for (j in seq_len(nrow(x))) {
-    for (k in seq_len(nrow(y))) {
-      z[j,k,] <- c(x[j,],y[k,])
-    }
-  }
-  dim(z) <- c(nrow(x)*nrow(y),ncol(x)+ncol(y))
-  colnames(z) <- c(colnames(x),colnames(y))
-  as.data.frame(z)
-}

Modified: pkg/R/sobol.R
===================================================================
--- pkg/R/sobol.R	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/R/sobol.R	2010-09-28 15:22:42 UTC (rev 333)
@@ -14,3 +14,17 @@
   colnames(y) <- names(vars)
   as.data.frame(y)
 }
+
+sobol.design <- function (lower = numeric(0), upper = numeric(0), nseq) {
+  if (length(lower)!=length(upper))
+    stop(sQuote("lower")," and ",sQuote("upper")," must have same length")
+  lnames <- names(lower)
+  if (is.null(lnames))
+    stop(sQuote("lower")," and ",sQuote("upper")," must be named vectors")
+  if (!all(sort(lnames)==sort(names(upper))))
+    stop("names of ",sQuote("lower")," and ",sQuote("upper")," must match")
+  upper <- upper[lnames]
+  ranges <- lapply(lnames,function(k)c(lower[k],upper[k]))
+  names(ranges) <- lnames
+  sobol(ranges,n=as.integer(nseq))
+}

Modified: pkg/inst/NEWS
===================================================================
--- pkg/inst/NEWS	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/inst/NEWS	2010-09-28 15:22:42 UTC (rev 333)
@@ -1,3 +1,8 @@
+NEW IN VERSION 0.33-1:
+    o Major improvements in speed in the probe-matching routines have been realized by coding the computationally-intensive portions of these calculations in C.  
+
+    o New probes recommended by Simon Wood (Nature 466:1102-1104, 2010) have been implemented.  In particular, the new function 'probe.marginal' regresses the marginal distributions of actual and simulated data against a reference distribution, returning as probes the regression coefficients.  'probe.marginal' and 'probe.acf' have been coded in C for speed.
+
 NEW IN VERSION 0.32-1:
     o  pomp now includes parameter estimation methods based on probe-matching and power-spectrum-matching as explained in papers by Kendall et al. (B. E. Kendall, C. J. Briggs, W. M. Murdoch, P. Turchin, S. P. Ellner, E. McCauley, R. M. Nisbet, S. N. Wood (1999) Why do populations cycle? A synthesis of statistical and mechanistic modeling approaches.  Ecology, 80:1789--1805) and Reuman et al. (D.C. Reuman, R.A. Desharnais, R.F. Costantino, O. Ahmad, J.E. Cohen (2006) Power spectra reveal the influence of stochasticity on nonlinear population dynamics. Proc. Nat'l. Acad. Sci., U.S.A.} 103:18860--18865).
 

Added: pkg/man/profile-design.Rd
===================================================================
--- pkg/man/profile-design.Rd	                        (rev 0)
+++ pkg/man/profile-design.Rd	2010-09-28 15:22:42 UTC (rev 333)
@@ -0,0 +1,37 @@
+\name{profile.design}
+\alias{profile.design}
+\title{Design matrices for likelihood profile calculations.}
+\description{
+  \code{profile.design} generates a data-frame where each row can be used as the starting point for a profile likelihood calculation.
+}
+\usage{
+profile.design(\dots, lower, upper, nprof)
+}
+\arguments{
+  \item{\dots}{
+    Specifies the parameters over which to profile.
+  }
+  \item{lower, upper}{
+    Named numeric vectors, specifying the range over which the other parameters are to be sampled.
+  }
+  \item{nprof}{
+    The number of starts per profile point.
+  }
+}
+\value{
+  \code{profile.design} returns a data frame with \code{nprof} points per profile point.
+  The other parameters in \code{vars} are sampled using \code{sobol}.
+}
+\seealso{\code{\link{sobol}}}
+\author{Aaron A. King \email{kingaa at umich dot edu}}
+\examples{
+## A one-parameter profile design:
+x <- profile.design(p=1:10,lower=c(a=0,b=0),upper=c(a=1,b=5),nprof=20)
+dim(x)
+plot(x)
+## A two-parameter profile design:
+x <- profile.design(p=1:10,q=3:5,lower=c(a=0,b=0),upper=c(b=5,a=1),nprof=20)
+dim(x)
+plot(x)
+}
+\keyword{design}

Copied: pkg/man/slice-design.Rd (from rev 324, pkg/man/slice.Rd)
===================================================================
--- pkg/man/slice-design.Rd	                        (rev 0)
+++ pkg/man/slice-design.Rd	2010-09-28 15:22:42 UTC (rev 333)
@@ -0,0 +1,34 @@
+\name{slice.design}
+\alias{slice.design}
+\title{Design matrices for likelihood slices.}
+\description{
+  \code{slice.design} generates a data-frame representing points taken along one or more slices through a point in a multidimensional space.
+}
+\usage{
+slice.design(center, ...)
+}
+\arguments{
+  \item{center}{
+    \code{center} is a named numeric vectors specifying the point through which the slice(s) is (are) to be taken.
+  }
+  \item{\dots}{
+    Additional numeric vector arguments specify the slices.
+  }
+}
+\value{
+  \code{slice.design} returns a data frame with one row per point along a slice.
+  The column \code{slice} is a factor that tells which slice each point belongs to. 
+}
+\seealso{\code{\link{profile.design}}}
+\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.
+x <- slice.design(center=c(A=3,B=8,C=0),B=seq(0,10,by=1))
+dim(x)
+plot(x)
+## Two slices through the same point along the A and C directions.
+x <- slice.design(c(A=3,B=8,C=0),A=seq(0,5,by=1),C=seq(0,5,length=11))
+dim(x)
+plot(x)
+}
+\keyword{design}

Deleted: pkg/man/slice.Rd
===================================================================
--- pkg/man/slice.Rd	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/man/slice.Rd	2010-09-28 15:22:42 UTC (rev 333)
@@ -1,59 +0,0 @@
-\name{slice.design}
-\alias{slice.design}
-\alias{profile.design}
-\title{Design matrices for likelihood slices and profiles}
-\description{
-  \code{slice.design} generates a data-frame representing points taken along one or more slices through a point in a multidimensional space.
-  \code{profile.design} generates a data-frame where each row can be used as the starting point for a profile likelihood calculation.
-}
-\usage{
-slice.design(vars, n)
-profile.design(\dots, vars, n)
-}
-\arguments{
-  \item{\dots}{
-    Specifies the parameters over which to profile.
-  }
-  \item{vars}{
-    For the \code{slice.design} case:
-    \code{vars} is a 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.
-
-    For the \code{profile.design} case:
-    Named list of numeric vectors, each of which has length 2, specifying the range over which the parameter is to be sampled.
-  }
-  \item{n}{
-    In the case of \code{slice.design}, the number of points per slice.
-    In the case of \code{profile.design}, the number of starts per profile point.
-  }
-}
-\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. 
-
-  \code{profile.design} returns a data frame with \code{n} points per profile point.
-  The parameters in \code{vars} are sampled using \code{sobol}.
-}
-\seealso{\code{\link{sobol}}}
-\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.
-x <- slice.design(list(A=3,B=c(0,8,10),C=0),n=11)
-dim(x)
-plot(x)
-## Two slices through the same point along the A and C directions.
-x <- slice.design(list(A=c(0,3,5),B=8,C=c(0,0,5)),n=11)
-dim(x)
-plot(x)
-
-## A one-parameter profile design:
-x <- profile.design(p=1:10,vars=list(a=c(0,1),b=c(0,5)),n=20)
-dim(x)
-plot(x)
-## A two-parameter profile design:
-x <- profile.design(p=1:10,q=3:5,vars=list(a=c(0,1),b=c(0,5)),n=20)
-dim(x)
-plot(x)
-}
-\keyword{design}

Modified: pkg/man/sobol.Rd
===================================================================
--- pkg/man/sobol.Rd	2010-09-28 15:06:56 UTC (rev 332)
+++ pkg/man/sobol.Rd	2010-09-28 15:22:42 UTC (rev 333)
@@ -6,15 +6,20 @@
 }
 \usage{
 sobol(vars, n)
+sobol.design(lower, upper, nseq)
 }
 \arguments{
   \item{vars}{Named list of ranges of variables.}
-  \item{n}{Number of vectors requested.}
+  \item{lower,upper}{named numeric vectors giving the lower and upper bounds of the ranges, respectively.}
+  \item{n,nseq}{Number of vectors requested.}
 }
 \value{
   \item{sobol}{
     Returns a data frame with \code{n} \sQuote{observations} of the variables in \code{vars}.
   }
+  \item{sobol.design}{
+    Returns a data frame with \code{nseq} \sQuote{observations} of the variables over the range specified.
+  }
 }
 \references{
   W. H. Press, S. A. Teukolsky, W. T. Vetterling, \& B. P. Flannery,
@@ -25,6 +30,6 @@
 \author{Aaron A. King \email{kingaa at umich dot edu}}
 \examples{
 plot(sobol(vars=list(a=c(0,1),b=c(100,200)),100))
-plot(sobol(vars=list(a=c(0,1),b=c(100,200),c=c(-1,1)),100))
+plot(sobol.design(lower=c(a=0,b=100),upper=c(b=200,a=1),100))
 }
 \keyword{design}



More information about the pomp-commits mailing list