Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
Close
From: Alois Schloegl <schloegl@us...>  20041223 17:39:48

Update of /cvsroot/octave/octaveforge/extra/NaN In directory sc8prcvs1.sourceforge.net:/tmp/cvsserv25978 Modified Files: corrcoef.m Log Message: improve docu Index: corrcoef.m =================================================================== RCS file: /cvsroot/octave/octaveforge/extra/NaN/corrcoef.m,v retrieving revision 1.29 retrieving revision 1.30 diff u d r1.29 r1.30  corrcoef.m 10 Jun 2004 15:16:10 0000 1.29 +++ corrcoef.m 23 Dec 2004 17:39:36 0000 1.30 @@ 1,28 +1,26 @@ function [R,sig,ci1,ci2,nan_sig] = corrcoef(X,Y,Mode); % CORRCOEF calculates the correlation coefficient. % X and Y can contain missing values encoded with NaN. % NaN's are skipped, NaN do not result in a NaN output. % It is garanteed that abs(R) is not larger than 1. % A significance test to check the independence of NaN's +% The input data can contain missing values encoded with NaN. +% Missing data (NaN's) are handled by pairwise deletion [15]. +% In order to avoid possible pitfalls, use casewise deletion or +% or check the correlation of NaN's with your data (see below). +% A significance test for testing the Hypothesis +% "correlation coefficient R is significantly different to zero" % is included. % R = CORRCOEF(X [,Mode]); +% +% [...] = CORRCOEF(X [,Mode]); % calculates the (auto)correlation matrix of X % R = CORRCOEF(X,Y [,Mode]); +% [...] = CORRCOEF(X,Y [,Mode]); % calculates the crosscorrelation between X and Y % % Mode='Pearson' or 'parametric' [default] % gives the correlation coefficient % also known as the "productmoment coefficient of correlation" or "Pearson's correlation" [1] % Mode='Spearman' gives "Spearman's Rank Correlation Coefficient" % This replaces SPEARMAN.M % Mode='Rank' gives a nonparametric Rank Correlation Coefficient % This replaces RANKCORR.M % % The result is only valid if the occurence of NaN's is uncorrelated. % This 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,nan_sig] = CORRCOEF(...); +% Mode='Pearson' or 'parametric' [default] +% gives the correlation coefficient +% also known as the "productmoment coefficient of correlation" +% or "Pearson's correlation" [1] +% Mode='Spearman' gives "Spearman's Rank Correlation Coefficient" +% This replaces SPEARMAN.M +% Mode='Rank' gives a nonparametric Rank Correlation Coefficient +% This replaces RANKCORR.M % % [R,p,ci1,ci2,nansig] = CORRCOEF(...); % R is the correlation matrix @@ 38,12 +36,25 @@ % nan_sig pvalue 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 casewise deletion should be applied. +% CaseWise deletion can be implemented +% ix = ~any(isnan([X,Y])) +% [...] = CORRCOEF(X(ix,:),Y(ix,:),...) +% +% Correlation (nonrandom 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 % + LOOK AT THE SCATTERPLOTS! % + Correlation is not causation. The observed correlation between two variables % might be due to the action of other, unobserved variables. % % see also: SUMSKIPNAN, COVM, COV, COR, SPEARMAN, RANKCORR, RANKS +% see also: SUMSKIPNAN, COVM, COV, COR, SPEARMAN, RANKCORR, RANKS, +% PARTCORRCOEF % % REFERENCES: % on the correlation coefficient @@ 58,12 +69,13 @@ % [12] http://www.janda.org/c10/Lectures/topic06/L24significanceR.htm % [13] http://faculty.vassar.edu/lowry/ch4apx.html % [14] http://davidmlane.com/hyperstat/B134689.html +% [15] http://www.statsoft.com/textbook/stbasic.html#Correlationsk % others % [20] http://www.tufts.edu/~gdallal/corr.htm % $Revision$ % $Id$ % Copyright (C) 20002003 by Alois Schloegl <a.schloegl@...> +% Copyright (C) 20002004 by Alois Schloegl <a.schloegl@...> % This function is part of the NaNtoolbox % http://www.dpmi.tugraz.ac.at/~schloegl/matlab/NaN/ @@ 82,16 +94,18 @@ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 021111307 USA % Features: % + interprets NaN's as missing value % + Pearson's correlation % + Spearman's rank correlation % + Rank correlation (nonparametric, nonSpearman) +% + handles missing values (encoded as NaN's) +% + pairwise deletion of missing data +% + checks independence of missing values (NaNs) +% + parametric and nonparametric (rank) correlation +% + Pearson's correlation +% + Spearman's rank correlation +% + Rank correlation (nonparametric, nonSpearman) % + is fast, using an efficient algorithm O(n.log(n)) for calculating the ranks % + significance test for nullhypthesis: r=0 % + confidence interval included %  rank correlation works for cell arrays, too (no check for missing values). % + compatible with Octave and Matlab % + checks independence of missing values (NaNs) NARG = nargout; % needed because nargout is not reentrant in Octave 