Linear Regression - hac function
Ältere Kommentare anzeigen
Hello,
I am relatively new to MATLAB so please excuse this odd question. I was doing a linear regression using the fitlm function, however, I had problems with heteroscedasticity. I then found the hac function.
Is there a way to also get the R-squared for this function. So I basically only use this function instead? my Y variable is Excess Return and my x variables are the three Fama French Factors.
Thank you very much for your advice!
5 Kommentare
dpb
am 4 Aug. 2018
"then found the hac function"
>> which hac
'hac' not found.
>>
???
the cyclist
am 4 Aug. 2018
@dpb, I find your lack of google skills disturbing. :-)
It's a function in the Econometrics Toolbox.
dpb
am 4 Aug. 2018
:)
I'm patently lazy...looks like a meaningful function name, though... ???
Karoline Bax
am 5 Aug. 2018
Bearbeitet: dpb
am 5 Aug. 2018
dpb
am 5 Aug. 2018
Rsq = 1- SSe/SSt; no need to run fitlm (which would estimate a different model, anyway).
Antworten (1)
Vishal Chaudhary
am 14 Aug. 2018
You can also use fitlm function with hac.
DataTable = array2table([X,y],'VariableNames',{'X1','X2','X3','Y'});
OLSModel = fitlm(DataTable);
[EstCov,se,coeff]=hac(OLSModel,'display','full');
Or, you can calculate r-squared as follows only using hac:
[EstCov,se,coeff] = hac(DataTable,'display','full');
ypred2 = [ones(size(X,1),1) X] * coeff;
sse = var(y-ypred2);
sst = var(y);
rsq = 1-(sse/sst);
Kategorien
Mehr zu Linear and Nonlinear Regression finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!