Code covered by the BSD License  

Highlights from
Huynh-Feldt epsilon general procedure

5.0

5.0 | 4 ratings Rate this file 9 Downloads (last 30 days) File Size: 6 KB File ID: #22870

Huynh-Feldt epsilon general procedure

by Matthew Nelson

 

02 Feb 2009 (Updated 21 Apr 2009)

Calc. the Huynh-Feldt epsilon for any arbitrary combination of between and within subject factors

| Watch this File

File Information
Description

%function [EpsHF EpsList EpsGG]=GenCalcHFEps(Y,BTFacs,WInFacs,S)
%
% This will calculate the Geisser-Greenhouse and Huynh-Feldt epsilon value
% for the general case when given a univariate dataset with any amount of
% between or within subject factors.
%
% After calling this function, the intention is to multiply the degrees of
% freedom for tests in a repeated measures ANOVA by the corresponding
% epsilon value given by this code to obtain a corrected p-value. The
% F-statistic does not change as a result of this.
%
% Inputs:
% Y- A column vector of the dependent variable (the value
% measured) for each data point.
% BTFacs- A matrix of between subject factors. Must have the same
% number of rows as Y. Each factor is down a different column
% of BTFacs, and the value in each row denotes the level of
% that factor for each corresponding datapoint in Y. If there
% are no between subject factors, input an empty matrix, [].
% WInFacs- A matrix of within subject factors. Must have the same
% number of rows as Y. Each factor is down a different column
% of WInFacs, and the value in each row denotes the level of
% that factor for each corresponding datapoint in Y.
% S- A column vector of subject numbers corresponding to each
% datapoint in Y. Must have the same number of rows as Y. If
% left empty, the program assumes all subjects are entered in
% the same order for all combinations of factors.
%
% Outputs:
% EpsHF- A row vector of all the possible values for the Huynh-Feldt
% epsilon, correspondding to all main effects for ecah within
% subject factor, and all interactions of within subject
% factors.
% EpsList- A cell array of a text list of the effects corresponding to
% the positions in EpsHF. For example 'A' means a main effect
% for the first (within subject) factor, 'AB' means a 2way
% interaction for the first two (within subject) factors,
% etc.
% EpsGG- The Geisser-Greenhouse epsilon values, in teh same form as
% EpsHF.
%
% The Huynh-Feldt epsilon value is less conservative while maintaining the
% proper Type I error rate, which is why the program title focuses on that.
% The Geisser-Greenhouse epsilon is calculated first as part of the
% process of calculating the Huynh-Feldt value, so I've allowed it to be
% optionally returned as well.
%
% This code follows a procedure described in Huynh(1978), but includes a
% modification of the last step, as described in Chen & Dunlap(1994).
%
% I've tested this with results from SPSS for a couple of sample datasets
% I've found in various websites, and it gives results that match
% According to what I've seen and read though, SPSS and SAS give results
% for EpsHF that are wrong when both between and with-in factors are
% present, and thus they slightly differ from the results this program,
% although the results for EpsGG are identical. To reproduce the SPSS
% results, uncomment line 153. See other comments near there for references
% on why I think SPSS/SAS is wrong.
%
%
% References:
%
% Huynh H. "Some approximate tests for repeated measurement designs",
% Psychometrika (1978)
%
% Chen, RS and Dunlap, WP "A MonteCarlo STudy on the Performance of a
% Corrected Formula for eps(tilda) suggested by Lecoutre", Journal of
% Educational Statistics (1994)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
adjPF

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
05 Oct 2009 Kathrin

thank you! very flexible and easy to use for repeated measures anova. but it would be even more helpful if there was a little statistic (like mauchly's test on sphericity) specifying if one needs to adjust the degrees of freedoms with the computed epsilon estimates.

12 Mar 2010 Yoni

This seems useful, especially with allowing the arbitrary numbers of both kinds of factors. But what functions would you use to get the actual F values from data that are arranged in the same way?

02 Apr 2010 Matt Mollison

Kathrin, I modified some code from Mausphercnst http://www.mathworks.com/matlabcentral/fileexchange/19648 for doing Mauchly's Test of Sphericity. I did this because Mausphercnst cannot handle the interaction, but GenCalcHFEPS can. Here's some code you could put at the end of the final for-loop of GenCalcHFEPS:

% Mauchly's W
Mau.w(im) = det(S)/((trace(S)/r)^r);
% approximate to Chi-square distribution
Mau.chiSq(im) = -(N-1-((2*r^2+r+2)/(6*r)))*log(Mau.w(im));
% degrees of freedom
Mau.df(im) = r*(r+1)/2-1;
% Chi-square probability-value
Mau.p(im) = 1-chi2cdf(Mau.chiSq(im),Mau.df(im));

08 Apr 2010 Kathrin

Thanks!

13 Apr 2010 Matthew Nelson

Thanks all for the comments and sorry to be slow to respond.

I didn’t add anything like mauchly’s test for sphericity because personally I prefer to account for even small deviations from sphericity rather than use a test like that to decide whether or not to. But thanks just the same to Matt for posting that code for anyone that wants to use it.

With regards to Yoni’s question, there is matlab’s anovan that could be combined with this to allow for a Repeated Measures anovan. I have code for that halfway finished, but stopped as I found a better way around that for the project I was working on at the time. If I come across a project later on where I need that, I will finish that and post it to the matlab file exchange. (Provided someone else hasn’t already done that by then!)

It’s unfortunate that matlab’s statistical toolbox is so lacking for such basic things like a repeated measures anova, among other things, but c’est la vie.

10 Aug 2010 Matt Mollison

Yoni,

Not sure if you found a solution yet, but I stuck a call to GenCalcHFEps inside this guy's http://www.mathworks.com/matlabcentral/fileexchange/authors/7089 RMAOV scripts; I've used it in RMAOV2 and RMAOV33 and it works great. You'll just have to modify the print statements to output a table with the GG/HF values. Let me know if you want mine and I can send them along.

22 Dec 2011 Damiano

Matthew,
I applied your function to a simple Mixed-model ANOVA, with one BT factor (4 levels) and 1 WIn factor (3 levels), and checked the results with SPSS 20.
EpsGG is OK, however the discrepancy in EpsHF is still there, even when the commented line is used in the script.
I noticed that differences btw SPSS values and function outputs can be as great as 10%.

05 Jan 2012 Matthew Nelson

I suspect that this is a difference between how SPSS defines the Huynh-Feldt epsilon in its different versions of SPSS, but I don’t have the time to investigate this further now. I had checked this earlier with a version that I know was older than SPSS 20, but I don’t recall which. The ‘heart’ of the program is the EpsGG which is used to determine the EpsHF.

04 Feb 2012 Amarelo

Thanks, a very helpful function! Together with Matt Mollison's addition of the Mauchly-Test for sphericity (see above) this completely saves me running the repeated measures ANOVAs on SPSS again to get the corrected p-values. And it seems to agree well with the comparisons I have made.

Please login to add a comment or rating.
Updates
03 Feb 2009

added authorship lines

21 Apr 2009

Fixed bug on line 120 related to determining the numbers of subjects from the subject list when between subject factors are present

Tag Activity for this File
Tag Applied By Date/Time
statistics Matthew Nelson 03 Feb 2009 16:02:35
anova Matthew Nelson 03 Feb 2009 16:02:35
repeated measures Matthew Nelson 03 Feb 2009 16:02:35
repeated Matthew Nelson 03 Feb 2009 16:02:35
huynhfeldt Matthew Nelson 03 Feb 2009 16:02:35
huynh Matthew Nelson 03 Feb 2009 16:02:35
geissergreenhouse Matthew Nelson 03 Feb 2009 16:02:35
epsilon Matthew Nelson 03 Feb 2009 16:02:35
orthogonal comparison Matthew Nelson 03 Feb 2009 16:02:35

Contact us at files@mathworks.com