How to store the regression coefficients and std.errors of the slope only (but not intercept)?
3 次查看(过去 30 天)
显示 更早的评论
Dear all
I want to estimate a set of regressions with HAC covariance matrix. For this purpose, I created the function below. I have a N*N matrix whose columns are time series. I wish to regress each column on each other column and store the slopes in a N*N matrix, the serrors in another N*N matrix. Position (i,j) in these matrices would store the slope coefficient or serror of the regression of the data in column i on the data in column j. My problem is that the standard errors and the coefficients are returned in pairs (for the slope and for the intercept). How can I adapt the code below so that I only store the slope coefficients and associated st.errors but not those of the intercept?
Thanks!
function [mCoeff mSE mTstat] = regressionHAC(mMatrix)
[~, C] = size(mMatrix,2);
mCoeff = NaN(C,C);
mSE = NaN(C,C);
for j = 1 : C
for k = 1 : C
if j ~= k % This is just to avoid regressing a column on itself
[mCoeff(j,k) mSE(j,k)] = hac(mMatrix(:,k),mMatrix(:,j));
end
end
end
mTstat = mCoeff ./ mSE;
end
采纳的回答
dpb
2016-7-18
According to the doc, the coefficient vector is third output argument, not first...
[~,SE,Coeff] = hac(mMatrix(:,k),mMatrix(:,j));
mSE(j,k)=SE(end);
mCoeff(j,k)=Coeff(end);
I presume above it's a poly of degree 1; the intercept is first in position in the vector (again, according to the doc at <econ/hac>, hence the slope is last ( end) position in the output 2-vector. Matlab has no facility to subscript function results for even a single output argument, what more multiple ones, so just save each result as a temporary and then retrieve the desired quantities for posterity.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!