I'm running a for loop to do bulk nonlinear regression. The problem is, some columns end up causing an error because there aren't enough iterations.
Error in nls(y ~ cbind(1, 1/(1 + exp((xmid - x)/exp(lscal)))), data = xy, :
number of iterations exceeded maximum of 50
I tried changing the number of iterations (the following) but it still gives me the same error. I'm not sure what to do. Either I need it to flag the columns that don't run or to iterate until it converges. The strange thing is that for all the ones that run, they take only 1 iteration so I don't understand how this can go over 50?
for(i in 1:(ncol(df))) {jpeg(paste((i), ".jpg"), height = 5, width = 6, units = "in", res = 300)
plot(time,
df[[i]],
xlab = "time (hours)",
ylab = "fluorescence (rfu)",
xlim=c(0, 92), ylim=c(0, 150000),
pch = 20,
col = "grey65",
main=colnames(df[i]))
N$i <- nlsLM(df[[i]]~SSfpl(time, a, b, c, d), control=nls.lm.control(maxiter=100, nprint = 1))
lines(time, predict(N$i), col = "black")
dev.off()
}
Any help would be greatly appreciated!