Endfunc
r2coefdf(lx,ly)
func
©Find coefficient of determination r^2, adjusted for DOF
©lx is list of x-data points
©ly is list of y-data points
©24 nov 99/dburkett@infinet.com
local n
dim(lx)→n
1-((n-1)*sum((regeq(lx)-ly)^2))/((n-dim(regcoef)-1)*sum((ly-mean(ly))^2))
Endfunc
Note that neither of these functions will account for weighting of the data points.
Both functions should be run in Approx mode. Both take the list of x-data and y-data values in the lists
lx and ly. Be sure to run the regression command (CubicReg, ExpReg, etc) before using these
functions, because they depend on the system variables regeq and regcoef being up-to-date.
regeq is a function that is updated by the regression command. It is the regression equation itself, and I
use it in both routines to calculate needed values. regcoef is the list of regression equation coefficients,
and I use it in r2coefdf() to find the degrees of freedom.
The coefficient of determination, without adjustment for degrees of freedom, is defined as
r2 = 1 −
SSE
SSM
SSE is the sum of the squares of the error, defined as
SSE =
✟
i=1
n
yˆ
i
− y
i
2
SSM is the sum of squares about the mean, defined as
SSM =
✟
i=1
n
y
i
− y
Also,
n is the number of data points
y
i
are the y-data values
y
ˆ
i
= f
x
i
are the estimated y-values, that is, the regression equation evaluated at each x-data value
y
is the mean of the y-data values
It is a simple matter to adjust r
2
for degrees of freedom:
r2 = 1 −
(
n−1
)
$SSE
(
DOF−1
)
$SSM
Here, DOF is the degrees of freedom, defined as
DOF = n − m
6 - 18