* * Example 11.3, page 407 * Spearman's Rank Correlation test * data(unit=input,org=columns) 1 10 avgret stddev 12.4 12.1 14.4 21.4 14.6 18.7 16.0 21.7 11.3 12.5 10.0 10.4 16.2 20.8 10.4 10.2 13.1 16.0 11.3 12.0 linreg avgret # constant stddev * * Spearman's rank correlation test. * Get the ranks for |u| and x. * Compute the difference in the ranks. * Compute r using %dot(d,d) (will be sum of squares) and * the %nobs variable, and the t statistic generated from it. * Use cdf to show the significance. * set absu = abs(%resids) order(ranks=urank) absu order(ranks=srank) stddev * sstats / (urank-srank)**2>>dd compute r=1-6*dd/(%nobs*(%nobs**2-1)) compute rt=r*sqrt(%nobs-2)/sqrt(1-r**2) * * The CDF instruction produces a two-tailed significance level, testing a null of * no correlation in the ranks vs non-zero correlation. If you want a one-tailed * test (that is, that the alternative is positive correlation, not just * non-zero), divide the reported significance level by 2. * cdf(title="Spearman Rank Correlation Test") ttest rt %nobs-2