I'm trying to calculate the coefficient of determination (R^2) in Python, but I'm getting a negative value in certain cases. Is this a sign that there's an error in my calculation? I thought R^2 should be bounded between 0 and 1.
Here's my Python code for doing the calculation, adapted straight from the WP article:
>>> yi_list = [1, 1, 63, 63, 5, 5, 124, 124]
>>> fi_list = [1.7438055421354988, 2.3153069186947639, 1002.7093097555808, 63.097699219524706, 6.2635465467410842, 7.2275532522971364, 17.55393551900103, 40.8570]
>>> y_mean = sum(yi_list)/float(len(yi_list))
>>> ss_tot = sum((yi-y_mean)**2 for yi in yi_list)
>>> ss_err = sum((yi-fi)**2 for yi,fi in zip(yi_list,fi_list))
>>> r2 = 1 - (ss_err/ss_tot)
>>> r2
-43.802085810924964