stats::BPCorr
-- Bravais-Pearson
correlationstats::BPCorr
(data)
returns the
Bravais-Pearson correlation coefficient of data pairs.
stats::BPCorr([x1, x2, ..], [y1, y2, ..])
stats::BPCorr([[x1, y1], [x2, y2], ..])
stats::BPCorr(s <, cx, cy>)
stats::BPCorr(s <, [cx, cy]>)
x1, x2, .. |
- | statistical data: arithmetical expressions. |
y1, y2, .. |
- | statistical data: arithmetical expressions. |
s |
- | a sample of domain type stats::sample . |
cx, cy |
- | integers representing column indices of the sample
s . Column cx provides the data x1, x2,
.. , column cy provides the data y1, y2,
.. . |
an arithmetical expression. FAIL
is returned, if the
Bravais-Pearson correlation coefficient does not exist.
sum((x[i]-X)*(y[i]-Y), i=1..n)/ sqrt( sum((x[i]-X)^2, i=1..n) * sum((y[i]-Y)^2, i=1..n) ) ,where X and Y are the mean values of the data x[i] and y[i], respectively.
This coefficient is a number between -1 and 1. It is close to 1, if the relation is approximately positive linear. It is close to -1, if it is negative linear. Values close to 0 correspond to non-linear relations or to unrelated data, respectively.
cx
, cy
are optional,
if the data are given by a sample object containing only two non-string
columns. Cf. example 2.We calculate the Bravais-Pearson correlation coefficient of four pairs of values given in two lists. There is a positive linear relation y = 1+2*x between the entries of the lists:
>> stats::BPCorr([0, 1, 2, 3], [1, 3, 5, 7])
1
Alternatively, the data may be specified by a list of pairs:
>> stats::BPCorr([[0, 0], [1, -3], [2, -4], [3, -3]])
1/2 5 - ---- 3
>> float(%)
-0.7453559925
We create a sample consisting of one string column and two non-string columns:
>> stats::sample([["a", 0, 0], ["b", 10, 10], ["c", 20, 35]])
"a" 0 0 "b" 10 10 "c" 20 35
The Bravais-Pearson correlation coefficient is calculated using the data columns 2 and 3. In this example there are only two non-string columns, so the column indices do not have to be specified:
>> float(stats::BPCorr(%))
0.9707253434
We create a sample consisting of three data columns:
>> stats::sample([[1, 0, 0], [2, 10, 10], [3, 20, 35]])
1 0 0 2 10 10 3 20 35
We compute the Bravais-Pearson correlation coefficient of the data pairs given by the first and the second column:
>> stats::BPCorr(%, 1, 2)
1
This result indicates that there is a linear relation between these columns. Indeed, the i-th entry y of column 2 is given by y = 10*(x -1), where x is the i-th entry of column 1.
We create a sample of three columns containing symbolic data:
>> stats::sample([[1, a, 10], [2, 10, A], [3, 6, 30], [x, 30, 10]])
1 a 10 2 10 A 3 6 30 x 30 10
We compute the Bravais-Pearson correlation coefficient of the data pairs given by the second and the third column. Here we specify these columns by a list of column indices:
>> stats::BPCorr(%, [2, 3])
/ / A \ / a \ \ | 10 A + 10 a - 4 | - + 25/2 | | - + 23/2 | + 480 | / \ \ 4 / \ 4 / / / / 2 / a \2 \ | | a - 4 | - + 23/2 | + 1036 | \ \ \ 4 / / / 2 / A \2 \ \ | A - 4 | - + 25/2 | + 1100 | |^(1/2) \ \ 4 / / /