kingaa / pomp

R package for statistical inference using partially observed Markov processes
https://kingaa.github.io/pomp
GNU General Public License v3.0
111 stars 27 forks source link

pomp debug #80

Closed minjuner closed 5 years ago

minjuner commented 5 years ago

I‘m newer to R,can R debug just like Python. For example,when i debug the pomp construct in the pomp package,it return a pomp object.Then i use the simulate function.and i step into it,but i didn't figure out how it works. image

kingaa commented 5 years ago

Debugging S4 methods is slightly more complicated than debugging ordinary R functions. Try

debug(simulate,signature="pomp")

or

debug(selectMethod("signature","pomp"))
kingaa commented 5 years ago

I'm closing this issue now, but feel free to re-open if needed.

LinyiGuo96 commented 5 years ago

Hi Aaron, I have one problem here: my code is

library(pomp)
# state function
gompertz.proc.sim <- function(x, t, params, delta.t, ...) {
   eps <- exp(rnorm(n = 1, mean = 0, sd = params["sigma"]))
   S <- exp(-params["r"] * delta.t)
   setNames(params["K"]^(1 - S) * x["X"]^S * eps, "X")
}
# obs
gompertz.meas.sim <- function(x, t, params, ...){
  setNames(rlnorm(n = 1, meanlog = log(x["X"]), sdlog = params["tau"]), "Y")
}
# density
gompertz.meas.dens <- function(y, x, t, params, log, ...) {
  dlnorm(x=y["Y"], meanlog = log(x["X"]), sdlog = params["tau"], log = log )
}
# build our 'pomp' object
gompertz <- pomp(data = data.frame(time = 1:100, Y = NA), times = "time", 
                 rprocess = discrete_time(step.fun = gompertz.proc.sim, delta.t = 1),
                 rmeasure = gompertz.meas.sim, t0 = 0
                 )
# assign values to params
theta <- c(r = 0.1, K = 1, sigma = 0.1, tau = 0.1, X.0 = 1) 
# simulate values for our obs
gompertz <- simulate(gompertz, params = theta )

then i got Error: in ‘simulate’: argument "params" is missing, with no default why did this happen?

LinyiGuo96 commented 5 years ago

@kingaa

kingaa commented 5 years ago

The basic model components (rprocess, rmeasure) that you've supplied are inappropriate for pomp versions >=2. See the upgrade guide for information on how to modify your old codes to work with the new version of pomp.