[R] State space modelling

Michael Camann camann at babylon.cnrs.humboldt.edu
Fri Sep 7 20:07:48 CEST 2001


I did a lot of state-space simulation modeling using S-plus in my
dissertation work some years ago.  One of the primary lessons I learned
was that S (and R) is great for "wrapping" the simulation engine, but not
particulary good for coding the simulations themselves, largely due to
memory and speed issues.  This is especially true for large simulations
and/or lots of time steps.

What worked for me was a combination approach with the actual simulation
coded in C with an R wrapper (I used S but I'll write R here for clarity).
I dynamically linked the C simulation to the R wrapper so that I could
simply pass empty data structures (the model compartments) from R to C,
the C simulation code filled them with time-stepped values, and then
returned them to the R wrapper for analyses, display, etc.  The really
cool part was that I could use a simple shell script to write input
parameters to a file, then call the R code via the command line interface,
and thus let the system cook through HUGE explorations of state-space
while I was out enjoying the University night life.  Nowadays, if I did it
again, I'd probably not pass whole data structures to the simulation
engine, but rather just the input parameters, then I'd write the results
to output files for R to suck back in when the simulation completed-- of
course, that'll only work if you don't need simultaneous
display/interaction with the simulation while it runs.

Doing it the way I did it was a bit of a pain initially-- at least at the
time all of the variable references in the C code had to be pointer refs
and pointer arithmatic-- I assume that's still the case.  The alternative
approach I mentioned above would ease the pain somewhat by largely
eliminating the pointer arithmatic (which was only really a problem when
debugging). All in all, R is supurb for the wrapper functions because of
it's extensive graphical and analysis capabilities.

Best of luck!
--Mike C.

Michael A. Camann                                  Voice: 707-826-3676
Associate Professor of Zoology                       Fax: 707-826-3201
Institute for Forest Canopy Research     Email: mac24 at axe.humboldt.edu
Department of Biology                            ifcr at axe.humboldt.edu
Humboldt State University           
Arcata, CA 95521


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list