Closed luismieryteran closed 4 years ago
Thanks @luismieryteran, for such a carefully prepared question. There were just a few small errors in your C code. See the following:
library(tidyverse)
library(pomp)
rmeas_C <- Csnippet("
int N = (int) stateSize;
const double *I = &I1;
double *Cases = &Cases1;
int d;
for (d = 0; d < N; d++){
Cases[d] = rnbinom(phi_car, phi_car / (phi_car + car * I[d]));
}")
simulate(
t0 = 0,
times = 1:nSteps,
statenames = c(sprintf("I%d",seq_len(stateSize)),
"cumsumI",
sprintf("E_Cases%d",seq_len(stateSize))),
obsnames = c(sprintf("Cases%d", seq_len(stateSize))),
paramnames = c("pop", "R0", "car", "phi_car", "I0", "stateSize"),
params = c(pop = pop, R0 = R0, car = car, phi_car = phi_car, I0 = I0,
stateSize = stateSize),
rinit = rinit_C,
rprocess = discrete_time(step.fun = rproc_C, delta.t = 1),
rmeasure = rmeas_C,
nsim = 100
) %>%
as.data.frame() -> sim
sim %>%
select(time,rep=.id,starts_with("Cases")) %>%
gather(var,cases,-time,-rep) %>%
group_by(time,var) %>%
summarize(
p=c(0.05,0.5,0.95),
q=quantile(cases,probs=p),
lab=c("lo","med","hi")
) %>%
ungroup() %>%
select(-p) %>%
spread(lab,q) %>%
ggplot(aes(x=time,y=med,ymin=lo,ymax=hi))+
geom_ribbon(fill=grey(0.8),color=NA)+
geom_line()+
guides(color=FALSE)+
facet_grid(var~.)
This runs for me and should for you. A couple of pointers:
;
is needed to end a line in C.const
declaration in C and cf. your error messages.Am closing this issue, but feel free to reopen if more discussion is warranted.
Hi there,
I am new to the pomp package and to C, potentially deadly combinations. I'm trying to set up a disease transmission model with an explicit serial interval in it. To force it to be Markovian, I truncate the serial interval at 5 days (for now) and make the state variable an array of length 5. Each step of the Markov process outputs the new 5 days worth of incidence given the previous 5 days, etc.
The model is here:
The error that results when trying to run the above is
and the output of source("https://kingaa.github.io/scripts/diagnostics.R") is
Perhaps you guys can help me see what is amiss? Really appreciate the help.