[R-sig-dyn-mod] Help to fit a dynamic model - irregular time
Bernardo Rangel Tura
tura at centroin.com.br
Thu Dec 10 09:38:21 CET 2009
On Wed, 2009-12-09 at 11:11 +0100, Soetaert, Karline wrote:
> 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
>
Karline,
I don't think your answer is vague! Your answer is very usefull.
Tank you!
I will look de package deSolve ...
--
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil
More information about the R-sig-dynamic-models
mailing list