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

I can't resolve this error when trying to run pomp #194

Closed LBJlove1 closed 1 year ago

LBJlove1 commented 1 year ago
library(doParallel)
library(doRNG)
registerDoParallel()
registerDoRNG(2488820)
library(pomp)
library(readxl)

library(tidyverse)
covid<-read_xlsx("C:/Users/1/Desktop/covid_data1.xlsx")

covid %>% 
  ggplot(aes(x=time,y=reports))+
  geom_line()+
  geom_point()

seir_step <- Csnippet("

    double beta;
    double sigma;
    double gamma;
    double betain;
    double betafi;

    if (t<3)
    beta = betain;
    if (t>=3 && t<12)
    beta = betain+(t-3)*(betafi-betain)/9;
    if (t>=12)
    beta = betafi;

    double SE = rbinom(S,1-exp(-beta*I/N*dt));
    double EI = rbinom(E,1-exp(-sigma*dt));
    double IR = rbinom(I,1-exp(-gamma*dt));
    S -= SE;
    E += SE - EI;
    I += EI - IR;
    R += IR;
                      ")

seir_init <- Csnippet("
  S = N-1;
  E = 0;
  I = 1;
  R = 0;
")

sir_dmeas <- Csnippet("
  lik = dnbinom_mu(reports,k,rho*I,give_log);
  ")

sir_rmeas <- Csnippet("
  reports = rnbinom_mu(k,rho*I);
  ")

covid %>%
pomp(
  times="time",t0=0,
  rprocess=euler(seir_step,delta.t=1),
  rinit=seir_init,
  rmeasure=sir_rmeas,
  dmeasure=sir_dmeas,
  paramnames=c("N","sigma","gamma","betain","betafi","rho","k"),
  statenames=c("S","E","I","R")
) -> covidSEIR

Error: error in building shared-object library from C snippets: in ‘Cbuilder’: compilation error: cannot compile shared-object library ‘C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.dll’: status = 1
compiler messages:
gcc  -I"D:/R-42~1.2/include" -DNDEBUG     -I"D:/rtools42/x86_64-w64-mingw32.static.posix/include"     -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mstackrealign  -c C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.c -o C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.o
C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.c: In function '__pomp_stepfn':
C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.c:48:17: error: '__p' redeclared as different kind of symbol
   48 | #define sigma  (__p[__parindex[1]])
      |                 ^~~
C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fd
In addition: Warning message:
In system2(command = R.home("bin/R"), args = c("CMD", "SHLIB", "-c",  :
  running command '"D:/R-4.2.2/bin/R" PKG_CPPFLAGS="-I"D:/R-4.2.2/library/pomp/include" -I"C:/Users/1/Documents"" CMD SHLIB -c -o C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.dll C:/Users/1/AppData/Local/Temp/RtmpojNoXL/2072/pomp_e54be27a8bb3fdb0ace0595aa6071f7c.c' had status 1
kingaa commented 1 year ago

Your variable sigma is declared both as a parameter (via paramnames) and a local variable (the double declaration in your C snippet). It can't be both. Notice that your error message calls your attention to this.

Looks like you want to remove all the local variable declarations in your rprocess C snippet.

P.S. If more help is needed, please provide codes that I can run. You have a data file there that I would need. If you don't want to share the actual data, provide some fake data in the same format.

LBJlove1 commented 1 year ago

Thank you very much for your reply, the above problem has been solved, my data file is as follows:

time: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 reports: 1 10 23 45 70 148 155 58 178 340 297 741 521 512 520 405 321 367 390 297 190 92 131 73 61 62 41 35 32 46 97 34 69 43 24 31 14 26 34 71 23 14 60

I want to construct a beta(t) that changes over time. I don't know if the construction of rprocess in the above code is correct, and I hope to get your advice.

kingaa commented 1 year ago

@LBJlove1: I am happy to help, but you might provide me with codes that run, rather than expect me to write them myself.

I am happy to help you, but generic requests for advice are not particularly efficient. I encourage you to formulate questions. In particular, whether code is correct or not depends on what it is intended to accomplish. At the moment, I have no idea what you are up to or what you expect the code to do.

You should also have a look at the FAQ.

kingaa commented 1 year ago

I am closing this issue for now. Feel free to reopen it if more discussion is warranted.