Skip to content

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