Code covered by the BSD License  

Highlights from
RMA1multap

from RMA1multap by Antonio Trujillo-Ortiz
One-Sample Repeated Measures Analysis by the Multivariate Approach.

RMA1multap(X,alpha)
function [RMA1multap] = RMA1multap(X,alpha)
%RM1MULTAP One-Sample Repeated Measures Analysis by the Multivariate Approach.
%  One-sample repeated measures is used to analyze the relationship between 
%  the independent variable and dependent variable when:(1) the dependent 
%  variable is quantitative in nature and is measured on a level that at
%  least approximates interval characteristics, (2) the independent variable
%  is within-subjects in nature, and (3) the independent variable has three
%  or more levels. It is an extension of the correlated-groups t test, where
%  the main advantage is controlling the disturbance variables or individual
%  differences that could influence the dependent variable. 
%  Another approach to repeated measures analyses is through using multivariate
%  statistical techniques. This requires a paradigm shift. When considering
%  the univariate analysis techniques, the experimental design was subjects
%  as a random factor crossed with treatments or repeated measures as a fixed
%  factor. To shift to the multivariate techniques, the repeated measures become
%  a series of dependent variables and subjects are considered as replications
%  in a single-cell design (Lewis, 1993). The most common approach is to 
%  transform the p dependent variables into p-1 linearly independent pairwise
%  difference scores. Analysis is performed on these p-1 new dependent variables.
%  The null hypothesis that is most often tested in this situation is that the
%  difference scores have population means of zero, using an F transformation of
%  Hotelling's T2 (Lewis, 1993;Stevens, 1996).
%  There are advantages and disadvantages to using the multivariate approach.
%  The multivariate approach does not require the sphericity assumption. However,
%  researchers have not come to an agreement as to the best multivariate approach
%  to take when considering power and robustness against assumption violations.
%  There are serious concerns about power when the number of subjects is less than
%  or equal to the degrees of freedom for a repeated measures main effect or 
%  interaction; in fact, the test statistic could not be computed. When the number
%  of subjects is greater than, but still close to the degrees of freedom, the test
%  has little power. But, power increases rapidly as the number of subjects 
%  increases (Lewis, 1993;Stevens, 1996).
%  In general, it is recommended that both the univariate and the multivariate
%  approaches be run since the two approaches evaluate different aspects of the 
%  data. The only safeguard if this approach is taken is to decrease the alpha-
%  level for each approach by half, in order to control for experiment-wise Type
%  I error (Barcikowski and Robey, 1984;Lewis, 1993;Stevens, 1996).
%  Applied statisticians tend to prefer the multivariate test to the standard or
%  the alternative univariate test because the multivariate test and follow-up 
%  tests have a close conceptual link to each other.
%  According to Box (1954) if sphericity (circularity) assumption is not met, then
%  the F ratio is positively biased and we are rejecting falsely too often. So, if
%  sphericity holds the univariate approach is more powerful. When small but 
%  reliable effects are present with the effects being highly variable, the 
%  multivariate test is far more powerful than the univariate test.
%  The exact F transformation of T2 is multiply it by the ratio (n-p+1)/(n-1)(p-1). 
%  The F-citical value is with alpha-value and (p-1) and (n-p+1) degrees of 
%  freedom.
%
%  Syntax: function [RM1multap] = RMA1multap(X,alpha) 
%     
%  Inputs:
%       X - data matrix (Size of matrix must be n subjects-by-p correlated variables). 
%   alpha - significance level (default = 0.05).
%  Output:
%         - Complete Multivariate Analysis Table.
%
%   Example: From the example given by Dr. Matthias Winkel* (http://www.stats.ox.ac.uk/~winkel/phs.html) 
%            on the relaxation therapy against migrane. Nine subjects participated in a relaxation therapy
%            with several weeks baseline frequency/duration recording (w1 and w2) and several weeks
%            therapy (w3 to w5). Its is of interest to test if there exist differences on the relaxation
%            therapy and within subjects with a significance level = 0.05.
%
%                                                          Weeks
%                            ------------------------------------------------------
%                             Subject        1       2       3       4       5
%                            ------------------------------------------------------
%                                 1         21      22       8       6       6
%                                 2         20      19      10       4       4           
%                                 3         17      15       5       4       5
%                                 4         25      30      13      12      17
%                                 5         30      27      13       8       6
%                                 6         19      27       8       7       4
%                                 7         26      16       5       2       5        
%                                 8         17      18       8       1       5       
%                                 9         26      24      14       8       9
%                            ------------------------------------------------------
%                                      
%   *Note: Due to a typing error, on the data table given by Dr. Winkel the value of subject 6 on
%    week 4 must be 7, not 6.
%
%   Data matrix must be:
%   X=[21 22 8 6 6;20 19 10 4 4;17 15 5 4 5;25 30 13 12 17;30 27 13 8 6;
%   ;19 27 8 7 4;26 16 5 2 5;17 18 8 1 5;26 24 14 8 9];
%
%   Calling on Matlab the function: 
%            RMA1multap(X)
%
%   Answer is:
%
%   One-Sample Repeated Measures Analysis by the Multivariate Approach Table.
%   -------------------------------------------------------------------------------------
%   Sample-size    Variables      T2          F           df1          df2          P
%   -------------------------------------------------------------------------------------
%         9            5       552.9009    86.3908        4             5        0.0001
%   -------------------------------------------------------------------------------------
%   With a given significance = 0.050
%   Mean vectors results significant.
% 
%   Created by A. Trujillo-Ortiz, R. Hernandez-Walls, K. Barba-Rojo and A. Castro-Perez
%              Facultad de Ciencias Marinas
%              Universidad Autonoma de Baja California
%              Apdo. Postal 453
%              Ensenada, Baja California
%              Mexico.
%              atrujo@uabc.mx
%
%   Copyright.September 24, 2007.
%
%   To cite this file, this would be an appropriate format:
%   Trujillo-Ortiz, A., R. Hernandez-Walls, K. Barba-Rojo and A. Castro-Perez (2007).
%     RM1MULTAP:One-Sample Repeated Measures Analysis by the Multivariate Approach.
%     A MATLAB file. [WWW document]. URL http://www.mathworks.com/matlabcentral/
%     fileexchange/loadFile.do?objectId=16575
%
%   References:
%   Barcikowski, R.S. and Robey, R.R. (1984). Decisions in single group repeated measures analysis:
%        Statistical tests and three computer packages. The American Statistician. 38:148-150.
%   Box, G.E.P. (1954). Some theorems on quadratic forms applied in the study of analysis of 
%        variance problems, II. Effects of inequality of variance and of correlation between
%        errors in the two-way classification. The Annals of Mathematical Statistics. 25:484-498.
%   Lewis, C. (1993). Analyzing means from repeated measures data. In G. Keren and C. Lewis (eds.),
%        A Handbook for data analysis in the behavioral sciences (pp.73-94). Hillsdale, NJ:Erlbaum.
%   Stevens, J. (1996). Applied multivariate statistics for the social sciences (3rd ed.).
%        Hillsdale, NJ:Erlbaum.
%

if nargin < 2,
   alpha = 0.05; %(default)
end 

if (alpha <= 0 | alpha >= 1)
   fprintf('Warning: significance level must be between 0 and 1\n');
   return,
end

if nargin < 1, 
   error('Requires at least one input argument.');
   return,
end

[n,p] = size(X);  %n=No. of subjects;p=No. of correlated variables (=p repeated
                  %measures on n subjacts)
M = mean(X);  %vector of means of the p-correlated variables
S = cov(X);  %covariance matrix of the p-correlated variables
C = [eye(p-1,p-1) -ones(p-1,1)];  %(p-1) x p matrix whose rows are orthonormal
                                  %contrasts normalized to unit length 
                                  %(rank = p-1)            
T2 = n*(C*M')'*inv(C*S*C')*(C*M');  %Hotelling's T2 statistic
F = ((n-1)-(p-1)+1)/((n-1)*(p-1))*T2;  %exact F transformation of T2
v1 = p-1;  %Numerator degrees of freedom
v2 = n-p+1;  %Denominator degrees of freedom.
P = 1-fcdf(F,v1,v2);  %Probability that null Ho: is true.
disp(' ')
disp('One-Sample Repeated Measures by the Multivariate Approach Table.')
fprintf('-------------------------------------------------------------------------------------\n');
disp(' Sample-size    Variables      T2          F           df1          df2          P')
fprintf('-------------------------------------------------------------------------------------\n');
fprintf('%8.i%13.i%15.4f%11.4f%9.i%14.i%14.4f\n',n,p,T2,F,v1,v2,P);
fprintf('-------------------------------------------------------------------------------------\n');
fprintf('With a given significance = %3.3f\n', alpha);
if P >= alpha;
    disp('Mean vectors results not significant.');
else
    disp('Mean vectors results significant.');
end

return,

Contact us at files@mathworks.com