wilcoxon_signed_rank_test = function( data, mu_0=0 ){ # # Returns: # s_{+} the sum of the positive ranks of the sample values x_i that have x_i - mu_0 greater than zero. # s_{-} the sum of the negative ranks of the sample values x_i that have x_i - mu_0 less than zero. # # See Page 600 from the book Probability and Statistics: For Engineering and the Sciences by Jay L. Devore # # Note: this code does not compute or use the values of tau_i (the number samples that have tied values), # as described on page 606 of the book. # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- data_diff = data - mu_0 abs_data_diff = abs( data_diff ) if( sum( diff(abs_data_diff)==0 )>0 ){ print( 'WARNING: Duplicate data values found' ) } abs_sample_ranks = rank( abs_data_diff ) neg_inds = ( data_diff < 0 ) s_minus = -sum( abs_sample_ranks[ neg_inds] ) s_plus = +sum( abs_sample_ranks[!neg_inds] ) list( s_plus=s_plus, s_minus=s_minus ) }