Interpreting $R^2$ for comparing groups of observations I got the following columns:
Level 1        240    12     7
Level 2        98     5      5
Level 3        46     4      6
Level 4        21     0      1

I try to prove that there is a correlation between the "Level" and the number of people (represented by each column) I used the following forumla (Table is the table..) :
RS2 = r2_score(Table.iloc[1:5,0], Table.iloc[1:5,1], Table.iloc[1:5,2])

print(RS2 )

The result is negative (-4....) which is wrong.
I am undecided, but maybe I should calculate the columns together as one group, finding mean and then the estimated values? if not, what should I do?
** note my data is small, concatenating the columns will probably give a large confidence interval..

$R^2$ has nothing to do with the sign of a correlation. While there are ways of getting $R^2<0$ in a regression model (an indication of a poor fit), the notation comes from the fact that $R^2 = r^2$, where $r$ is the sample correlation between two variables, when you fit a regression model $\hat y_i = \hat\beta_0 + \hat\beta_1x_i$ with the extremely common method of least squares.
However, it looks like you have one variable with the levels in it and one variable with the numerical observations>
$$
X = (1,2,3,4,1,2,3,4,1,2,3,4)\\
Y = (240, 98, 46, 21, 12, 5, 4, 0, 7, 5, 6, 1)
$$
Since your levels appear to be ordinal---that is, ordered but with unclear differences between them---Spearman's rank correlation is appropriate here. In R, the line is
cor(x, y, method = "spearman").
This gives me a result of about $- 0.5$. However, the plot is not so convincing. When I do a test of the Spearman correlation being nonzero via cor.test(x, y, method = "spearman"), I get a p-value that tends to be considered inconclusive, $p = 0.099$, along with a warning that the exact p-value cannot be computed, due to tied values. I am not sure how serious this is, but, combined with the graph, I am skeptical increasing the level decreases the $Y$ variable.
