I wrote:
> corr =: (+/@:* % *&(+/)&.:*:)&(- +/%#)
Linda asked for:
> some sample data for corr with your expected result
I'll just short-circuit this discussion and rephrase corr in Simplistic J
for you.
avg =: +/ % #
sumSqrs =: 13 : '+/ *: y'
simplisticCorr =: 13 : '(x - avg x) ( ([: +/ *) % [: %: ([: sumSqrs [)
* [: sumSqrs ]) (y - avg y)'
simplisticCorrSpelledOut =: simplisticCorr f.
simplisticCorr
([ - [: avg [) (([: +/ *) % [: %: ([: sumSqrs [) * [: sumSqrs ]) ] - [: avg
]
simplisticCorrSpelledOut
([ - [: (+/ % #) [) (([: +/ *) % [: %: ([: ([: +/ *:) [) * [: ([: +/ *:) ])
] - [: (+/ % #) ]
Of course, defining it this way defeats the entire purpose for which I
introduced corr (elegance, simplicity, symmetry, brevity) but I know you
have other purposes (avoiding conjunctions at all costs).
So if you want to play with it for these purposes, any standard textbook
example of calculating the correlation coefficient will do:
gnp1955 =: 91 51 58 359 134 70 129 515 70 707 468 749 998
2334
trade1955 =: 2729 407 349 1169 923 2689 1601 415 83 5395 1852 6530 18677
26836
gnp1955 corr trade1955 NB. GNP/capita highly correlated with trade in
1955
0.925343
gnp1955 simplisticCorr trade1955
0.925343
gnp1955 simplisticCorrSpelledOut trade1955
0.925343
However, for those are interested in the verb's form, rather than its
function, and want to know why I introduced it as a beautiful example of J,
some explanations can be in the original thread:
http://www.jsoftware.com/pipermail/programming/2007-June/007179.html
[I should have noted yesterday that Oleg Kobchenko was the original author
of corr (which I was somewhat disappointed to discover when I independently
developed it some years later....)]
-Dan
PS: Because I know you want to see it:
5!:4<'simplisticCorr'
+- [
+- -
+-+ +- [:
| +---+- avg
| +- [
|
| +- [:
| +---+- / --- +
| | +- *
| +- %
+-+ +- [:
| | +- %:
--+ | | +- [:
| +---+ +---+- sumSqrs
| | | +- [
| +-----+- *
| | +- [:
| +---+- sumSqrs
| +- ]
| +- ]
| +- -
+-+ +- [:
+---+- avg
+- ]
5!:4<'simplisticCorrSpelledOut'
+- [
+- -
+-+ +- [:
| | | +- / --- +
| +---+-----+- %
| | +- #
| +- [
|
| +- [:
| +---+- / --- +
| | +- *
| +- %
| | +- [:
+-+ +- %:
| | | +- [:
--+ | | | +- [:
| +---+ +-----+----+- / --- +
| | | | +- *:
| | | +- [
| +-----+- *
| | +- [:
| | | +- [:
| +-----+----+- / --- +
| | +- *:
| +- ]
| +- ]
| +- -
+-+ +- [:
| | +- / --- +
+---+-----+- %
| +- #
+- ]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm