changeset 2602:768b25797d18 octave-forge

indexing improved: if the product of columns of X and Y is much smaller than the max(col(X),col(y)^2
author schloegl
date Fri, 06 Oct 2006 08:04:00 +0000
parents aa6522fae7ef
children 97f4fc99a453
files extra/NaN/inst/corrcoef.m
diffstat 1 files changed, 22 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/extra/NaN/inst/corrcoef.m	Fri Oct 06 08:00:46 2006 +0000
+++ b/extra/NaN/inst/corrcoef.m	Fri Oct 06 08:04:00 2006 +0000
@@ -33,9 +33,9 @@
 %  p < alpha: The alternative hypothesis "R2 is larger than zero" is true with probability (1-alpha).
 %  ci1	lower 0.95 confidence interval 
 %  ci2	upper 0.95 confidence interval 
-%  nan_sig 	p-value whether H0: "NaN's are not correlated" could be correct
+%  nan_sig 	p-value whether H0: "NaN's are not correlated" could be correct
 %       if nan_sig < alpha, H1 ("NaNs are correlated") is very likely. 
-% 
+% 
 % The result is only valid if the occurence of NaN's is uncorrelated. In
 % order to avoid this pitfall, the correlation of NaN's should be checked 
 % or case-wise deletion should be applied. 
@@ -43,9 +43,9 @@
 %    ix = ~any(isnan([X,Y]))
 %    [...] = CORRCOEF(X(ix,:),Y(ix,:),...) 
 %
-%  Correlation (non-random distribution) of NaN's can be checked with 
-%       [nan_R,nan_sig]=corrcoef(X,isnan(X))
-%   or  [nan_R,nan_sig]=corrcoef([X,Y],isnan([X,Y]))
+%  Correlation (non-random distribution) of NaN's can be checked with 
+%       [nan_R,nan_sig]=corrcoef(X,isnan(X))
+%   or  [nan_R,nan_sig]=corrcoef([X,Y],isnan([X,Y]))
 %   or  [R,p,ci1,ci2] = CORRCOEF(...);
 %
 % Further recommandation related to the correlation coefficient 
@@ -124,9 +124,9 @@
         end;
 end;        
 Mode=[Mode,'        '];
-
-FLAG_WARNING = warning;		% save warning status
-warning('off');
+
+FLAG_WARNING = warning;		% save warning status
+warning('off');
 
 [r1,c1]=size(X);
 if ~isempty(Y)
@@ -149,7 +149,7 @@
         [jxo,jyo] = find(IX);
 	R = eye(c1);        
 else
-        IX = zeros(c1+c2);
+        IX = sparse([],[],[],c1+c2,c1+c2,c1*c2);
         IX(1:c1,c1+(1:c2)) = 1;
         [jx,jy] = find(IX);
         
@@ -237,7 +237,7 @@
                 end;
 		X = ranks(X);
         end;
-        R = 1 - 6 * R ./ (n.*(n.*n-1));
+        R = 1 - 6 * R ./ (n.*(n.*n-1));
         
 elseif strcmp(lower(Mode(1:7)),'partial');
         fprintf(2,'Error CORRCOEF: use PARTCORRCOEF \n',Mode);
@@ -253,7 +253,7 @@
 end;
 
 if (NARG<2), 
-	warning(FLAG_WARNING); 	% restore warning status
+	warning(FLAG_WARNING); 	% restore warning status
         return;
 end;
 
@@ -280,10 +280,10 @@
         fprintf('CORRCOEF: significance test not completed because of missing TCDF-function\n')
         sig = repmat(nan,size(R));
 end;
-sig  = 2 * min(sig,1 - sig);
+sig  = 2 * min(sig,1 - sig);
 
 if NARG<3, 
-	warning(FLAG_WARNING); 	% restore warning status
+	warning(FLAG_WARNING); 	% restore warning status
         return;
 end;
 
@@ -301,12 +301,12 @@
 %ci2(isnan(ci2))=R(isnan(ci2));
 
 if (NARG<5) | ~YESNAN, 
-        sig_nan = [];
-	warning(FLAG_WARNING); 	% restore warning status
+        sig_nan = [];
+	warning(FLAG_WARNING); 	% restore warning status
         return;
 end;
 
-
+
 %%%%% ----- check independence of NaNs (missing values) -----
 %[nan_R,nan_sig,nan_ci1,nan_ci2] = corrcoef(X,isnan(X))
 [nan_R, nan_sig] = corrcoef(X,isnan(X));
@@ -314,17 +314,17 @@
 % remove diagonal elements, because these have not any meaning %
 nan_sig(isnan(nan_R)) = nan;
 
-if any(nan_sig(:) < alpha),
-        tmp = nan_sig(:);			% Hack to skip NaN's in MIN(X)
-        min_sig = min(tmp(~isnan(tmp))); 	% Necessary, because Octave returns NaN rather than min(X) for min(NaN,X) 
+if any(nan_sig(:) < alpha),
+        tmp = nan_sig(:);			% Hack to skip NaN's in MIN(X)
+        min_sig = min(tmp(~isnan(tmp))); 	% Necessary, because Octave returns NaN rather than min(X) for min(NaN,X) 
         fprintf(1,'CORRCOFF Warning: Missing Values (i.e. NaNs) are not independent of data (p-value=%f)\n', min_sig);
         fprintf(1,'   Its recommended to remove all samples with any missing value (NaN).\n');
         fprintf(1,'   In the following combinations the null-hypotheses (NaNs are uncorrelated) must be rejected.\n');
         [ix,iy] = find(nan_sig < alpha);
         disp([ix,iy])
 end;
-
+
 %%%%% ----- end of independence check ------
-
-warning(FLAG_WARNING); 	% restore warning status
+
+warning(FLAG_WARNING); 	% restore warning status
 return;