Regression Technique Gives Bad Coefficients
Afficher commentaires plus anciens
I'm trying to perform an unfolding technique using regression techniques, and to be blunt, my abilities with matlab and with regression techniques in general is basic at best. I've tried using the lsqcurvefit command, but I'm running into one problem. When doing a fit of an equation such that Y=x1A1+x2A2+...xnAn, where A are data sets and Y is the response I'm trying to fit the summation to, Matlab is unwilling to return only positive coefficients. I've tried setting the lower and even upper bounds, as well as using the options=optimset but this does not seem to help. Instead of returning coefficients which makes sense, matlab will spit out several identical values with an e-14 magnitude and produce one or two spikes. If the lower bounds are not set to require that x be greater than or equal to 0. Can anyone suggest a fix for this, or am I just hitting my head against a wall here?
Example of the code I'm trying to get working, it was based on what I found in the help manual as well as examples online.
MDS_X = @(z_X,xdata_X)(z_X(1)*A0_121+z_X(2)*A0_167+z_X(3)*A0_217+z_X(4)*A0_293+z_X(5)*A0_360);
z0 = ones(1,5);
options = optimset('MaxIter',10,'Tolfun',1e-10)
[z_X,resnorm_X,residual_X] = lsqcurvefit(MDS_X,z0,t0_121,LR_C_PuBe,zeros(1,5),ones(1,5),options);
Réponses (1)
Star Strider
le 11 Nov 2014
I’m slightly lost. I understand that your anonymous function:
MDS_X = @(z_X,xdata_X)(z_X(1)*A0_121+z_X(2)*A0_167+z_X(3)*A0_217+z_X(4)*A0_293+z_X(5)*A0_360);
picks up ‘A0_121’ and the other from your workspace, but where do you use your independent variable values, ‘xdata_X’? Your equation doesn’t seem to be a function of it, and that could be causing problems for lsqcurvefit, that is doing it best to fit your dependent variable to a function of your independent variable.
12 commentaires
Jess
le 11 Nov 2014
Star Strider
le 11 Nov 2014
It still has to be a function of ‘data_X’ for lsqcurvefit to be happy with it. How do you want to state it as a function of ‘data_X’?
Jess
le 12 Nov 2014
Star Strider
le 12 Nov 2014
‘MDS_X’ must be a function of ‘data_X’ to work with lsqcurvefit.
Star Strider
le 12 Nov 2014
As I read your objective function, ‘z_X’ are your vector of parameters that you are estimating. (The the format for MATLAB objective functions is that the parameter vector is the first argument, and the independent variable the second.) That means that by definition, ‘xdata_X’ is your independent variable. I have no idea what you’re doing, so I’m going on what I can understand from your code.
Ideally, your equation is something like:
z_X(1).*xdata_X + z_X(2);
(for instance for a linear regression with ‘z_X(1)’ the slope and ‘z_X(2)’ the intercept in this illustration) but obviously with your own constants and function definition.
Star Strider
le 12 Nov 2014
If R(i,j) are fixed constant matrices and S(j) are parameters, this may be an optimisation problem more suited to fminsearch than lsqcurvefit (a much as I like lsqcurvefit).
You objective function then becomes (with ‘xdata_X’ playing the role of N(j)) and the norm function taking the RMS value of the difference:
MDS_X = @(z_X,xdata_X) norm((z_X(1)*A0_121+z_X(2)*A0_167+z_X(3)*A0_217+z_X(4)*A0_293+z_X(5)*A0_360) - xdata_X);
and your call to fminsearch becomes:
[S,fv] = fminsearch(@(z_X) MDS_X(z_X,xdata_X), rand(5,1))
See if that works to estimate ‘z_X’ with reasonable accuracy.
Star Strider
le 12 Nov 2014
The rand call substitutes for your initial parameter estimates. If you know the range the should be, substitute arbitrary values in those ranges for them, since those are likely to be closer to your optimal estimates.
The fmincon function will probably do what you want. You can use the ‘lb’ and ‘ub’ limits only and set everything else in the constraint argument list to empty arguments, for instance:
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
becomes for your purposes for example:
lb = zeros(5,1);
ub = inf(5,1);
x = fmincon(fun,x0,[],[],[],[],lb,ub)
I believe it uses the same optimset function, with different options.
Jess
le 12 Nov 2014
Star Strider
le 12 Nov 2014
I’m still not understanding what you’re doing, but if lsqcurvefit gives the best results, go with it.
I don’t understand your regression objective function, because it does not seem to be a function of ‘xdata_X’, and lsqcurvefit is calculating your ‘z_X’ parameters as though it is.
Catégories
En savoir plus sur Linear Least Squares dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
