MATLAB Answers

using a function that is similar to polyfit but with two linear terms

13 ビュー (過去 30 日間)
Locks 2013 年 4 月 29 日
I am looking for a matlab function that is working similar to polyfit, but where I can use two different input function but instead of having just one linear term, I need two. At the moment the regression looks as follows:
and the code to compute R^2 is the following:
x= changePriceWithoutNaN;
p = polyfit(x,y,1);
f = polyval(p,x);
yfit = polyval(p,x);
yfit = p(1) * x + p(2);
yresid = y - yfit;
SSresid = sum(yresid.^2);
SStotal = (length(y)-1) * var(y);
rsq_full = 1 - SSresid/SStotal
Instead of having just one linear term, the term I am looking for is the following:
Is there anybody how knows a function that is solving a least squared optimazation in the way to coe above does? Importat is that I do not look for a quadratic solution and therefore from what I can see polyfit(x,y,2) is not an option
  1 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 4 月 29 日
What is z?
Are you doing a mixed effects fitting?



Shashank Prasanna
Shashank Prasanna 2013 年 5 月 1 日
編集済み: Shashank Prasanna 2013 年 5 月 1 日
Locks, it seems like you are interested in multiple linear regression. If you have the stats toolbox you can use the REGRESS function to do that. If you don't then you can use a simple '\' as follows:
x = dataT(:,2);
%is the implied volatility
y = dataT(:,10);
z = dataT(:,15);
p = [x z ones(length(dataT))]\y
p will have the 3 coeff you desire. We are essentially solving a linear system in a least square sense.
  11 件のコメント
Locks 2013 年 5 月 3 日
I had some strange structure because I only used mdl_SAD.Coefficients.Estimate;
and I was not able to get the values saved in there, but no it's clear, thanks


その他の回答 (1 件)

Matt J
Matt J 2013 年 4 月 29 日
  4 件のコメント
Matt J
Matt J 2013 年 5 月 2 日
As said, the regression must stay linear, I do not want any quadratic components
And as I keep telling you, if you want to have only linear terms, then tell that to polyfitn:
p = polyfitn([x,y],z,1);


Community Treasure Hunt

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

Start Hunting!

Translated by