Hi, I'm new to R and am trying to implement a state-space model, and do some simulations looking at how well it works. Does anyone have an example I could use as a template? I'm having trouble working out where to start, and haven't been able to find anything similar in the help files or on the web. My example is a surplus production fisheries model, so something similar to that would be ideal. Thanks, Simon Simon Hoyle, Fisheries Modeller Southern Fisheries Centre, PO Box 76, Deception Bay, Q 4508, Australia (07) 3817 9541 (w) 3817 9555 (fax) 3269 0302 (h) hoyles at dpi.qld.gov.au / simon_hoyle at iname.com / sd.hoyle at student.qut.edu.au ********************************DISCLAIMER**************************** The information contained in the above e-mail message or messages (which includes any attachments) is confidential and may be legally privileged. It is intended only for the use of the person or entity to which it is addressed. If you are not the addressee any form of disclosure, copying, modification, distribution or any action taken or omitted in reliance on the information is unauthorised. Opinions contained in the message(s) do not necessarily reflect the opinions of the Queensland Government and its authorities. If you received this communication in error, please notify the sender immediately and delete it from your computer system network. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Simon--
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
URL:http://www.humboldt.edu/~mac24/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>Hi, I'm new to R and am trying to implement a state-space model, and dosome>simulations looking at how well it works.You might look at the dse package available on CRAN and the Users' Guide available at <http://www.bank-banque-canada.ca/pgilbert>. It does multivariate state-space and also ARMA modelling. The simulate method does simulation. There are also methods for monte-carlo experiments. Paul Gilbert -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi all, how do I enumerate models in R in an efficient way? Suppose I am interested in the fitted values of all linear models with at most four predictors. Can I use a loop 1:16 to do the equivalent of the following? m <- matrix(ncol=length(Y),nrow=16) m[1,] <- rep(mean(Y), length(Y)) # no predictor m[2,] <- lm(Y ~ X1)$fitted.values # one predictor m[3,] <- lm(Y ~ X2)$fitted.values m[4,] <- lm(Y ~ X3)$fitted.values m[5,] <- lm(Y ~ X4)$fitted.values m[6,] <- lm(Y ~ X1+X2)$fitted.values # two predictors m[7,] <- lm(Y ~ X1+X3)$fitted.values m[8,] <- lm(Y ~ X1+X4)$fitted.values m[9,] <- lm(Y ~ X2+X3)$fitted.values m[10,] <- lm(Y ~ X2+X4)$fitted.values m[11,] <- lm(Y ~ X3+X4)$fitted.values m[12,] <- lm(Y ~ X1+X2+X3)$fitted.values # three predictors m[13,] <- lm(Y ~ X1+X2+X4)$fitted.values m[14,] <- lm(Y ~ X1+X3+X4)$fitted.values m[15,] <- lm(Y ~ X2+X3+X4)$fitted.values m[16,] <- lm(Y ~ X1+X2+X3+X4)$fitted.values # four predictors -- Korbinian Strimmer http://users.ox.ac.uk/~strimmer Dept. of Zoology, University of Oxford, South Parks Road, Oxford OX1 3PS +44 1865 271272 (phone), -49 (fax), korbinian.strimmer at zoo.ox.ac.uk -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._