I'm trying to fit a logistic function to some data points. Each data "set" has 6 points that I'm trying to fit a seperate logistic function to.
Here is some sample code:
x = c(60, 80, 100, 140, 160, 180)
y = c(24.0688, 26.3774, 25.1653, 15.7559, 12.4160, 15.5849)
df = data.frame(x=x, y=y)
nls(y ~ SSlogis(x, 25, 110, 100), df)
But I get this error:
Error in nlsModel(formula, mf, start, wts) :
singular gradient matrix at initial parameter estimates
I'm not sure how I should be setting the Asym, xmid, scal parameters. I tried doing a call to nls with my own parameterized formulation of the logistic function but I get the same error. I thought it was the small number of data points, but I tried combining some of the data and I get the same error.
So my questions are:
- Is it possible to fit a logistic to this few points?
- Is the nls function the right way to go, or should I be using a different approach?
- How do I set the initial Asym, xmid, and scal parameters?
Thanks!
Best Answer
You are not using the
SSlogis
function correctly: it needs some parameters, and it will calculate the starting values by itself (that's why it isSS
, i.e. self-start):