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.