필터 지우기
필터 지우기

HAC confidence interval for the response

조회 수: 3 (최근 30일)
Tamas Bodai
Tamas Bodai 2021년 4월 23일
편집: Tamas Bodai 2021년 5월 13일
Hello. One can use Matlab's predict to get estimates of the response or dependent variable and its confidence interval for a desired value of the predictor or independent variable. Can we do somehow the same upon using hac? I'm interested in the default value of the option 'Prediction' being 'curve'.

답변 (1개)

Tamas Bodai
Tamas Bodai 2021년 4월 26일
Maybe the following works. I don't accept this answer because i'm not sure if we can use mdl.DFE.
% Define your own data vectors 'y', 't' first, and then make a table
tbl = table(y,t);
% Fit the linear model to have mdl.DFE
mdl = fitlm(tbl,'y ~ t');
% Consider the response in the middle of the interval
%[ypred,yci] = predict(mdl,t(T/2)); % instead of this, do as follows
[EstCov, se, coeff] = hac(t,y);
[ypred,yci] = mypredict(t(T/2),coeff,EstCov,mdl.DFE,0.05);
% This is a stripped down version of function 'predci' called in function
% 'predictDesign' in CompactLinearModel.m.
function [ypred,yCI] = mypredict(X,beta,Sigma,dfe,alpha)
X = [1 X];
% Compute the predicted values at the new X.
ypred = X * beta;
% confi interval for fitted curve
varpred = sum((X*Sigma) .* X,2);
% pointwise
crit = tinv(1-alpha/2,dfe);
delta = sqrt(varpred) * crit;
yCI = [ypred-delta ypred+delta];
end
  댓글 수: 1
Tamas Bodai
Tamas Bodai 2021년 5월 13일
편집: Tamas Bodai 2021년 5월 13일
I have found an answer here:
https://www.mathworks.com/help/econ/correct-ols-coefficient-covariance-estimate.html
From the function nlpredci, you can read out the degree of freedom of the t-distribution applied. Mind, however, that for small sample size, it is not a t-distribution, it appears to me, or, the approximate t-distribution is of a different degree of freedom.

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

Community Treasure Hunt

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

Start Hunting!

Translated by