# can't do non linear regression model

With this data frame:

``````DB <- data.frame(T = c(8, 16, 25, 25, 29, 29, 35),
Teq = c(0, 0.29, 0.63, 0.63, 0.77, 0.77, 1),
Rate = c(0, 0.27, 0.69, 0.75, 1, 0.97, 0))
``````

By running this code:
#nonlinearregression

``````> M4 <- nls(Rate~(a*Teq^b*(1-Teq))^c, data = Avg_speciesless, start = list(a = 50, b = 10, c = 0.2), algorithm = "port")
``````

This is the error I get

``````Error in numericDeriv(form[[3L]], names(ind), env, dir = -1 + 2 * (internalPars <  :
Missing value or an infinity produced when evaluating the model
``````

How to solve?
Thanks

Marta

you need to avoid infinities. so for example
a negative value of c when the bracket values evaluate to zero, which can happen when I suppose A is zero, but you set up to happen when Teq=1 as in the last row of your inputs.
similarly Teq =0 on the first row is a problem if b would be negative.

``````> 0^(-1)
[1] Inf
``````

So I think a reasonable thing to do, is set limits on at least b and c to be positive numbers. also it can help to allow more iterations for convergence to happen. consider this example

``````DB <- data.frame(T = c(8, 16, 25, 25, 29, 29, 35),
Teq = c(0, 0.29, 0.63, 0.63, 0.77, 0.77, 1),
Rate = c(0, 0.27, 0.69, 0.75, 1, 0.97, 0))

(M4 <- nls(Rate~(a*Teq^b*(1-Teq))^c,
data = DB, start = list(a = 50, b = 10, c = 0.2),
lower = list(-10^10,
10^-6,
10^-6),
upper = list(10^10,
10^6,
10^3),algorithm = "port",
control = nls.control(maxiter = 100L
)))
``````

results in :

``````Nonlinear regression model
model: Rate ~ (a * Teq^b * (1 - Teq))^c
data: DB
a         b         c
1.000e+10 8.882e+01 1.597e-02
residual sum-of-squares: 0.003637

Algorithm "port", convergence message: X-convergence (3)``````

The solution is given here, non linear regression.

@Marta95, it's better to avoid posting the same question twice.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.