Corrcoef and R^2 definition give different R^2 values
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to calculate R^2 value for my data and simulation. I used two different ways.
First one,
C = corrcoef(ydata,simulation);
rsq1 = C(1,2).^2;
Second one,
rsq2 = 1 - norm(ydata-simulation)^2 / norm(ydata-mean(ydata))^2;
They should be the same, but actually, the second one is smaller than the first one. Could anyone tell me what is a possible reason for that? Thanks a lot!
Rui
0 个评论
回答(2 个)
Tom Lane
2012-10-27
I would expect your formula to work if simulation is a set of predicted values from fitting ydata using least squares as a function of a set of predictors, including a constant term. Otherwise maybe not.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!