changeset 12492:d7adff2641da octave-forge

statistics: adding new function and alphabetical order of INDEX
author jpicarbajal
date Sat, 24 May 2014 19:47:26 +0000
parents 433d51ea22ad
children 32ce8fbfb857
files main/statistics/INDEX main/statistics/NEWS main/statistics/inst/dcov.m
diffstat 3 files changed, 90 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/main/statistics/INDEX	Thu May 22 21:15:19 2014 +0000
+++ b/main/statistics/INDEX	Sat May 24 19:47:26 2014 +0000
@@ -35,20 +35,21 @@
  wblstat
  wishpdf wishrnd
 Descriptive statistics
- nansum
+ combnk
+ dcov
+ geomean
+ harmmean
+ jackknife
+ mad
  nanmax
  nanmean
  nanmedian
  nanmin
  nanstd
+ nansum
  nanvar
- geomean
- harmmean
- mad
  trimmean
  tabulate
- combnk
- jackknife
 Experimental design
  fullfact ff2n
 Regression
@@ -63,13 +64,15 @@
  stepwisefit
 Plots
  boxplot
- normplot
+ dendrogram
  histfit
  hist3
+ normplot
  repanova
- dendrogram
 Models
- hmmestimate hmmgenerate hmmviterbi
+ hmmestimate 
+ hmmgenerate 
+ hmmviterbi
 Hypothesis testing
  anderson_darling_test
  runstest
--- a/main/statistics/NEWS	Thu May 22 21:15:19 2014 +0000
+++ b/main/statistics/NEWS	Sat May 24 19:47:26 2014 +0000
@@ -11,7 +11,7 @@
 
  ** The following functions are new:
  
-    cdf signtest ttest ttest2 vartest vartest2 ztest qrandn
+    cdf signtest ttest ttest2 vartest vartest2 ztest qrandn dcov
 
 Summary of important user-visible changes for statistics 1.2.3:
 -------------------------------------------------------------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/statistics/inst/dcov.m	Sat May 24 19:47:26 2014 +0000
@@ -0,0 +1,77 @@
+## Copyright (C) 2014 - Maria L. Rizzo and Gabor J. Szekely
+## Copyright (C) 2014 Juan Pablo Carbajal
+## This work is derivated fomr the R energy package. Was adapted 
+## for Octave by Juan Pablo Carbajal.
+## 
+## This progrm is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+## Author: Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {[@var{dCor}, @var{dCov}, @var{dVarX}, @var{dVarY}] =} dcov (@var{x}, @var{y}, @var{index}=1)
+## Distance covariance and correlation statistics.
+##
+## It returns distace correlation (@var{dCor}), 
+## distance covariance (@var{dCov}), diatance variace on x (@var{dVarX}) and
+## distance variance on y (@var{dVarY}).
+##
+## Reference: https://en.wikipedia.org/wiki/Distance_correlation
+##
+## @seealso{cov}
+## @end deftypefn
+
+function [dCov, dCor, dVarX, dVarY] = dcov (x,y,index=1.0)
+  %x = abs(x - x.');
+  %y = abs(y - y.');
+  x = bsxfun (@minus, x, x.');
+  y = bsxfun (@minus, y, y.');
+  
+  [n nc] = size (x);
+  [m mc] = size (y);
+  if (n != m) 
+    error ("Octave:invalid-input-arg", "Sample sizes must agree.");
+  endif
+  
+  if  any (isnan (x) | isnan (y))
+      error ("Octave:invalid-input-arg","Data contains missing or infinite values.");
+  endif
+  
+  if index < 0 || index > 2
+    warning ("Octave:invalid-input-arg","index must be in [0,2), using default index=1");
+    index = 1.0;
+  endif
+
+  A = Akl (x, index);
+  B = Akl (y, index);
+  
+  dCov  = sqrt (mean (A(:) .* B(:)));
+  dVarX = sqrt (mean (A(:).^2) );
+  dVarY = sqrt (mean (B(:).^2) );
+  V     = sqrt (dVarX .* dVarY);
+
+  if V > 0
+    dCor = dCov / V;
+  else 
+    dCor = 0;
+  end
+
+endfunction
+
+function c = Akl (x, index)
+        d = x .^ index;
+        m = mean (d, 2);
+        M = mean (d(:));
+        %c = d - m - m.' + M;
+        c = d - bsxfun (@plus, m, m.') + M;
+endfunction