Mercurial > hg > octave-max
changeset 652:baf268d7f7ee
[project @ 1994-08-25 14:26:59 by jwe]
author | jwe |
---|---|
date | Thu, 25 Aug 1994 14:26:59 +0000 |
parents | b4692246e165 |
children | fcaa09b47acf |
files | scripts/statistics/kurtosis.m scripts/statistics/skewness.m |
diffstat | 2 files changed, 43 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/statistics/kurtosis.m +++ b/scripts/statistics/kurtosis.m @@ -21,28 +21,37 @@ # usage: kurtosis (x) # # If x is a vector of length N, return the kurtosis +# # kurtosis(x) = N^(-1) std(x)^(-4) SUM_i (x(i)-mean(x))^4 - 3 +# # of x. -# If x is a matrix, return the row vector containing the kurtosis -# of each column. +# +# If x is a matrix, return a row vector containing the kurtosis for each +# column. -# Written by Kurt Hornik (hornik@neuro.tuwien.ac.at) June 1993. -# Dept of Probability Theory and Statistics TU Wien, Austria. +# Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Jul 29, 1994. +# Copyright Dept of Probability Theory and Statistics TU Wien, Austria. if (nargin != 1) - error("usage: kurtosis (x)"); + error ("usage: kurtosis (x)"); endif - [nr, nc] = size (x); - if (nr == 1 || nc == 1) - n = max (nr, nc); - x = x - ones (x) * sum (x) / n; - retval = sum (x.^4) / (n * max (sumsq (x)^2, ! any (x))); - elseif (nr > 0 && nc > 0) - x = x - ones (nr, 1) * sum(x) / nr; - retval = sum (x.^4) ./ (nr * max (sumsq (x).^2, ! any (x))); + if (is_vector (x)) + x = x - mean (x); + if (! any (x)) + retval = 0; + else + retval = sum (x .^ 4) / (length (x) * std (x) ^ 4) - 3; + endif + elseif (is_matrix (x)) + [nr, nc] = size (x); + x = x - ones (nr, 1) * mean (x); + retval = zeros (1, nc); + s = std (x); + ind = find (s > 0); + retval (ind) = sum (x (:, ind) .^ 4) ./ (nr * s (ind) .^ 4) - 3; else - error ("kurtosis: invalid matrix argument"); + error ("kurtosis: x has to be a matrix or a vector."); endif endfunction
--- a/scripts/statistics/skewness.m +++ b/scripts/statistics/skewness.m @@ -26,26 +26,32 @@ # # of x. # -# If x is a matrix, return the row vector containing the skewness -# of each column. +# If x is a matrix, return a row vector containing the skewness for each +# column. -# Written by Kurt Hornik (hornik@neuro.tuwien.ac.at) June 1993. -# Dept of Probability Theory and Statistics TU Wien, Austria. +# Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Jul 29, 1994. +# Copyright Dept of Probability Theory and Statistics TU Wien, Austria. if (nargin != 1) - error("usage: skewness (x)"); + error ("usage: skewness (x)"); endif - [nr, nc] = size (x); - if (nr == 1 || nc == 1) - n = max (nr, nc); - x = x - ones (x) * sum (x) / n; - retval = sum (x.^3) / (n * max (sumsq (x)^(3/2), ! any (x))); - elseif (nr > 0 && nc > 0) - x = x - ones (nr, 1) * sum (x) / nr; - retval = sum (x.^3) ./ (nr * max (sumsq (x).^(3/2), ! any (x))); + if (is_vector (x)) + x = x - mean (x); + if (! any (x)) + retval = 0; + else + retval = sum (x .^ 3) / (length (x) * std (x) ^ 3); + endif + elseif (is_matrix (x)) + [nr, nc] = size (x); + x = x - ones (nr, 1) * mean (x); + retval = zeros (1, nc); + s = std (x); + ind = find (s > 0); + retval (ind) = sum (x (:, ind) .^ 3) ./ (nr * s (ind) .^ 3); else - error ("skewness: invalid matrix argument"); + error ("skewness: x has to be a matrix or a vector."); endif endfunction