[R-sig-dyn-mod] data fitting problem with FME package

Karline Soetaert Karline.Soetaert at nioz.nl
Wed Oct 23 10:24:12 CEST 2013


Himanshu,

You will have to pool them, for instance:

yobs1 <- data.frame(
 names= rep("Y",8),  time = 0:7, Y = runif(8),
 err = c(0.1, 0.11, 0.10, 0.120, 0.16, 0.145, 0.153, 0.16)
)

yobs2 <- data.frame(
 names= rep("Y",8),  time = 0:7, Y = runif(8),
 err = c(0.1, 0.11, 0.10, 0.120, 0.16, 0.145, 0.153, 0.16)
)

yobs3 <- data.frame(
 names= rep("Y",8), time = 0:7, Y = runif(8),
 err = c(0.1, 0.11, 0.10, 0.120, 0.16, 0.145, 0.153, 0.16)
)

# Here they are pooled...
yobs <- rbind(yobs1, yobs2, yobs3)


modCost(obs=yobs, model=out, y="Y", err="err")


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 Himanshu
Sent: dinsdag 22 oktober 2013 17:56
To: r-sig-dynamic-models at r-project.org
Subject: [R-sig-dyn-mod] data fitting problem with FME package

Dear list,


 I have some issue with the model fitting, I came across multiple observations problem and I am not sure how to fix this issue in FME package.

My problem here is, I have suppose 3 sets of observations, say "yobs_1", "yobs_2", "yobs_3", if I use the pseudo code below seperately for each observation, I will get 3 different parameters sets for the 3 different datasets. So my question is, is there any way where I can input all the three data sets together (except pooling them together) and find out a single parameters sets?



 Here is the pseudo code, I hope you understand my problem. Kindly let me know if there is some confusion.


 Thanks a lot in advance!


 library(deSolve)

library(FME)

 ## function derivs

 derivs <- function(time, y, pars) {

with (as.list(c(y, pars)), {

dy = a1 * Y * (1 - Y/Ymax) - a2 * (Y + 0.001)

dz = a3 * Y - a4 * Z;

return(list(c(dy, dz)))

})

}

 ## parameters

pars <- c(a1 = 0.9, a2 = 0.7, a3 = 0.06, a4 = 0.02)

Ymax <- c(0.8)

## initial values

y <- c(Y = 0.2, Z = 0.1)

## time steps

 times <- c(seq(0, 10, 0.1))

## numerical solution of ODE

 out <- ode(y = y, parms = pars, times = times, func = derivs)

 ## example observation data

yobs <- data.frame(

names= rep("Y",8),

time = 0:7,

Y = c(0.2, 0.195, 1.19, 2.487, 1.185, 0.683, 0.182, 0.018),

err = c(0.1, 0.11, 0.10, 0.120, 0.16, 0.145, 0.153, 0.16)

)

  ## model cost function, see help file and vignette for details

modelCost <- function(p) {

out <- ode(y = y, func = derivs, parms = p, times = yobs$time)

return(modCost(obs=yobs, model=out, y="y", err="err"))

}

 ## start values for the parameters

startpars <- c(a1 = 1, a2 = 0.6, a3 = 0.1, a4 = 0.1)

 low<-c(a1 =0.1, a2 = 0.1, a3 = 0.01, a4 = 0.01)

up<-c(a1 = 3.0, a2 = 2.6, a3 = 2.1, a4 = 2.1)

## fit the model; nprint = 1 shows intermediate results

fit <- modFit(f = modelCost, p = startpars,lower=low, upper=up, control = list(nprint = 1))

--
With Regards:

Himanshu Manchanda  M.Sc.
Doctorate Student,
Leibniz Institute for Natural Product Research and Infection Biology e.V.
Hans-Knöll-Institute (HKI)
FSU, Jena
Germany
Contact: +49-160-96444678
              +49-176 56526087
email: bioinfo.himanshu at gmail.com

P.S: All good things come to those who wait..!!

	[[alternative HTML version deleted]]



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