# Exponent for non-linear regression (in R)?

I have a non-linear reglationship and I want to find the best way to determine the value for the exponent $\gamma$ in the following regression:

$y = \beta x ^ \gamma$

I would preferably like to do this in R.

• It depends on what you mean by "best" and on the nature of your data. For example, if $y$ is measured with additive error then really $y = \beta x^\gamma + \varepsilon$, which is nonlinear, but if $y$ is measured with multiplicative error then $\log(y) = \log(\beta) + \gamma \log(x) + \delta$ is actually a linear model. The two models are not the same: typically they will produce (slightly) different estimates of $\gamma$ and different standard errors. If also $x$ is measured with error, both models get substantially more complicated and yield yet two more estimates. – whuber Jan 16 '13 at 16:24

In order that this receive an answer (though it may not add a heck of a lot to whuber's comment):

I want to find the best way to determine the value for the exponent $\gamma$ in the following regression: $y = \beta x^\gamma$

The observed $y$ will not actually be $\beta x^\gamma$; if it were there'd be no need for statistics.

We might say $E(y)=\beta x^\gamma$, for example, but it's not sufficient.

To address this problem we would normally consider the distribution of $y$ given $x$, and describe how the distribution - or at least parameters that describe the distribution, such as at least the mean and variance - relates to $x$.

In particular, we would (at least) consider the way the error term enters the relationship, such as:

$y=\beta x^\gamma+\varepsilon\,$, or

$y=\beta x^\gamma\times\eta$

If it's of the first form, and the (zero-mean) error terms are independent with $\text{Var}(\varepsilon)$ constant, then we'd use ordinary nonlinear least squares to estimate $\beta$ and $\gamma$.

If it's of the second form, and the error terms are independent, $\eta$ is positive (such that $\log(\eta)$ is zero mean and constant variance), then we might take logs and estimate $\beta$ and $\gamma$ using linear regression.

If, on the other hand, we assumed that the $\eta$ were gamma-distributed, then we might fit a gamma-family GLM with log-link.

In some situations, it doesn't make sense to specify an error term at all; consider the situation where $y\sim \text{Poisson}(\beta x^\gamma)$; the specification $E(y)=\beta x^\gamma$ is correct, but to deal with things from there we're best leaving the model as $y\sim \text{Poisson}(\beta x^\gamma)$. Again, this would be fitted via a GLM with log-link.

There are a number of other possibilities.

If you really do need the nonlinear regression option (additive error, constant variance), then this is done using nls in R.

This works a little differently to lm, because lm can simply assume one coefficient for every predictor. By contrast, nls needs us to specify the form of the model including the parameters.

Here's an example (the data comes with R. It isn't necessarily suited to this model).

carsfit=nls(dist~beta*speed^gamma,data=cars,start=list(beta=exp(-.73),gamma=1.6))


The start values came from an OLS regression on the logs of the y and x variables.

 summary(carsfit)

Formula: dist ~ beta * speed^gamma

Parameters:
Estimate Std. Error t value Pr(>|t|)
beta    0.5897     0.3357   1.757   0.0853 .
gamma   1.5493     0.1920   8.068 1.74e-10 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 15.06 on 48 degrees of freedom

Number of iterations to convergence: 3
Achieved convergence tolerance: 4.979e-07 