Comments (2)
Furthermore, former when I used the following parameterization, it works
sir<-pomp(data=data.frame(cases=data,time=seq(1,14,by=1)),
times="time",t0=0,
dmeasure=Csnippet(dmeas),
rmeasure=Csnippet(rmeas),
rprocess=euler.sim(
step.fun=Csnippet(sir.step),delta.t=1/14/2),
statenames=c("S","I","R"),
paramnames=c("popsize","bet","mu","rho","S.0","I.0","R.0","theta"),
initializer=function(params,t0,...){
fracs<-params[c("S.0","I.0","R.0")]
return(setNames(c(round(params["popsize"]*fracs/sum(fracs))),c("S","I","R")))
setNames(c(round(params["popsize"]*fracs/sum(fracs))),c("S","I","R"))
},
params=c(popsize=763,theta=100,bet=2,mu=0.5,rho=3,S.0=757,I.0=3,R.0=3))
however, after I changed the parameterization to above, it doesn't work. Where is the problem?
from pomp.
The error message tells me that initializer
is supposed to return a named numeric vector. Does it?
sir <- pomp(data=data.frame(cases=NA,time=seq(1,14,by=1)),
times="time",t0=0,dmeasure=Csnippet(dmeas),
rmeasure=Csnippet(rmeas),
rprocess=euler.sim(
step.fun=Csnippet(sir.step),delta.t=1/14/2),
statenames=c("S","I","R"),
paramnames=c("popsize","bet","mu","rho","theta1","theta2","theta"),
initializer=function(params,t0,...){
ps<-exp(params["theta1"])/(1+exp(params["theta1"])+exp(params["theta2"]))
pi<-1/(1+exp(params["theta1"])+exp(params["theta2"]))
pr<-exp(params["theta2"])/(1+exp(params["theta1"])+exp(params["theta2"]))
x <- setNames(rmultinom(1,params["popsize"],prob=c(ps,pi,pr)),
c("S","I","R"))
print(class(x))
x
},
params=c(popsize=763,theta=100,bet=2,mu=0.5,rho=3,theta1=5,theta2=1)
)
sir<-simulate(sir,seed = 73691676L)
Which gives:
[1] "matrix"
Error: in ‘simulate’: in 'init.state': user 'initializer' must return a named numeric vector
So, it appears that rmultinom
returns a matrix, not a vector. See ?rmultinom
to confirm this. If I do instead
sir <- pomp(data=data.frame(cases=NA,time=seq(1,14,by=1)),
times="time",t0=0,
dmeasure=Csnippet(dmeas),
rmeasure=Csnippet(rmeas),
rprocess=euler.sim(
step.fun=Csnippet(sir.step),delta.t=1/14/2),
statenames=c("S","I","R"),
paramnames=c("popsize","bet","mu","rho","theta1","theta2","theta"),
initializer=function(params,t0,...){
ps<-exp(params["theta1"])/(1+exp(params["theta1"])+exp(params["theta2"]))
pi<-1/(1+exp(params["theta1"])+exp(params["theta2"]))
pr<-exp(params["theta2"])/(1+exp(params["theta1"])+exp(params["theta2"]))
setNames(as.numeric(
rmultinom(1,params["popsize"],prob=c(ps,pi,pr))),
c("S","I","R"))
},
params=c(popsize=763,theta=100,bet=2,mu=0.5,rho=3,theta1=5,theta2=1)
)
sir<-simulate(sir,seed = 73691676L)
all is well.
In your second snippet of code above, note that your second setNames(...)
call goes unevaluated due to the previous return
call. Also note that this returns a named numeric vector, hence the success where the previous codes failed.
Hope this helps.
from pomp.
Related Issues (20)
- looking for more information on `bsmc2()` HOT 1
- Trajectory Fitting issue HOT 9
- Error I'm getting for pfilter function HOT 2
- Error: in ‘bsmc2’: ‘dmeasure’ with log=TRUE returns illegal value HOT 4
- Global Search failing bc of one particle HOT 2
- Measurement model for multi-observed variables/states HOT 12
- How to simulate the time-varying parameter model by pomp package? HOT 14
- encounter problems when conducting trajectory fitting HOT 15
- MIF unable to fit to the data HOT 7
- Can we fit the time-series with the weighted likelihood? HOT 3
- Implementing a time delay in pomp HOT 1
- Using R's internal sample function in CSnippet HOT 7
- feel confused when choosing the best fitted model with loglik HOT 1
- An error associated with the installation and C snippets HOT 4
- Can I access the files related to Csnippet and directly edit? HOT 4
- I can't resolve this error when trying to run pomp HOT 4
- Error in adapting old syntax (traj.match) to the new one(traj_objfun) HOT 8
- Pseudo-likelihood combining iterated filtering and probe matching HOT 4
- How to estimate parameters of SIR model HOT 2
- How to add the exp(cubic spline) function to the deterministic model? HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pomp.