library(nlme) data(Soybean) xyplot(weight ~ Time, data = Soybean, subset = Plot == "1988F2") Soybean.1 <- Soybean[Soybean$Plot == "1988F1",] fit.nls <- nls(weight ~ Asym/(1 + exp((xmid - Time)/scal)), data = Soybean.1, start = c(Asym = 20, xmid = 60, scal = 10)) newdat <- data.frame(Time = seq(10, 90)) preds <- predict(fit.nls, newdata = newdat) xyplot(preds ~ Time, data = newdat, type='l', ylab = 'Weight', panel = function(x,y,...){ panel.xyplot(x,y,...) panel.xyplot(Soybean.1$Time, Soybean.1$weight, type = 'p') }) fit.nls2 <- nls(weight ~ SSlogis(Time, Asym, xmid, scal) , data = Soybean.1) ## Example of logistic function logis <- function(x, Asym , xmid, scal){ y <- Asym/(1 + exp((xmid - x)/scal)) y } x <- seq(0,35) y <- logis(x, 30, 15, 2) xyplot(y ~ x, type = 'l') pdf('../figs/logis.pdf') xyplot(y ~ x, type = 'l') dev.off()