[Yuima-commits] r84 - in pkg/yuima: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 28 10:45:43 CEST 2010


Author: iacus
Date: 2010-06-28 10:45:43 +0200 (Mon, 28 Jun 2010)
New Revision: 84

Modified:
   pkg/yuima/DESCRIPTION
   pkg/yuima/R/adaBayes.R
   pkg/yuima/R/subsampling.R
   pkg/yuima/R/yuima.sampling.R
   pkg/yuima/man/adaBayes.Rd
   pkg/yuima/man/subsampling.Rd
Log:
meielisalp commit

Modified: pkg/yuima/DESCRIPTION
===================================================================
--- pkg/yuima/DESCRIPTION	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/DESCRIPTION	2010-06-28 08:45:43 UTC (rev 84)
@@ -1,10 +1,10 @@
 Package: yuima
 Type: Package
 Title: The YUIMA Project package (unstable version)
-Version: 0.0.89
-Date: 2010-06-25
+Version: 0.0.90
+Date: 2010-06-28
 Depends: methods, zoo, stats4
-Suggests: adapt
+Suggests: adapt, mvtnorm
 Author: YUIMA Project Team.
 Maintainer: Stefano M. Iacus <stefano.iacus at R-project.org>
 Description: The YUIMA Project for Simulation and Inference 

Modified: pkg/yuima/R/adaBayes.R
===================================================================
--- pkg/yuima/R/adaBayes.R	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/R/adaBayes.R	2010-06-28 08:45:43 UTC (rev 84)
@@ -385,16 +385,16 @@
 ##::example: 0 <= theta1 <= 1 theta1.lim = matrix(c(0,1),1,2)
 ##::if theta1, theta2 are matrix, theta.lim can be defined matrix like rbind(c(0,1),c(0,1))
 setGeneric("adaBayes",
-           function(yuima, print=FALSE, init, prior,propose,n.iter=100,lower,upper,n.burnin,method="nomcmc",mhtype="independent")
+           function(yuima, print=FALSE, start, prior,propose,n.iter=100,lower,upper,n.burnin,method="nomcmc",mhtype="independent")
            standardGeneric("adaBayes")
            )
 setMethod("adaBayes", "yuima",
-          function(yuima, print=FALSE,  init, prior,propose,n.iter=100,lower,upper,n.burnin,method="nomcmc",mhtype="independent"){
+          function(yuima, print=FALSE,  start, prior,propose,n.iter=100,lower,upper,n.burnin,method="nomcmc",mhtype="independent"){
             if( missing(yuima)){
               cat("\nyuima object is missing.\n")
               return(NULL)
             }
-			            
+			            init <- start
 			  if(length(match(yuima at model@parameter at drift ,names(init),nomatch=0))!=length(yuima at model@parameter at drift)){
 				  cat("\ndrift parameters in yuima model and init do not match.\n")
 				  return(NULL)

Modified: pkg/yuima/R/subsampling.R
===================================================================
--- pkg/yuima/R/subsampling.R	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/R/subsampling.R	2010-06-28 08:45:43 UTC (rev 84)
@@ -7,38 +7,33 @@
 # returns sample of data using poisson sampling
 
 setGeneric("subsampling", 
-function(x, sampling=NULL, Initial, Terminal, delta, 
- grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
- sgrid=as.numeric(NULL), interpolation="pt") 
+function(x, sampling, ...) 
  standardGeneric("subsampling")
 )
 
 setMethod("subsampling","yuima", 
-function(x, sampling=NULL, Initial, Terminal, delta, 
- grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
-sgrid=as.numeric(NULL), interpolation="pt"){
- obj <- subsampling(x at data, sampling=sampling, Initial = Initial, 
-  Terminal = Terminal, delta = delta, 
-  grid = grid, random = random, sdelta=sdelta, 
-  sgrid=sgrid, interpolation=interpolation)
+function(x, sampling, ...){
+obj <- NULL
+	if(missing(sampling))
+		obj <- subsampling(x at data, setSampling(...))
+	 else
+		obj <- subsampling(x at data, sampling=sampling)
  obj at model <- x at model
  return(obj)
 }
 )
 
 setMethod("subsampling", "yuima.data",
-function(x, sampling=sampling, Initial, Terminal, delta, 
- grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
- sgrid=as.numeric(NULL), interpolation="pt"){
+function(x, sampling=sampling){
 
- tmpsamp <- NULL
- if(missing(sampling)){
-	tmpsamp <- setSampling(Initial = Initial, Terminal = Terminal, 
-				delta = delta, grid = grid, random = random, sdelta=sdelta, 
-				sgrid=sgrid, interpolation=interpolation)
- } else {
+#tmpsamp <- NULL
+#if(missing(sampling)){
+#	tmpsamp <- setSampling(Initial = Initial, Terminal = Terminal, 
+#				delta = delta, grid = grid, random = random, sdelta=sdelta, 
+#				sgrid=sgrid, interpolation=interpolation)
+#} else {
 	tmpsamp <- sampling
- }
+#}
 
  
  Data <- get.zoo.data(x)

Modified: pkg/yuima/R/yuima.sampling.R
===================================================================
--- pkg/yuima/R/yuima.sampling.R	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/R/yuima.sampling.R	2010-06-28 08:45:43 UTC (rev 84)
@@ -125,10 +125,8 @@
 setSampling <- function(Initial=0, Terminal=1, n=100, delta, 
  grid, random=FALSE, sdelta=as.numeric(NULL), 
  sgrid=as.numeric(NULL), interpolation="pt" ){
-  if(missing(delta))
-	delta <- NA
-  if(missing(grid))
-	 grid <- NULL
+  if(missing(delta))	delta <- NA
+  if(missing(grid))	 grid <- NULL
   return(new("yuima.sampling", Initial=Initial, Terminal=Terminal, 
 	n=n, delta=delta, grid=grid, random=random, 
 			 regular=TRUE, sdelta=sdelta, sgrid=sgrid,

Modified: pkg/yuima/man/adaBayes.Rd
===================================================================
--- pkg/yuima/man/adaBayes.Rd	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/man/adaBayes.Rd	2010-06-28 08:45:43 UTC (rev 84)
@@ -4,17 +4,21 @@
 \title{Adaptive Bayes estimator for the parameters in sde model}
 \description{Adaptive Bayes estimator for the parameters in a specific type of sde.}
 \usage{
-adaBayes( yuima , h , prior2 , prior1 , domain2 , domain1, theta2.offset=0,theta1.offset=0)
+adaBayes(yuima, print = FALSE, start, prior, propose, n.iter = 100, 
+    lower, upper, n.burnin, method = "nomcmc", mhtype = "independent")
 }
 \arguments{
   \item{yuima}{a 'yuima' object.}
-  \item{h}{ sampling interval [positive value].}
-  \item{prior2}{ prior distribution function of theta2 [function].}
-  \item{prior1}{ prior distribution function of theta1 [function].}
-  \item{domain2}{ domain of theta2 [vector or matrix].}
-  \item{domain1}{ domain of theta1 [vector or matrix].}
-  \item{theta2.offset}{ offset value of theta2 [scalar or vector].}
-  \item{theta1.offset}{ offset value of theta1 [scalar or vector].}
+  \item{prior}{ a list of prior distributions for the parameters [function].}
+  \item{start}{ initial suggestion for parameter values }
+  \item{propose}{ ... }
+  \item{print}{trace optimization?}
+  \item{method}{ \code{nomcmc} requires package \code{adapt} }
+  \item{mhtype}{ ... }
+  \item{n.burnin}{ ... }
+  \item{lower}{ ... }
+  \item{upper}{ ... }
+  \item{n.iter}{ ... }
 }
 \details{
   Calculate the values of the parameters theta1 and theta2. When the quasi-likelihood is too large for the given data, the integral in the Bayes estimator may diverges. For such a case, offset values for the parameters can be specified not to diverge.}
@@ -26,48 +30,36 @@
   This routine is not stable and accurate. Dr.Kamatani is now working for improvements.
 }
 \examples{
-  set.seed(1)
-  diff.matrix <- matrix(c("theta1"),1,1)
-  mod <- setModel(drift=c("(-1)*theta2*x"),diffusion=diff.matrix,time.variable="t",state.variable="x")
-  n <- 100
-  Terminal <- (n)^(1/3)
-  mod.sampling <- setSampling(Terminal=Terminal, n=n)
-  yuima.mod <- setYuima(model=mod, sampling=mod.sampling)
-  yuima.mod <- simulate(yuima.mod,
-               xinit=1,
-               true.parameter=list(theta1=0.6,theta2=0.3)
-               )
-  
-  ## TBC: sample the path later
+library(yuima)
+library(mnormt)
+set.seed(123)
 
-  domain <- c(0,1)
-  ## prior distribution of theta1
-  prior1 <- function(theta1,domain){
-    tmp <- 1/(domain[1,2] - domain[1,1])
-    return(tmp)
-  }
-  ## prior distribution of theta2
-  prior2 <- function(theta2,domain){
-    tmp <- 1/(domain[1,2]-domain[1,1])
-    return( tmp )
-  }
-  
-  rand <- matrix(runif(20,0,1),10,2) ## initial points for MLE
-  QL <- 0
-  param <- numeric(2)
-  for( i in 1:5){
-    PAR <-  ml.ql(yuima.mod,theta2=rand[i,1],theta1=rand[i,2],h=(n^(-2/3)))
-    if(PAR at min > QL){
-      QL <- PAR at min
-      param <- PAR at coef
-    }
-  }
-  BE <- adaBayes(yuima.mod,h=(n-1)^(-2/3),prior2=prior2,prior1=prior1,domain2=domain,domain1=domain,theta2.offset=param[1],theta1.offset=param[2])
-  print("True param")
-  print("theta2 = .6, theta1 = .3")
-  print("ML estimate")
-  PAR at coef
-  print("Bayes estimate")
-  BE
+ymodel <- setModel(drift="(-1)*theta2*x", diffusion="sqrt(theta1^2+1)",
+                   time.variable="t", state.variable="x", solve.variable="x")
+n <- 100#10^2
+h <- 1/((n)^(2/3))
+ysamp <- setSampling(Terminal=(n)^(1/3), n=n) 
+yuima <- setYuima(model=ymodel, sampling=ysamp)
+param.true <- list(theta2=0.3, theta1=0.5)
+yuima <- simulate(yuima, xinit=1, true.parameter=param.true)
+
+prior.theta1 <- function(theta2)
+  1*(theta2 > 0 & theta2 < 1)
+
+prior.theta2 <- function(theta1)
+  1*(theta1 > 0 & theta1 < 1)
+
+prior <- list(theta1=list(measure.type="density", density=prior.theta1,domain=c(-2,2)),
+theta2=list(measure.type="density", density=prior.theta2,domain=c(-2,2)))
+
+param.init <- list(theta2=0.35,theta1=0.52)
+
+lower = c(0,0)
+upper=c(1,1)
+
+bayes1 <- adaBayes(yuima, start=param.init, lower=lower,upper=upper,prior=prior, method="nomcmc")
+
+mle1 <- qmle(yuima, start=param.init, lower=lower, upper=upper, method="L-BFGS-B")
+mle1 at coef
 }
 \keyword{ts}

Modified: pkg/yuima/man/subsampling.Rd
===================================================================
--- pkg/yuima/man/subsampling.Rd	2010-06-25 14:23:25 UTC (rev 83)
+++ pkg/yuima/man/subsampling.Rd	2010-06-28 08:45:43 UTC (rev 84)
@@ -3,23 +3,13 @@
 \title{subsampling }
 \description{subsampling}
 \usage{
-subsampling(x, sampling=NULL, Initial, Terminal, delta, 
- grid = as.numeric(NULL), random = FALSE, sdelta=as.numeric(NULL), 
- sgrid=as.numeric(NULL), interpolation="pt") 
+subsampling(x, sampling, ...) 
 }
 \arguments{
   \item{x}{an \code{\link{yuima-class}} or 
     \code{\link{yuima.model-class}} object.}
   \item{sampling}{a \code{\link{yuima.sampling-class}} object.}
-  \item{Initial}{Initial time of the grid.}
-  \item{Terminal}{Terminal time of the grid.}
-  \item{delta}{mesh size in case of regular time grid.}
-  \item{grid}{a grid of times for the simulation, possibly empty.}
-  \item{random}{specify if it is random sampling. See Details.}
-  \item{sdelta}{mesh size in case of regular space grid.}
-  \item{sgrid}{a grid in space for the simulation, possibly empty.}
-  \item{interpolation}{a rule of interpolation in case of subsampling. 
-   By default, previous tick interpolation is used. See Details.}
+  \item{...}{used to create a sampling structure}
 }
 \value{
   \item{yuima}{a \code{yuima.data-class} object.}



More information about the Yuima-commits mailing list