Robust standard errors on coefficients in a robust linear regression
24 次查看(过去 30 天)
显示 更早的评论
T27667
2013-7-30
I am new in MATLAB and have performed a robust linear regression with the 2 commands:
ds = dataset('XLSFile','C:\...\data.xlsx','ReadObsNames',true);
mdl = LinearModel.fit(ds,'linear','RobustOpts','on');
The standard errors (SE) shown in the property "Coefficients", are these the heteroskedasticity robust standard errors? If not, how can I modify my commands such that I get the robust standard errors?
采纳的回答
Shashank Prasanna
2013-7-30
The output is robust to outliers and are not heteroskedasticity consistent estimates.
If that is what you are interested in, please check out the HAC command in the Econometrics Toolbox:
21 个评论
T27667
2013-7-30
Yes, I am interested in estimates and standard errors which are both outlier robust AND heteroskedasticity consistent. From the robust regression, I get the outlier robust estimates and outlier robust standard errors, if I understand correctly, right?
In order to get estimates and standard errors which are also heteroskedasticity consistent, I have checked out http://www.mathworks.com/help/econ/hac.html but it says here that: "...returns robust covariance estimates for ordinary least squares (OLS) coefficient estimates". Then I guess that I cannot use this command as I do not have the ordinary least squares (OLS) coefficient estimates but the robust regression estimates (as I have used robust regression). Isn't that true?
Shashank Prasanna
2013-7-30
HAC takes in the fitted linear model with robust opts:
load hald
X = ingredients; % predictor variables
y = heat; % response
mdl = LinearModel.fit(X,y,'linear','RobustOpts','on')
EstCov = hac(mdl)
T27667
2013-7-30
编辑:T27667
2013-7-30
Ok, thanks a lot. The code lines that you provide above, are these from mathworks.se? Because then I will read that page. Or have you created them yourself? However, I get an error message using the 2 commands:
mdl = LinearModel.fit(ds,'linear','RobustOpts','on');
EstCov = hac(mdl)
Undefined function 'hac' for input arguments of type 'LinearModel'.
How can that be?
Shashank Prasanna
2013-7-30
These is directly from the documentation from LinearModel.fit but I've continued to use the same model in HAC.
You are getting the error because you don't have the Econometrics Toolbox installed. To confirm type the following on your command line.
>> ver
T27667
2013-7-30
All my commands are now:
ds = dataset('XLSFile','C:\...\data.xlsx','ReadObsNames',true);
mdl = LinearModel.fit(ds,'linear','RobustOpts','on');
ver
EstCov = hac(mdl)
Undefined function 'hac' for input arguments of type 'LinearModel'.
But I still I get the error above. Should I type more than ver?
Shashank Prasanna
2013-7-30
编辑:Shashank Prasanna
2013-7-30
ver won't solve your problem. You need the Econometric Toolbox, which is this product:
If you don't have it then you can't use HAC. All ver does is show you if you have the product installed on your machine.
>> ver
Just run the above and confirm if Econometrics Toolbox is installed or not based on what appears on the command line output.
This is what ver does:
T27667
2013-7-31
Great, now I got the heteroskedasticity consistent standard errors using the command:
EstCov = hac(mdl,'display','full')
Thanks a lot for your help!
Unfortunately, the command doesn't give the t-stats and p-values such that I can reduce my linear model. Can I modify the command such that t-stats and p-values are provided?
Shashank Prasanna
2013-7-31
Please read the documentation of HAC on how to get the coefficients and standard errors. From theory t-stats is their ratio.
T27667
2013-7-31
编辑:T27667
2013-7-31
I got the heteroskedasticity consistent standard errors using the command from http://www.mathworks.com/help/econ/hac.html:
EstCov = hac(mdl,'display','full')
But isn't it possible to also get the t-stats and p-values using a build-in command? I had hoped that columns with estimates, standard errors AND t-stats and p-values were generated as when you run a LinearModel.fit and open "Coefficients".
If there is no such build-in command, which code lines should I then write after the EstCov command in order to have t-stats and p-values calculated. Unfortunately, I have no programming experience in MATLAB. Would be lovely with a code that generate the estimates, robust SEs, t-stats and p-values in Workspace like in the output from LinearModel.fit
Shashank Prasanna
2013-7-31
Did you get a chance to read the documentation page?
You can ask HAC to return EstCov,se and coeff.
>> tstats = coeff./se
T27667
2013-7-31
编辑:T27667
2013-7-31
Yes, but the documentation page doesn't say anything about a command that generates tstats and p values. Getting HAC to return EstCov, robust SE and coeff works fine. I get the error below if I write the command tstats = coeff./se directly?
Undefined function or variable 'Coeff'.
How do I store the returned Coeffs and SEs from command Window (from command EstCov = hac(mdl,'display','full')) into variables such that I can calculate the tstats using your formula? And afterwards what command calculates the p values?
Shashank Prasanna
2013-7-31
MATLAB is case sensitive.
Please read the documentation on how to store the returned values in the variables. Go through the examples.
T27667
2013-7-31
I will. Thanks for all your help! Really appreciate it! If you know the formula for the p values, I would love to see it.
Shashank Prasanna
2013-7-31
This comes from theory.
dfe is the degrees of freedom = number of observations - number of estimated parameters. t is the t statistic.
pValue = 2*(tcdf(-|t|,dfe));
T27667
2013-7-31
编辑:T27667
2013-7-31
Thank you so much. However, I really can't see from the examples how to store the coeffs and robust SEs in the Workspace such that I can calculate the tstats (and afterwards the p values). The covariance matrix is stored automatically in the Workspace as a double by EstCov = hac(mdl,'display','full') but I can't find a way to store the coeffs and robust SEs. I can't see this is done in any of the examples. Should I convert a vector into a cell or? I can see that se and coeff are of the type vector. I know about converting a dataset into a cell using dataset2cell but can't find anything about converting a vector into a cell. Or am I on the right track at all?
Shashank Prasanna
2013-7-31
Did you try running the first example completely? When you do you should see 3 variables LSCov,LSSe,coeff in your workspace.
T27667
2013-8-1
编辑:T27667
2013-8-1
Finally got it using the commands:
ds = dataset('XLSFile','C:\...\data.xlsx','ReadObsNames',true);
mdl = LinearModel.fit(ds,'linear','RobustOpts','on');
[EstCov,se,coeff] = hac(mdl,'display','full');
tstats = coeff./se
pValue = 2*(tcdf(-abs(tstats),1803-17));
So nice finally to have all results. Thank you so much again!! I was 100% sure that I had the correct command in EstCov = hac(Mdl) and couldn't see until now that [EstCov,se,coeff] = hac(mdl,'display','full'); did the same + more.
Just to be sure, the degrees of freedom = number of observations - number of estimated parameters. Last term (Number of estimated parameters) does that include the intercept?
Shashank Prasanna
2013-8-1
I've been asking you to read the documentation from the very first post. If you did you would have saved this much time.
T27667
2013-8-1
Sorry but I misunderstood the example. I'm a completely new user of MATLAB and both using it and understanding the documentation pages are difficult here in the beginning. But getting better every day :)
Just to be sure, the degrees of freedom = number of observations - number of estimated parameters. Last term (Number of estimated parameters) does that include the intercept?
Shashank Prasanna
2013-8-1
That's a statistics question (along with how to compute tstats and pvalue)
I don't know what your application is but you should get hold of some statistics material to convince yourself before applying anything I mentioned.
If you want to get better with MATLAB, check out the Getting Started guide:
T27667
2013-8-1
I think those formulas are the correct ones in my case as I perform a backwards elimination of a robust linear regression.
更多回答(1 个)
T27667
2013-7-30
Yes, I am interested in estimates and standard errors which are both outlier robust AND heteroskedasticity consistent. From the robust regression, I get the outlier robust estimates and outlier robust standard errors, if I understand correctly, right?
In order to get estimates and standard errors which are also heteroskedasticity consistent, I have checked out http://www.mathworks.com/help/econ/hac.html but it says here that: "...returns robust covariance estimates for ordinary least squares (OLS) coefficient estimates". Then I guess that I cannot use this command as I do not have the ordinary least squares (OLS) coefficient estimates but the robust regression estimates (as I have used robust regression). Isn't that true?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Robust Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
