Linear Regression - hac function

조회 수: 12 (최근 30일)
Karoline Bax
Karoline Bax 2018년 8월 4일
답변: Vishal Chaudhary 2018년 8월 14일
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
Karoline Bax
Karoline Bax 2018년 8월 5일
편집: dpb 2018년 8월 5일
Hello, thank you for your replies. The function I am referring to is for Heteroscedasticity and autocorrelation consistent covariance estimators ( https://de.mathworks.com/help/econ/hac.html ). As it gives me all the pvalues, coefficience and tStatistics I was wondering if there is a way for me to get the Rsquared too? Instead of running a fitml ( https://de.mathworks.com/help/stats/fitlm.html ) for the Squared. Thank you for your advice!
dpb
dpb 2018년 8월 5일
Rsq = 1- SSe/SSt; no need to run fitlm (which would estimate a different model, anyway).

댓글을 달려면 로그인하십시오.

답변 (1개)

Vishal Chaudhary
Vishal Chaudhary 2018년 8월 14일
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);

카테고리

Help CenterFile Exchange에서 Model Building and Assessment에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by