3
This is going to be relatively quick...
Challenge
Given a lower-case word as input, calculate the Pearson's Correlation Coefficient between the letter position of the word (nth letter within the word, x), and the letter position within the alphabet (nth letter of the alphabet, y).
Background
Pearson's Correlation Coefficient is worked out for data sets x and y, as:
where x and y are the respective data sets as explained above (and further below), and n is the length of the string.
Examples
Input: forty
Output: 0.964406804
Explanation:
Letters: f o r t y
Alphabet Number (y): 6 15 18 20 25
Letter Position (x): 1 2 3 4 5
Length of word (n): 5
Correlation coefficient is worked out from the above formula.
Input: bells
Output: 0.971793199
Explanation:
Letters: b e l l s
Alphabet Number (y): 2 5 12 12 19
Letter Position (x): 1 2 3 4 5
Length of word (n): 5
Correlation coefficient is once again worked out from the above formula.
Rules
- Input must provide the word as a lower-case alphabetic string with no spaces (assumed input). The delivery of this string is entirely up to you (file, STDIN, function, array, carrier pigeon, etc.)
- Output is in the form of a numeric that will, by the formula, provide r, such that -1 <= r <= 1. Delivery of the output, once again, is entirely up to you.
- No silly loop holes
- This is not code-golf, as I'm sure there will be many languages that may have native statistical functions. Instead, this will be a popularity contest, so most votes wins here, so make your entry count... I'll be throwing in a bounty for the most creative answer that attracts my attention a little later down the line...
Any questions/comments?
Relevant Wikipedia article – Copper – 2016-10-09T13:54:55.510
5
I wish you had made this a pop con in the sandbox, so I could have said it over there. If you want to avoid built-ins in code golf challenges, just ban functions that compute the PCC. This type of popularity contest has fallen out of scope. The tag wiki explicitly says Questions like "do (this) the most creative way" should be avoided. Creativity should be the tool, not the goal.
– Dennis – 2016-10-09T14:42:11.5031
I wasn't aware of this when I posted my previous comment, but this has already be done as a code golf challenge.
– Dennis – 2016-10-09T15:04:10.677