计算使用JavaScript实现的Spearman相关系数的函数

‘ use strict ‘; var DEBUG=0; module.exports=function ((this.spearman=function ) x,y ) )/checkingparametersif ) undefined==typeof ) ) }if(undefined==typeof(y ) ) { return; } var len_x=x.length; var len_y=y.length; var len=len_x len_y? len_x : len_y; if(len=0) { return; } var x_mean=0.0; var y_mean=0.0; for(varI=0; i len; I ) x_mean=parsefloat(x[I]; y_mean=parsefloat(y[I]; } x_mean=x_mean/len; y_mean=y_mean/len; var tmp_u=0.0; for(varI=0; i len; I ) {tmp_u=(x_mean-x[I] ) ) * (y_mean – y[i] ); (/console.log(‘tmp_u=’,tmp_u ); var tmp_d_x=0.0; for(varI=0; i len; I ) {tmp_d_x=(* (x_mean – x[i] ) ) x_mean-x[I] ); } var tmp_d_y=0.0; for(varI=0; i len; I ) ) tmp_d_y=(* (y_mean – y[i] ) ) y_mean-y[I]; } var rho=tmp _ u/math.sqrt (tmp _ d _ x * tmp _ d _ y ) if ) debug ) console.log ) report ‘ ) console.log consog console.log(‘meanvauleofy=’,y_mean ); console.log(spearmancorofx-y=’,rho ); (} return rho; }