0

I am trying to fit a non linear model to a data-set that has two different treatment groups.

values <- runif(20,1000,10000)
timefornls <- rep(c(0:9), 2)
treatment <- rep(c("group1", "group2"), each=10, len=20)
datafornls <- data.frame(timefornls,treatment,values)

datafornls represents the data-set that I am trying to fit, reasonably well. I am using formula: X0 + p * t * exp(q*t), where t = time and X0, p and q are unknown parameters that I am trying to estimate. Parameters p and q differ between two groups while, X0 stays same between them.

datafit.m1 <- nls(values ~ X0 + p[treatment] * timefornls * exp(q[treatment] * timefornls), data = datafornls, start = list(q=c(0.05,0.05), p=c(1000,1000), X0=1000))

Since p an q depend on treatment, square brackets are used which suggests that p and q would each have 2 values for 2 treatments. With this code I am getting the error:

Error in numericDeriv(form[[3L]], names(ind), env) : 
Missing value or an infinity produced when evaluating the model

I am not able to understand what am I doing wrong? Thanks in advance if you could figure out the problem.

VitalSigns
  • 83
  • 2
  • 10
  • Use the gnls function from package nlme. – Roland Jan 12 '17 at 19:07
  • @Roland : but what's wrong with this? – VitalSigns Jan 12 '17 at 19:10
  • Your model is over-parameterized. If you add an arbitrary number to X0 and then subtract that number from each component of p then you get the same predictions so the parameters are not uniquely determined. Omit X0 from the model. – G. Grothendieck Jan 13 '17 at 07:03
  • The main problem is that your example data doesn't support the model at all. Create example data like this: `datafornls$values <- with(datafornls, 1000 + 1000 * as.integer(treatment) * timefornls * exp(0.05 * as.integer(treatment) * timefornls)) + rnorm(nrow(datafornls), sd = 500)` – Roland Jan 13 '17 at 07:28
  • @G.Grothendieck Are you sure? Because I'm not seeing that (and get a successful fit with the example data from my preceding comment). – Roland Jan 13 '17 at 07:42

0 Answers0