Skip to content
\n

I also used traj_func() to do a global search on likelihood, it returns NA most of the time and few valid numbers on discrete parameter combinations.

\n

Can you please tell me what might go wrong? Thank you so much!!

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

I notice that you round J in ili_nll_objfun, but not in traj_func. Notice that dbinom insists (correctly) on size being an integer:

\n
dbinom(50,size=c(100,100.1),prob=0.5)\n[1] 0.07958924        NaN\nWarning message:\nIn dbinom(50, size = c(100, 100.1), prob = 0.5) : NaNs produced\n
\n

The usual rounding function in C is nearbyint. Cf. the following:

\n
### measure model ###\ninc_dmeas <- Csnippet(\"\n  lik = dbinom(ili, nearbyint(J), rho, give_log);\n\")\n\n## build traj_func using simulated data ##\ndata.frame(\n  daynum = seq(from=3653,to=3653 + 3652)\n) |>\n  mutate(\n    ili = round(\n      rbinom(\n        n = length(daynum),\n        size = 120,\n        prob = 0.5 + rnorm(n=length(daynum),sd = 0.01)\n      ) +\n        2 * sin(2*pi/365*daynum)\n    )\n  ) |>\n  traj_objfun(\n    times = \"daynum\",\n    t0 = 1,\n    rinit = sirs_init,\n    skeleton = pomp::map(sirs_annual_beta_skeleton, delta.t = 1),\n    dmeasure = inc_dmeas,\n    accumvars = \"J\",\n    params = c(\n      beta = 0.2,seas = 0.02,\n      rho = 0.01,mu_R = 4/150,\n      mu_IR = 1/5,N = 1e7\n    ),\n    est = c(\"beta\",\"seas\",\"rho\",\"mu_R\"),\n    paramnames = c(\"beta\",\"seas\",\"mu_IR\",\"mu_R\",\"N\",\"rho\"),\n    statenames = c(\"S\",\"I\",\"R1\",\"R2\",\"R3\",\"R4\",\"J\")\n  ) -> traj_func\n\ntraj_func(c(beta = 0.2,seas = 0.02,mu_R = 4/150,rho = 0.01))\n[1] 14292.71\n
\n

I also notice that you have extraneous code in your example. Please reduce your examples to their essentials. Not only is this a courtesy to those you are asking for help, and to the readers of this discussion, but it may help you find the error yourself!

","upvoteCount":1,"url":"https://github.com/kingaa/pomp/discussions/190#discussioncomment-5469596"}}}

NA in traj_objfun() #190

Answered by kingaa
Fuhan-Yang asked this question in Q&A
Mar 29, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I notice that you round J in ili_nll_objfun, but not in traj_func. Notice that dbinom insists (correctly) on size being an integer:

dbinom(50,size=c(100,100.1),prob=0.5)
[1] 0.07958924        NaN
Warning message:
In dbinom(50, size = c(100, 100.1), prob = 0.5) : NaNs produced

The usual rounding function in C is nearbyint. Cf. the following:

### measure model ###
inc_dmeas <- Csnippet("
  lik = dbinom(ili, nearbyint(J), rho, give_log);
")

## build traj_func using simulated data ##
data.frame(
  daynum = seq(from=3653,to=3653 + 3652)
) |>
  mutate(
    ili = round(
      rbinom(
        n = length(daynum),
        size = 120,
        prob = 0.5 + rnorm(n=length(daynum),sd = 0.01)
      ) …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Fuhan-Yang
Comment options

Answer selected by Fuhan-Yang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants