Nonlinear regression

I have some functions of $x$, in the form of $d\sqrt{x}$ or $d\log(x)$ where $d$ is known. I would like to rewrite (approximate is fine) them in the form $a/(1 + bx^c)$, where $a$, $b$ and $c$ are arbitrary.

I don't think there are $a$, $b$ and $c$ such that the two curves will match exactly, so I think maybe try to fit a nonlinear regression and find the closest $a$, $b$ and $c$. I tried the following R code, and I get the singular gradient error.

x     = seq(1, 50000, by=1000)
y     = 50*sqrt(x)
model = nls(y ~ a/(1 + b*x^c), start=list(a=1, b=-0.01, c=0.01))

-
Your problem is the best fit will be obtained when a and b are huge and c = -0.5 – Glen_b Jun 25 '14 at 2:00
Your function (given its starting values) is undefined for non-positive $x$ and is equivalent to $y=1$ for positive $x$. – Alexis Jun 25 '14 at 2:03
@Glen_b yup... at least in my graphing software for values of x up toward the order of $10^{1}$ on up to $10^{22}$. Or... Hmmm wait, that should be "for negative" and "for non-negative". My bad. – Alexis Jun 25 '14 at 2:05
Yep... ok just did it numerically, it's not exactly one, but it does not get far away from one. For his starting values, at $x=10^{50}$, $y=1.033$. – Alexis Jun 25 '14 at 2:10
Yes, we are agreed that the starting values aren't much good. But that's not the main problem, since other starting values can be chosen easily, and that doesn't happen with better starting values. See what happens in your graph when a=50000, b=1000, and c=-0.5 --- yet he still has multiple problems. – Glen_b Jun 25 '14 at 2:32

You have several problems there. The biggest problems are easiest to see if you reparameterize your fitted function from

$y = a/(1 + b x^{-c})$

to

$y = 1/(\frac{1}{a} + \frac{b}{a} x^{-c})$

$\quad = 1/(a_1 + b_1 x^{-c})$

(this gives the same model fit, just some of the parameters are different from your expression of the model)

Now let's look at your data:

$y = 50 x^\frac{1}{2}$

$\quad = 1/( \frac{1}{50} x^{-\frac{1}{2}})$

$\quad = 1/(0 + \frac{1}{50} x^{-\frac{1}{2}})$

That is, your model exactly fits your data if $a_1=0$, $b_1=\frac{1}{50}$ and $c=-\frac{1}{2}$.

Therefore, taking that back to the original form you tried to fit, $b/a = \frac{1}{50}$ or $a=50 b$ and $1/a = 0$.

So three problems:

(i) there's a ridge along $a=50b$

(ii) the bigger $a$ is, the better the fit (the sums of squares of error will be minimized as $a\to\infty$.

(iii) as $a\to\infty$, there's no error in the fit. This causes some difficulties with the fitting algorithm - it doesn't terminate nicely, but it can still find the fit if you solve the first two problems. (If you turn trace=TRUE on after the first two problems are fixed, and start in a reasonable place, it does locate the parameter values I mention - 1.662634e-22 : 0.02 -0.50 are the values trace gives for the SSE, b1 and c. If you play with the convergence criteria, you may be able to get it to store the results in model.)

(Well, Alexis correctly points out your starting values are no good, so maybe that's four problems.)

-