Home > matlab > moments.m

moments

PURPOSE ^

Returns the central sample moment of X specified by the positive integer order.

SYNOPSIS ^

function m = moments(X,order)

DESCRIPTION ^

 Returns the central sample moment of X specified by the positive integer order.

 Note that the cross moments are only computed if order=2, in this case the 
 output is a matrix.

 INPUTS
    X      [double]   T*n matrix, where T is the number of observations and n the number of variables.
    order  [integer]  scalar.

 OUTPUTS
    m      [double]  n*n matrix or n*1 vector of centered moments.

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function m = moments(X,order)
0002 % Returns the central sample moment of X specified by the positive integer order.
0003 %
0004 % Note that the cross moments are only computed if order=2, in this case the
0005 % output is a matrix.
0006 %
0007 % INPUTS
0008 %    X      [double]   T*n matrix, where T is the number of observations and n the number of variables.
0009 %    order  [integer]  scalar.
0010 %
0011 % OUTPUTS
0012 %    m      [double]  n*n matrix or n*1 vector of centered moments.
0013 %
0014 % SPECIAL REQUIREMENTS
0015 %    none
0016 
0017 % Copyright (C) 2009-2010 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 switch order
0035   case 1
0036     m = transpose(mean(X));
0037   case 2
0038     m = cov(X);
0039   otherwise
0040     if round(order)-order
0041         error('The second input argument (order) has to be an integer!')
0042     end
0043     [T,n] = size(X);
0044     c = mean(X);
0045     m = zeros(n,1);
0046     for i=1:n
0047         m(i) = mean((X(:,i)-c(i)).^order);
0048     end
0049 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005