View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Heteroskedasticity test

5.0 | 2 ratings Rate this file 26 Downloads (last 30 days) File Size: 716 KB File ID: #24722 Version: 1.6

Heteroskedasticity test


Oleg Komarov (view profile)


14 Jul 2009 (Updated )

White, White special case and Breush-Pagan tests. Stat TB needed: regstats and chi2cdf.

| Watch this File

File Information

TESTHET Tests wether heteroskedasticity affects data. Need 'regstats' and 'chi2cdf' (Stat TB).

- Res: residuals obtained by regressing Y on x1, x2 etc...(1) It can be a numeric 'n-by-1' vector or a 'n-by-p' matrix with 'p' residuals obtained from different regressions. The # of obs. is 'n'.
- X: predictors suspected of causing heteroskedasticity. Not necessarily all those in (1). Same format as Res.
- Whichtest: test chosen in format string.
                a. Breush-Pagan, Koenker mod. --> -BPK
                b. White --> -W
                c. White, Wooldridge --> -Ws
- Yhat: only for '-Ws' test. Fitted values from (1). Same format as Res.

A '1-by-p' array with p-values.

1. Regress Y on x1, x2:
--> regstats(Y, [x1 x2], 'linear', {'r','yhat'})
2. Test with -Ws:
--> TestHet(r,[x1, x2], '-Ws', yhat)

For general econometric reference:
[1] Greene, W.H. (2003 - 5th ed.) Econometric Analysis. Prentice Hall.
[2] Wooldridge, J.M. (2006 - 3rd ed.). Introductory Econometrics: A Modern Approach. Thomson - South West.
[3] Kennedy, P. (2008 - 6th ed.). A Guide to Econometrics. Blackwell Publishing.

Any comments, suggestions and critics are truly welcome.
Plz let me know if you prefer a function which doesn't use the stats toolbox.


Required Products Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
27 Dec 2016 Fatih Olmez

29 Aug 2013 Oleg Komarov

Oleg Komarov (view profile)

From the description above:

A '1-by-p' array with p-values.

Also, for general reference:'>

Comment only
09 Aug 2013 Luc

Luc (view profile)

I've got the same question. waht does pval mean?

Comment only
27 Nov 2012 Sara Sá

What the pval means? How do i know if there is heteroscedasticity or not?

Comment only
27 Jun 2012 Kyle

Kyle (view profile)

Thanks for the submission, I really like it!

Due to changes in Matlab there is one small caveat: in Matlab 2007 you could use a matrix of regressors with a constant column in it. This has changed since, in Matlab 2010a (possibly earlier ), you are prohibited to use a constant col in the 'regstats' function, this in the 'TESTHET', otherwise you get all NaNs for every metric that matters. However, you are still advised to add a constant col to regressors in the 'regress' function.
Obviously, this inconsistency is Mathworks' fault, not the author's, so five stars.

(Although it would be nice to implement a check on constant columns to alleviate this problem.)

17 Jul 2009 Oleg Komarov

Oleg Komarov (view profile)

Updating with check on solvability of the system. In case observations < regressors, regstats gives an error. If this is the case, skip that series and leave NaN in the Pvalue vector.

Comment only
14 Jul 2009 Oleg Komarov

Oleg Komarov (view profile)

DemoDataset missing, updating...

Comment only
14 Jul 2009 1.1

DemoDataset.mat was missing in the package. Added.

17 Jul 2009 1.5

Added check on solvability of the system.

15 Aug 2009 1.6

Error on line 80: Nseries = size(Res,2)-1 --> Nseries = size(Res,2).
Pointed out by Dan Iancu.

Contact us