在R - 误差中拟合具有非线性混合效应模型(nlme)的ODE

时间:2017-07-07 08:49:32

标签: r random mixed-models nlme

我尝试使用混合效果拟合ODE模型(两个方程式到两个变量),因为“复制”'每个时间点实际上来自不同的患者,这意味着我们将它们组合起来构建一个时间序列。 (下面带注释的代码)

我收到此错误:

    Error in chol.default((value + t(value))/2) : the leading minor of order 1 is not positive definite

我已经尝试过装入一个参数(并修复其余参数)并得到相同的错误,因此它不会过度拟合。有想法该怎么解决这个吗?非常感谢

    library(nlmeODE)
    library(lattice)

    TwoComp <- list(DiffEq=list(
      dy1dt = ~ r*y1 - g*y1 , #infected cell type 1
      dy2dt = ~ g*y1 - h*y2), #infected cell type 2
      ObsEq=list(
        c1 = ~ y1,
        c2 = ~ 0),
      States=c("y1","y2"),
      Parms=c("r","g","h"),
      Init=list(10, 1))

    #make dataset:
    x1<-c(rep(7,8),rep(14,20),rep(21,2)) #days
    var<-c(rep(1,4),rep(2,4),rep(1,10),rep(2,10),1,2) #var = 1 fit to y1 and var =2 => fit to y2
    repl<-c(rep(c(1,2,3,4),2),rep(seq(1,10),2),1,2) #rep = replicates from different patients, 
    #i.e. combining multiple patients' data to infer one timeseries of the infection
    #measurements (cell counts):
    ys<-c(31, 22, 32, 36, 51, 52, 42, 54, 46, 41, 43, 46, 44, 37, 38, 43, 42, 38, 120, 82, 50, 71, 85, 48, 34, 69, 76, 55, 47, 128)
    dataBS1 <-as.data.frame(list(Time=x1,Var=var,reps=repl,Conc=ys))

    SimData <- groupedData( Conc ~ Time | Var,
                    data = dataBS1,
                    labels = list( x = "Time", y = "Counts"),
                    units = list(x="(days)")) 

    plot(SimData, aspect=1/1) 

    testModel <- nlmeODE(TwoComp,SimData)

    #fitting:
    fit0 <- nlme(Conc ~ testModel(r, g, h, Time, Var),
         data = SimData,
         fixed =  r+g+h ~ 1 , #none are fixed (not sure I entered that correctly)
         random = Time~1 |reps, #replicates are random effects (i.e. come from different patients)
         #also tried random = reps ~ 1 (gives same error)
         start=c(r=0.5, g=0.08, h=0.04),
         control=list(msVerbose=TRUE),
         verbose=TRUE)

    summary(fit0)
    #Error given: Error in chol.default((value + t(value))/2) : the leading   minor of order 1 is not positive definite

    plot(augPred(fit0,level=0:1)) 

0 个答案:

没有答案
相关问题