home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / statistics / base / kurtosis.m < prev    next >
Encoding:
Text File  |  1999-11-20  |  1.9 KB  |  71 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} kurtosis (@var{x})
  22. ## If @var{x} is a vector of length @var{N}, return the kurtosis
  23. ## @iftex
  24. ## @tex
  25. ## $$
  26. ##  {\rm kurtosis} (x) = {1\over N \sigma(x)^4} \sum_{i=1}^N (x_i-\bar{x})^4 - 3
  27. ## $$
  28. ## @end tex
  29. ## @end iftex
  30. ## @ifinfo
  31. ## 
  32. ## @example
  33. ## kurtosis (x) = N^(-1) std(x)^(-4) sum ((x - mean(x)).^4) - 3
  34. ## @end example
  35. ## @end ifinfo
  36. ## 
  37. ## @noindent
  38. ## of @var{x}.  If @var{x} is a matrix, return the row vector containing
  39. ## the kurtosis of each column.
  40. ## @end deftypefn
  41.  
  42. ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
  43. ## Created: 29 July 1994
  44. ## Adapted-By: jwe
  45.  
  46. function retval = kurtosis (x)
  47.  
  48.   if (nargin != 1)
  49.     usage ("kurtosis (x)");
  50.   endif
  51.  
  52.   if (is_vector (x))
  53.     x = x - mean (x);
  54.     if (! any (x))
  55.       retval = 0;
  56.     else
  57.       retval = sum (x .^ 4) / (length (x) * std (x) ^ 4) - 3;
  58.     endif
  59.   elseif (is_matrix (x))
  60.     [nr, nc] = size (x);
  61.     x = x - ones (nr, 1) * mean (x);
  62.     retval = zeros (1, nc);
  63.     s      = std (x);
  64.     ind    = find (s > 0);
  65.     retval (ind) = sum (x (:, ind) .^ 4) ./ (nr * s (ind) .^ 4) - 3;
  66.   else
  67.     error ("kurtosis: x has to be a matrix or a vector.");
  68.   endif
  69.  
  70. endfunction
  71.