# What methods can quickly determine the coefficient of determination of the data?

The given data is:

x = {0.04, 0.06, 0.04, 0.08, 0.08, 0.05, 0.05, 0.07, 0.07, 0.06};
y = {0.25, 0.4, 0.22, 0.54, 0.51, 0.34, 0.36, 0.46, 0.42, 0.4};


Is there a quicker method to calculate the coefficient of determination for this dataset? The approach I used involved step-by-step computation using the formula for the coefficient of determination.

x = {0.04, 0.06, 0.04, 0.08, 0.08, 0.05, 0.05, 0.07, 0.07, 0.06};
y = {0.25, 0.4, 0.22, 0.54, 0.51, 0.34, 0.36, 0.46, 0.42, 0.4};
meanY = Mean[y];
SST = Total[(y - meanY)^2];
lm = LinearModelFit[data, t, t]
residuals = lm["FitResiduals"]
SSE = Total[residuals^2]
rSquared = 1 - SSE/SST

• lm["RSquared"] ?
– ydd
Commented Jul 8 at 2:22
• For a simple linear model (just one predictor) try Correlation[x, y]^2. For linear models with more than one predictor use @ydd 's suggestion.
– JimB
Commented Jul 8 at 2:32
• What is a "coefficient of determination"? Commented Jul 8 at 5:19
• @DavidG.Stork Please see the content introduction in this web address: en.wikipedia.org/wiki/Coefficient_of_determination Commented Jul 8 at 8:20
• Thanks. I have always referred to it as $R^2$. Commented Jul 8 at 18:34

If you want to be "old school" (using linear algebra):

a = Thread[{1, x}];
sol = Inverse[Transpose[a] . a] . Transpose[a] . y
Plot[Inverse[Transpose[a] . a] . Transpose[a] . y . {1, t}, {t, 0.03,
0.08}, Epilog -> Point[Thread[{x, y}]], PlotRange -> All]


Using LinearModelFit and comparing with linear algebra:

lm = LinearModelFit[Thread[{x, y}], {1, s}, s];
lm["RSquared"]
d = y - Mean[y];
vec = a . sol - y;
1 - vec . vec/d . d


->

0.947046

0.947046

• Does using PseudoInverse count as old school? Or intermediate-oldish school?
– ydd
Commented Jul 8 at 15:24
• Yes you are right. This simple example… I was just sadly amusing myself Commented Jul 8 at 20:13