Skip to content
Prev 639 / 696 Next

[R-sig-dyn-mod] FME Fitting a multicompartmental model using the sum of several variables

Hi Jesus,
Thank you for your solution. It seems a good alternative to using the modCost function of FME, which does not seem to work if all variables are not included.


-----Mensaje original-----
De: R-sig-dynamic-models [mailto:r-sig-dynamic-models-bounces at r-project.org] En nombre de Jesus Maria Frias Celayeta
Enviado el: martes, 17 de septiembre de 2019 12:24
Para: Special Interest Group for Dynamic Simulation Models in R
Asunto: Re: [R-sig-dyn-mod] FME Fitting a multicompartmental model using the sum of several variables

Hi Juan,

Using the example from
https://www.r-bloggers.com/learning-r-parameter-fitting-for-models-involving-differential-equations/

you could include the sum in your ode system like:

rxnrate=function(t,c,parms){

 # rate constant passed through a list called parms
 k1=parms$k1
 k2=parms$k2

 # c is the concentration of species

 # derivatives dc/dt are computed below
 r=rep(0,length(c))
 r[1]=-k1*c["A"] #dcA/dt
 r[2]=k1*c["A"]-k2*c["B"] #dcB/dt
 r[3]=k2*c["B"] #dcC/dt
 r[4]= r[1]+r[2]+r[3] # sum of A,B,C

 # the computed derivatives are returned as a list  # order of derivatives needs to be the same as the order of species in c
 return(list(r))

}

all the best,

Jesus