Regression Technique Gives Bad Coefficients

2 views (last 30 days)
Jess
Jess on 11 Nov 2014
Commented: Star Strider on 12 Nov 2014
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);

Answers (1)

Star Strider
Star Strider on 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 Comments
Jess
Jess on 12 Nov 2014
Yes, fmincon uses the same optimset function and a slightly different array of options, but the tolerance and number of iterations can still be set using "Tolfun" and "MaxIter". I think fmincon may actually have been worse than using lsqcurvefit though. It returns the same coefficients that lsqcurvefit did, but now the fit is horrible when comparing plots of x_dataX and the summation of Rij*Sj.
xdata_X = LR_C_PuBe;
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);
z0 = zeros(1,5);
lb = zeros(1,5);
ub = inf(1,5);
options = optimset('MaxIter',1000,'Tolfun',1e-100)
[S,fv] = fmincon(@(z_X) MDS_X(z_X,xdata_X),z0,[],[],[],[],lb,ub,[],options)
MDS_Coeff = S;
MDS_size = [0.121 0.167 0.217 0.293 0.360];
Star Strider
Star Strider on 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.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!