[R-sig-dyn-mod] parameter estimation with simecol FitOdeModel function when using lapply function with an odeModel?

Thomas Petzoldt Thomas.Petzoldt at TU-Dresden.de
Tue Oct 20 02:36:54 CEST 2009


Hi Zachary,

thank you for opening the discussion on this new mailing list --
congratulations! On the other hand, however, your mail consists of
several questions (some of them quite specific), so please don't expect
comprehensive answers or a fully functional code.

In general, it helps if you ask one question after another, together
with *minimal* and *reproducible* examples that isolate the problem.

The following short notes may help you to proceed step by step.

Thompson, Zachary wrote:
> Hello, I am having a difficult time trying to understand what I need
> to do to include parameter estimation in my program.
> 
> I am trying to use the fitOdeModel function from the simecol package.
> 
> 
> Currently my output is a list of data frames because I use an lapply
> function call on the data and the odemodel.
> 
> Some advise I was given was to make my model and the lapply function
> together into an object with the class "simObj", without the
> out(sim()) call, is this possible? Then I could use that in the
> FitOdeModel function.

This is a rather specific idea, but yes, it is possible to create
something like a compound model object that consists of a series of
scenarios. However, I would not recommend this for your problem.

> Are there any suggestions about how to link my model through the
> lapply function to the parameter estimation function FitOdeModel?

In principle yes, a "compound object", but I think it is much easier to
use optim directly or the optimization routines from the FME package.

> I know the observer slot "generally" does not work with Odemodels but
> is there a way to use it in my case please see code below.

No, the "observer" slot is intended for something totally different.

> Can I hold all the results until all the lapply function uses all the
> input columns, and then return the data in a data frame? If I would
> try this I suppose I would have to put these statements into the
> function that my lapply function calls and not the odemodel???

In principle yes. Then use standard optimizers (or FME routines as
described in the FME vignette) to fit the parameters.

You can convert the list of lists returned by lapply:

outsim <- lapply(x.all[c(2,17)], f2test)

with:

do.call(rbind, lapply(outsim, data.frame))

to a unique data frame.

> Is it possible to put the apply function into the MAIN function of my
> odeModel and change the input to the complete dosing data set? This
> way I could simply insert the odeModel into the FitOdeModel
> function???

This is not appropriate here. The main function in class odeModel is the
derivative of the ODE, and not intended to hold a series of different 
scenarios.

My suggestion, make it simple:

1) put the "lapply" as it is in a function that returns a data frame, 
matrix or even a vector of data corresponding to the structure of your 
measured data (see above).

2) write a second function "cost" that returns a goodness of fit 
criterion, e.g. sum of squares between simulation and data (or use 
modCost from FME).

3) use optim or nlminb (or the FME package) to fit your parameters by 
using this cost function.

Sometimes it may help to start with a toy example before working with 
your full model and data set.

Thomas P.



More information about the R-sig-dynamic-models mailing list