Comments (4)
Use spy
to view the C file you've created with your C snippets. By default, this is stored in the temporary directory. You can change this using the cdir
and cfile
options.
Most people find it easiest to work with C snippets, but you can certainly link to a library of your own. See
FAQ 3.7. The C API for pomp is described here. In particular, if you furnish your own basic model components, they must conform to the prototypes for such functions.
I am not sure what you have in mind by "a long external data stream". Are you envisioning that rprocess should depend on covariates? If so, does the existing facility for covariates solve the problem?
More generally, you can do almost anything you want in the C snippets, as long as they are valid C. That doesn't mean that the resulting calculation will be correct, or even meaningful, of course!
from pomp.
Thanks for the answers. Does that mean the declarations void pomp_*
should always stay the same?
The covariates facility is what I need. But I'm having issues running simulations. Below is my test pomp model:
#### daily integrated pomp model ####
library(pomp)
library(dplyr)
library(ggplot2)
dat <- data.frame(
daynum = c(1:3652),
dat = rbinom(3652,size = 10, prob = 0.3) + c(1:3652)* 0.1 - 0.3
)
covar <- data.frame(
daynum = dat$daynum,
step = 1.1
)
### initial condition ###
step_rinit <- Csnippet("
x = 0;
y = 0;
")
### process model ###
## stochastic version ##
step_rproc <- Csnippet("
double dx = 0.1;
double dy = -0.1;
dx = dx + step * s;
dy = dy + 0.5 * step * s;
y = y + dx + dy;
x = x + dx + dy;
")
### measure model ###
step_dmeas <- Csnippet("
lik = dbinom(dat, y, rho, give_log);
")
step_rmeas <- Csnippet("
dat = rbinom(y, rho);
")
##### plug in pomp ####
test_pomp <-
pomp(data = dat,
times = 'daynum',
t0 = 1,
rinit = step_rinit,
rprocess = euler(step_rproc,delta.t = 1),
rmeasure = step_rmeas,
dmeasure = step_dmeas,
covar = covariate_table(covar$step,times = covar$daynum),
covarnames = 'step',
obsnames = 'dat',
statenames = c('x','y'),
paramnames = c('s','rho'),
cdir = 'c')
test_pomp |>
simulate(nsim = 20,
params = c(s = 0.2,rho = 1),
covar = covariate_table(covar$step,times = covar$daynum),
covarnames = 'step',
format = 'data.frame') |>
ggplot() +
geom_line(aes(x = daynum, y = y,color = .id))
The model just tests if the process model can be affected by the covariates. There are no issues building the pomp model, but error appeared in simulate
as "Error: in ‘simulate’: variable 'step' not found among the covariates." . Can you please tell me what happened?
from pomp.
Cf. the following, in particular, the call to covariate_table
. Note there is no need to reinsert covar
in the call to simulate.
##### plug in pomp ####
dat |>
pomp(
times = "daynum",
t0 = 1,
rinit = step_rinit,
rprocess = euler(step_rproc,delta.t = 1),
rmeasure = step_rmeas,
dmeasure = step_dmeas,
covar = covariate_table(covar,times="daynum"),
statenames = c("x","y"),
paramnames = c("s","rho"),
cdir = "c"
) -> test_pomp
test_pomp |>
simulate(
nsim = 20,
params = c(s = 0.2,rho = 1),
format = "data.frame"
) |>
ggplot(aes(x = daynum, y = y, color = .id)) +
geom_line()
While I think the above addresses your immediate question, and I take it that you've cobbled this up for purely illustrative purposes, I do point out that it makes little sense to include step
as a covariate, since it is constant and could more properly be included as a parameter.
from pomp.
Thank you so much for the prompt answer! Yes, this model is oversimplified to test the code implementation and to visually check the effect of the simple covariate. Thanks again for all the guidance. My issue is resolved and I will close it now.
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
- 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.