0

i have been trying to use the nlme package for differential equations and have struggled to get the code to work. I am aware there is an nlmeODE package but i was hoping to avoid using it. I was wondering if anyone knows of some example code combining nlme or nlmer with the desolve package?

So i've been able to solve the problem:

# My data takes the following form

ID DAYS DOSE BIO
1   0    0    8
1   0.1  1    NA
1   7    1    9
# time-series measurements of a biomarker (BIO) for a number of patients (ID)
# remember this is a dummy example

# My ODE a simple example 
simple<-function(t,x,parms) {
with(as.list(c(parms, x)), {
  dX <- kin 
  res <- c(dX)
  list(res)
})
}

# it's call within a function thats is passed to nlme
run_mod<-function(kin,r0,DOSE,DAYS){ 
out<-array(0,dim=c(1,length(kin)))
for (ii in 1:length(out)){
if (DAYS[ii]==0){
  out[ii]<-r0[ii]
}else{
  parms  <- c(kin=kin[ii], r0=r0[ii])
  xstart <- c(X=r0[ii])
  times<-c(0,DAYS[ii])
  vals<-lsoda(xstart, times, simple, parms)
  out[ii]<-as.numeric(vals[2,2])
}
}
return(out)
}

# finally my call to nlme
file2.grp<-groupedData(BIO~DAYS|ID,data=file2)
na.include <- function(x) x
fit<-nlme(BIO~run_mod(kin,r0,DOSE,DAYS), 
             fixed = kin+r0~1, random = pdDiag(kin+r0  ~1),
             data = file2.grp, start = c(7,0.01),method='ML',
             na.action=na.include, naPattern = ~ !is.na(BIO))
Jitendra
  • 1
  • 1
  • Can you show the code you've tried? – DanM7 Jan 14 '15 at 15:44
  • I have been able to solve the problem. It was related to what the output of the function was giving on the right hand-side of the ~ when specifying the formula. If people would like the code i can paste it in the original message. – Jitendra Jan 15 '15 at 17:04
  • 2
    if you've solved your problem, you are encouraged to post it as an answer. – Ben Bolker Jan 15 '15 at 17:07
  • I have pasted it above. I hope it is useful. It is not the most elegant of solutions but it has worked for me. – Jitendra Jan 15 '15 at 18:11

0 Answers0