[R] optimisation - Error in checkFunc(Func2, times, y, rho) : The number of derivatives returned by func() (22) must equal the length of the initial conditions vector (2)
Malgorzata Wieteska
g.wieteska at yahoo.ie
Tue Feb 21 12:03:53 CET 2017
Hello,
I get an error message:Error in checkFunc(Func2, times, y, rho) : The number of derivatives returned by func() (22) must equal the length of the initial conditions vector (2)
I try to optimise system of differential equations with 2 extra variables derived from the data.frame.
I didn't manage to install XLConnect package, so I don't know if this is the source of the problem.
Loading required package: XLConnectWarning message:In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘XLConnect’
I have missing data, so time frame is limited. I haven't got values for solution of the first equation, but I hope that it isn't problem, I've got the same message when putting random numbers as x values.
The code is as follow:time=c(16,17,18,19,20,21,22,23,24,25,26)
#x=c(20.2,18.9,16.5)y=c(7.63,9.22,4.86,4.78,0.38,6.13,3.91,38.41,2.58,36.95,1.73)
cE=c(15.05,38.01,41.09,31.41,3.54,15.92,24.01,25.29,14.82,43.93,2.45)cP=c(0.47,0.43,4.8,1.07,0.38,0.3,0.14,0.29,0.9,2.51,1.94)
#df<-data.frame(time,y,cE,cP)#dfrequire(FME)require(XLConnect)
#Initial values of the parametersparms=c(k1=500, k2=4500, k3=200,k4=2.42, k5=0.26,k6=12.2,k7=0.004,k8=55, k9=24,k10=8)
#definition of the parameters functionderivs<-function(time,y,pars){ with(as.list(c(pars,y)),{ cE=c(15.05,38.01,41.09,31.41,3.54,15.92,24.01,25.29,14.82,43.93,2.45) cP=c(0.47,0.43,4.8,1.07,0.38,0.3,0.14,0.29,0.9,2.51,1.94) dx=(k1+(k2*cE^k10)/(k3^k10+cE^k10))/(1+cP/k6)-k4*((1+k5*cP)/(1+k7*cE))*x; #dRP_LH/dt dy=(1/k8)*k4*((1+k5*cP)/(1+k7*cE))*x-k9*y #dL/dt list(c(dx,dy)) })}initial<-c(x=x[1],y=y[1])
model_cost<-function(pars){ out<-ode(y=initial,time=time,func=derivs,parms=pars) cost<-modCost(model=out,obs=df,x="time") return(cost) model_cost(parms)$model# model fitting model_fit<-modFit(f=model_cost,p=parms)}model_cost(parms)
Thank you in advance for any help.
PS, I've tried to put cE and cP as initial conditions or/and as parameters, but it didn't solve the problem.
[[alternative HTML version deleted]]
More information about the R-help
mailing list