# Can least squares be used to fit curves?

Can the method of least squares be used to fit growth curves like modified exponential or Gompertz curves?

• OLS can be used to fit anything. The answer depends on what you are going to do with the results. – Cagdas Ozgenc Jan 9 '17 at 8:46
• Yes, it can but not recommended. – SmallChess Jan 9 '17 at 11:29

## 1 Answer

I assume by modified exponential curve you mean something that could be written in the form $\lambda + A\exp(\beta x)$ (sometimes called a Makeham curve when looking at mortality, where it may refer to the hazard function)

Such nonlinear functions (specifically, nonlinear in parameters) can be fitted via nonlinear least squares, yes. (But see the caveat at the end)

Whether that's the right thing to do depends on your model for the observations; if you expect there to be constant-variance additive independent errors then nonlinear least squares makes sense.

(Gompertz curves are a special case of the above. If the standard deviation of the noise is approximately proportional to the mean, it would make some sense to take logs and use least squares on that scale.)

But such curves may also be fitted using other means than least squares (especially when related to mortality; then the response would involve counts or scaled counts or logs of scaled counts and specific distributional models for the counts may be used -- see the discussion in the latter part of this answer for example).

Here's a plot of some example data:

Here's the command to fit a nonlinear least squares model of the above form in R:

 makehamfit = nls(y ~ lambda + a * exp(b*x),start=list(lambda=1,a=.1,b=.5))


(other packages have similar commands)

Here's the estimates:

Nonlinear regression model
model: y ~ lambda + a * exp(b * x)
data: parent.frame()
lambda      a      b
5.0169 0.0139 0.1599
residual sum-of-squares: 0.1917

Number of iterations to convergence: 39
Achieved convergence tolerance: 1.836e-06


Here's what the fitted model looks like:

However, while your title only mentions "curves", you mention growth curves in the body of your post; if by "growth curve" you mean to refer to longitudinal data -- taking successive observations on single individuals over time -- then just fitting by least squares will not usually be suitable (because of the dependence between successive observations that this kind of data will lead to - your size now is definitely not independent of your size last time). In that situation, see the discussion of generalized logistic growth toward the end of the Wikipedia article on latent growth modelling.