0

I am trying to perform non linear regression on my data using nls in R and several different models which I am comparing using AIC to determine the best fitting model.

As an example, I am fitting either a simple exponential equation (model 1):

Y ~ a * exp(b * X)

or an expoential equation with an intercept (model 2):

Y ~ a * exp(b * X)+c

It is clear that, if c=0, we have model 2 = model 1.

In my dataset, for the vast majority of variables, model 2 gives a higher AIC than model 1. This happens because NLS always tries to fit model 2 with c =/= 0.

Is there any way for me to make it so that NLS can set coefficients to 0 (the c coefficient in this case) if that generates the best fitting model?

That way, the number of models I would need to run would reduce significantly.

  • There is no such implicit constraint in nls. If the model with c has higher AIC that is because it is not sufficiently better than the one without c to warrant the extra parameter. If what you are asking is how to use the formula with c but fix c at 0 then just omit c from the starting values and set it globally: c <- 0 or add c=0 as an argument to nls. – G. Grothendieck May 05 '21 at 14:01
  • I agree with you. In some situations, the addition of the C parameter improves the fit, whereas in others it worsens the fit. If I could set a constraint so that C can be 0, I would only need to run model 2, instead of both models to see which one is the better fit, correct? – João Duarte May 05 '21 at 14:05
  • There is no such constraint. What you are claiming, viz. c cannot be 0, is simply false. – G. Grothendieck May 05 '21 at 14:08
  • I understand that there is no such constraint by default but, just to be clear, is there no way to include that constraint? – João Duarte May 05 '21 at 14:12
  • If you use the port algorithm of nls then you can specify a lower bound. See ?nls – G. Grothendieck May 05 '21 at 14:15
  • but the default possibility for parameters is -inf to +inf by default using any algorithm, which means that NLS could have picked 0 as a value for parameter C in model 2, but chooses not to. Since model 1 gives a lower AIC than model 2, clearly, having C=0 gives a better fit but again, NLS does not pick this option. It seems to me there is a inbuilt constraint that any coefficient =/= 0. Setting a boundary for a coefficient would not remove this constraint, correct? – João Duarte May 05 '21 at 14:24
  • A lower AIC means that it has a better fit for the number of parameters used, not that it has a better fit. – G. Grothendieck May 05 '21 at 14:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/231980/discussion-between-joao-duarte-and-g-grothendieck). – João Duarte May 05 '21 at 14:29

0 Answers0