Failed attempts at fitting nonlinear Hill function (biochemistry) to data

982 Views Asked by At

I am trying to fit some data in Matlab to a Hill function of the form $y = \dfrac{1}{1+(K/r)^n}.$ I have data for $r,y$ and I need to find $K,n$.

I have tried following the approach shown here in Demo $3$ at this link: http://www.math.ubc.ca/~keshet/MCB2012/SlidesDodo/DataFitLect3.pdf

but I'm getting wrong results. Please help!

Here is my code:

Function file:

function response = func(x,dose)
EC50 = x(1);
n = x(2);
response = 1./(1+(EC50./dose).^n);
end

Script file:

xdata = (logspace(-2,2,101))';
ydata = [0.0981 0.1074 0.1177 0.1289 0.1411 0.1545 0.1692 0.1852 0.2027 ...
          0.2219 0.2428 0.2656 0.2905 0.3176 0.3472 0.3795 0.4146 0.4528 ...
          0.4944 0.5395 0.5886 0.6418 0.6994 0.7618 0.8293 0.9022 0.9808 ...
          1.0655 1.1566 1.2544 1.3592 1.4713 1.5909 1.7183 1.8537 1.9972 ...
          2.1490 2.3089 2.4770 2.6532 2.8371 3.0286 3.2272 3.4324 3.6437 ...
          3.8603 4.0815 4.3065 4.5344 4.7642 4.9950 5.2258 5.4556 5.6833 ...
          5.9082 6.1292 6.3457 6.5567 6.7616 6.9599 7.1511 7.3347 7.5105 ...
          7.6783 7.8379 7.9893 8.1324 8.2675 8.3946 8.5139 8.6257 8.7301 ...
          8.8276 8.9184 9.0029 9.0812 9.1539 9.2212 9.2834 9.3408 9.3939 ...
          9.4427 9.4877 9.5291 9.5672 9.6022 9.6343 9.6638 9.6909 9.7157 ...
          9.7384 9.7592 9.7783 9.7957 9.8117 9.8263 9.8397 9.8519 9.8630 ...
          9.8732 9.8826]';
guess = [1 1];
betaHat = nlinfit(xdata,ydata,@func,guess);
semilogx(xdata,ydata,'ro','MarkerSize',8)
hold on
plot(xdata,func(betaHat,xdata));

I am getting the Warning: Imaginary parts of complex X and/or Y arguments ignored

and here is my abysmal graph: Red = data, blue = bad fit

I have used nlinfit from the Statistics toolbox.

1

There are 1 best solutions below

0
On

Try transforming your equation to a different form? Often fitting can go wrong because of errors piling up in working with very small/large numbers. Sometimes, it can be fixed by transforming the equation to a different form.

I would suggest going in for fitting the logarithmic form of this equation, i.e. getting rid of the exponent. This is a pretty common practice in biochem.

the new form would be -

$log(y/1-y)=nlog(r)-nlog(k)$