I am working on nonlinear curve fitting in R and I cannot figure out how to constrain the data using the variables... Here is an example:
dat<-read.table(text="time y
1 4.62
2 13.55
3 30.82
6 93.97
12 145.93
24 179.93", header = TRUE)
plot(data);lines(data)
model <- nls(y ~ Max * (1-exp(-k * (time - Lag))),data=dat,start=list(Max = 200, k = 0.1, Lag = 0.5))
I would like to include if (time - Lag) < 0, then y = 0 but I cannot for the life of me figure out how to do it.