[Pomp-commits] r140 - pkg/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 2 22:12:17 CEST 2009


Author: kingaa
Date: 2009-06-02 22:12:12 +0200 (Tue, 02 Jun 2009)
New Revision: 140

Modified:
   pkg/man/init.state-pomp.Rd
   pkg/man/pomp.Rd
   pkg/man/simulate-pomp.Rd
   pkg/man/trajectory-pomp.Rd
Log:
add some nice examples

Modified: pkg/man/init.state-pomp.Rd
===================================================================
--- pkg/man/init.state-pomp.Rd	2009-06-02 19:20:50 UTC (rev 139)
+++ pkg/man/init.state-pomp.Rd	2009-06-02 20:12:12 UTC (rev 140)
@@ -24,6 +24,15 @@
 \value{
   Returns a matrix of initial states (with rownames).
 }
+\examples{
+data(ou2)
+coef(ou2)
+init.state(ou2)
+
+data(euler.sir)
+coef(euler.sir)
+init.state(euler.sir)
+}
 \author{Aaron A. King \email{kingaa at umich dot edu}}
 \seealso{\code{\link{pomp-class}}}
 \keyword{models}

Modified: pkg/man/pomp.Rd
===================================================================
--- pkg/man/pomp.Rd	2009-06-02 19:20:50 UTC (rev 139)
+++ pkg/man/pomp.Rd	2009-06-02 20:12:12 UTC (rev 140)
@@ -253,43 +253,37 @@
 
 ## simulate
 examples <- simulate(rw2,params=p)
-rw2 <- examples[[1]]  ## by default, simulate produces a list of pomp objects
-plot(rw2)
+plot(examples[[1]])
 
-t <- seq(0,20)
-X <- simulate(rw2,params=p[,1],nsim=10,states=TRUE,obs=TRUE,times=t)
+## construct an (almost) equivalent pomp object using a plugin:
+rw2 <- pomp(
+            rprocess = euler.simulate,
+            step.fun = function (x, t, params, delta.t, ...) {
+              y <- rnorm(n=2,mean=x[c("x1","x2")],sd=params[c("s1","s2")]*delta.t)
+              names(y) <- c("x1","x2")
+              y
+            },
+            rmeasure = function (x, t, params, ...) {
+              y <- rnorm(n=2,mean=x[c("x1","x2")],sd=params["tau"])
+              names(y) <- c("y1","y2")
+              y
+            },
+            dmeasure = function (y, x, t, params, log, ...) {
+              d <- dnorm(x=y[c("y1","y2")],mean=x[c("x1","x2")],sd=params["tau"],log=TRUE)
+              print(d)
+              if (log) sum(d,na.rm=T) else exp(sum(d,na.rm=T))
+            },
+            delta.t=1,
+            data=data.frame(
+                            time=1:100,
+                            y1=rep(c(1,2,3,4,NA),20),
+                            y2=0
+                            ),
+            times="time",
+            t0=0
+            )
+rw2 <- simulate(rw2,params=c(s1=2,s2=0.1,tau=1,x1.0=0,x2.0=0))
 
-## compute the process model likelihoods
-f <- dprocess(
-              rw2,
-              x=X$states,
-              times=t,
-              params=matrix(
-                p[,1],
-                nrow=nrow(p),
-                ncol=10,
-                dimnames=list(rownames(p),NULL)
-                ),
-              log=TRUE
-              )
-apply(f,1,sum)
-
-## compute the measurement likelihoods
-g <- dmeasure(
-              rw2,
-              y=X$obs[,7,],
-              x=X$states,
-              times=t,
-              params=matrix(
-                p[,1],
-                nrow=nrow(p),
-                ncol=10,
-                dimnames=list(rownames(p),NULL)
-                ),
-              log=TRUE
-              )
-apply(g,1,sum)
-
 ## For more examples, see the vignettes.
 }
 \section{Warning}{
@@ -308,7 +302,7 @@
   \code{\link{dmeasure}},
   \code{\link{skeleton}},
   \code{\link{init.state}},
-  \link{euler}
+  \link[pomp]{euler}
 }
 \keyword{models}
 \keyword{ts}

Modified: pkg/man/simulate-pomp.Rd
===================================================================
--- pkg/man/simulate-pomp.Rd	2009-06-02 19:20:50 UTC (rev 139)
+++ pkg/man/simulate-pomp.Rd	2009-06-02 20:12:12 UTC (rev 140)
@@ -51,6 +51,11 @@
   Simulation of the state process and of the measurement process are each accomplished by a single call to the user-supplied \code{rprocess} and \code{rmeasure} functions, respectively.
   This makes it possible for the user to write highly optimized code for these potentially expensive computations.
 }
+\examples{
+data(ou2)
+x <- simulate(ou2,seed=3495485,nsim=10)
+x <- simulate(ou2,seed=3495485,nsim=10,states=TRUE,obs=TRUE)
+}
 \author{Aaron A. King \email{kingaa at umich dot edu}}
 \seealso{\link{pomp-class}}
 \keyword{models}

Modified: pkg/man/trajectory-pomp.Rd
===================================================================
--- pkg/man/trajectory-pomp.Rd	2009-06-02 19:20:50 UTC (rev 139)
+++ pkg/man/trajectory-pomp.Rd	2009-06-02 20:12:12 UTC (rev 140)
@@ -40,6 +40,17 @@
   Unresolved issue: What is the behavior if \code{type="map"} and \code{times} are non-integral?
 }
 \author{Aaron A. King \email{kingaa at umich dot edu}}
+\examples{
+data(euler.sir)
+x <- trajectory(euler.sir)
+plot(time(euler.sir,t0=TRUE),x["I",1,],type='l',xlab='time',ylab='I')
+lines(time(euler.sir,t0=FALSE),diff(x["cases",1,]),col='red')
+
+coef(euler.sir,c("gamma")) <- log(12)
+x <- trajectory(euler.sir)
+plot(time(euler.sir,t0=TRUE),x["I",1,],type='l',xlab='time',ylab='I')
+lines(time(euler.sir,t0=FALSE),diff(x["cases",1,]),col='red')
+}
 \seealso{\code{\link{pomp-class}}, \code{\link{pomp}}, \code{\link[deSolve]{lsoda}}}
 \keyword{models}
 \keyword{ts}



More information about the pomp-commits mailing list