Solved – How to calculate 95% confidence interval for non-linear equation

confidence intervalnonlinear regression

I have an equation to predict the weight of manatees from their age, in days (dias, in portuguese):

R <- function(a, b, c, dias) c + a*(1 - exp(-b*dias))

I have modelled it in R, using nls(), and got this graphic:

enter image description here

Now I want to calculate the 95% confidence interval and plot it in the graphic. I've used the lower and higher limits for each variable a, b and c, like this:

lower a = a - 1.96*(standard error of a)
higher a = a + 1.96*(standard error of a)
(the same for b and c)

then I plot a lower line using lower a,b,c and a higher line using higher a,b,c. But I'm not sure if that's the right way to do it. It is giving me this graphic:

enter image description here

Is this the way to do it, or am I doing it wrong?

Best Answer

  1. This QA on this site explains the math to create confidence bands around curves generated by nonlinear regression: Shape of confidence and prediction intervals for nonlinear regression

  2. If you read further, it will help to distinguish confidence intervals for the parameters from confidence bands for the curve.

  3. Looking at your graph, it sure looks like you have data from four animals, measuring each on many days. If so, fitting all the data at once violates one of the assumptions of regression -- that each data point be independent (or that each residual has independent "error"). You might consider fitting each animal's tracing individually, or use a mixed model to fit them all at once.