[R-sig-dyn-mod] Help to fit a dynamic model - irregular time

Soetaert, Karline K.Soetaert at nioo.knaw.nl
Wed Dec 9 11:11:59 CET 2009


Bernardo,

You question is quite vague, so my answer will be quite vague also.  

Fitting a dynamic model in R, and using unevenly spaced times in R is
not a problem. This is what you have to do:

1.	You make a model function, call it "func", put the parameters in
a vector called "parms", put the initial values in a vector called "y" 

2.	You solve this model, using e.g. function ode from package
deSolve. See help files in deSolve or the package vignette.
You request a solution only at the points of observation, for instance
something like this:

  times <- c(0.16, 0.25 )   # the output times
  out <- as.data.frame(ode(func = func, times =Times , parms =parms, y=
y))    # solves the model


3.	You make a "cost" function that:
	a. has as input argument(s) the parameter(s) to be fitted, 
 	b. puts these parameters in "parms"
	c. solves the model, as outlined in (2), and 
	d. that returns the sum of squared residuals. 

For instance, if your model variable is called "Y", and the data are in
"data$Y", then your cost function should return:
sum((out$Y - data$Y)^2)

4.	You use one of R's optimization algorithms, e.g. optim to fit
the model to the data. See help of the optimization function.

Hope this helps,

karline

-----Original Message-----
From: r-sig-dynamic-models-bounces at r-project.org
[mailto:r-sig-dynamic-models-bounces at r-project.org] On Behalf Of
Bernardo Rangel Tura
Sent: Wednesday, December 09, 2009 9:50 AM
To: Special Interest Group for Dynamic Simulation Models in R
Subject: Re: [R-sig-dyn-mod] Help to fit a dynamic model - irregular
time

On Wed, 2009-12-09 at 06:46 -0200, Bernardo Rangel Tura wrote:

Sorry malformation
> 
> time  rate
> 0.16  0.09
> 0.25  0.23
> 0.38  0.28


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

_______________________________________________
R-sig-dynamic-models mailing list
R-sig-dynamic-models at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models



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