Context
I must find the general form of a linear equation. The $X$ and $Y$ values are the location coordinates of touches on a screen. I want to find the best fit line, described by equation $mX + nY + p = 0$ , so I need to find $m, n, p$.
I want to be able to make regression of horizontal lines as well as vertical lines, or diagonal lines. I decided to make Orthogonal Distance Regression (ODR) instead of Ordinary Least Square (OLS) one.
I am using SciPy library (python langage), and I've written below function to make the job. It is using Single Value Decomposition (SVD). I've tested it, and it is giving excellent results. Now, I want to get the coefficient of determination $R^2$.
Coefficient of determination
According to Wikipedia, the definition is $$ R^2 = 1 - \frac{SS_{res}}{SS_{tot}} $$ where $SS_{res}$ is the sum of squares of residuals, and $SS_{tot}$ is the total sum of squares. To apply it in my case I considered: $$ SS_{res} = \sum_id((x_i,y_i);(\hat{x}, \hat{y}))^2 $$ where $ d((x_i,y_i);(\hat{x}, \hat{y}))$ is the distance of point $(x_i,y_i)$ to the best fit line.
and $$ SS_{tot} = \sum_id((x_i,y_i);(\overline{x}, \overline{y}))^2 $$ where $\overline{x}$ is the mean of all the $x_i$ and $\overline{y}$ is the mean of all the $y_i$.
My question
Is it the correct way to compute the coefficient of determination?
I am asking because it looks optimistic, in the sense that it is very often closed to 1.