Global fitting with one shared paramenter

16 visualizaciones (últimos 30 días)
favret
favret el 11 de En. de 2019
Comentada: Alex Sha el 18 de Feb. de 2020
Hello all,
First I would apologize for the code. I am sure there are smarter ways to write it but I am pretty new in matlab and programming syntax.
I am struggling to write nonlinear model to fit several data sets simultaneously. In particular I need to global fit some experimental data and one of these (b(3) in the following code ) is shared among them. I went throw the previous dscussion on the topic but I could not correct my code. My problem is that I did not undertand how to specify that the parameters for the fitting [b(1) and b(2)] can be different among the 4 dataset and b(3) is the same in order to plot them finally.
The function I need to use for the globla fitting is the same as my model function
I upload here the excell data I was using to test the script
Thank you in advance, Fil.
%----- Model function for 1:1 binding -------
modelfun = @(b,x)b(1)*(b(2)+x+b(3)-sqrt((b(2)+x+b(3)).^2-4*b(2)*x))./(2*b(2));
modelfun = @(b,x) modelfun([b(1),30,b(3)],x) %fixing parameters
b0 = [1; 30; 20]; %initialize parameters
% b(1) = maximum asintot
% b(2) = P0: total protein concentration
% b(3) = kd value
input = 'Global_fitting'; %take excel file as input
sheet = 1;
xlrange= 'A2:H11'; %data range
data=xlsread(input,sheet,xlrange);
[nr,nc]=size(data); % size of the data: nc [number of columns], nr[number of rows]'
x= data(:,1); % data x
for i = 1:nc % prepare y data
if (rem(i,2)==0)
y(:,i) = data (:,i);
y( :, all(~y,1) ) = []; % delete zero values columns
end
end
[ry, cy] = size(y); % size of the data: cy [number of columns], ry[number of rows]'
output_params = zeros (3,4);
for n= 1:cy
output_params(:,n)=lsqcurvefit(modelfun, b0, x,y(:,n)); % first independent fit of the (x,y) dataset
end
output_param0 = output_params % output parameters of the fitting
%---- global fitting ------
Fitting = @(params,x) modelfun([params(1:4),params(3)], x)
params0 = output_param0
for n= 1:cy
m = lsqcurvefit(Fitting,params0,x,y(:,n))
end
plot (x,y, 'o')
hold on

Respuesta aceptada

Jeff Miller
Jeff Miller el 11 de En. de 2019
> I did not undertand how to specify that the parameters for the fitting [b(1) and b(2)] can be different
> among the 4 dataset and b(3) is the same in order to plot them finally.
Using fminsearch, one way to approach this problem is to imagine that there is one combined dataset (instead of 4 separate ones) and that there are 9 parameters instead of 3: that is, 4 b1's (one for each dataset), 4 b2's, and one b3.
For any proposed set of 9 parameter values, you compute the predicted y's, and return the error score sum( (Y-Ypred).^2 ) to fminsearch. fminsearch will find the best parameter values for you, and the same b3 will be used for all datasets since there is only one of them.
Maybe you can do something similar with lsqcurvfit.
  4 comentarios
favret
favret el 13 de En. de 2019
Thank you Jeff,
it worked. I followed your suggestion of treating the datasets as they were a signle combined one and I assumed to look for 9 different parameters. Instead of using fminsearch I used nlinfit routine.
Best regards
Alex Sha
Alex Sha el 18 de Feb. de 2020
Hi, favret, how about the result below?
Root of Mean Square Error (RMSE): 0.0453866241672465
Sum of Squared Residual: 0.0741580435187599
Correlation Coef. (R): 0.990025809859437
R-Square: 0.980151104187835
Adjusted R-Square: 0.97354297647267
Determination Coef. (DC): 0.979808203810207
F-Statistic: 0
Parameter Best Estimate
-------------------- -------------
b3 72.7094303649792
b1(V52) 1.1962117299204
b2(V52) -2.34403556285839
b1(A53) 1.11418356292307
b2(A53) 17.5408926600087
b1(K58) 1.05719379067003
b2(K58) 75.421982525703
b1(S129) 1.14076171005594
b2(S129) 7.94549472454694

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by